A callback is a special trigger in the game's code that notifies, and sometimes requests information from, the python code when an important event happens. These are used to control gameplay behavior and along with the functions GE:S provides, allow for a great variety of custom gameplays.
Here is a quick list of all gameplay callbacks and their functions. If a return value is not described then there is none.
GetGameDescription( self ):
Called as gameplay is loaded.
Returns: string, telling the engine what to display for “GAME” on the server list.
GetPrintName( self ):
Called as gameplay is loaded.
Returns: string, telling the game what to display for the gamemode title in help resources and chat notices.
GetTeamPlay( self ):
Called as gameplay is loaded
Returns: enum, telling the game what teammode states are possible. The enums are stored on GEGlobal and are:
TEAMPLAY_NONE - Teamplay cannot occur on this gamemode
TEAMPLAY_TOGGLE - Teamplay can be turned on and off by server owners and ge_autoteam rules
TEAMPLAY_ALWAYS - Teamplay is always enabled
GetScenarioHelp( self, help_obj ):
Called as gameplay is loaded.
Returns: Help Object, with parameters specified by the gamemode creator to control help resources.
OnLoadGamePlay( self ):
Called when gameplay is loaded.
OnUnloadGamePlay( self ):
Called when gameplay is being deleted.
OnPlayerConnect( self, player ):
Called when player first connects to the server
OnPlayerDisconnect( self, player ):
Called when player starts disconnecting from the server.
OnPlayerSpawn( self, player ):
Called when a player spawns into the game world (ie, not spectating)
OnPlayerObserver( self, player ):
Called when a player joins team spectator
OnPlayerKilled( self, victim, killer, weapon ):
Called when a player dies
CanPlayerRespawn( self, player ):
Called when a player attempts to spawn in.
Returns: boolean, which is true if they should be allowed to do so.
CanPlayerChangeChar( self, player, ident ):
Called when a player attempts to change character.
Returns: boolean, which is true if they should be allowed to do so
CanPlayerChangeTeam( self, player, oldteam, newteam, wasforced ):
Called when a player attempts to change teams.
Returns: boolean, which is true if they should be allowed to do so
CanPlayerHaveItem( self, player, weapon ):
Called when a player attempts to obtain an item, such as a weapon or armorvest.
Returns: boolean, which is true if the pickup should be permitted.
OnPlayerSay( self, player, text ):
Called when a player attempts to say something in chat.
Returns: boolean, which is true if the message should be hidden.
ShouldForcePickup( self, player, entity ):
Called when a player attempts to pick up something but can't
Returns: boolean, which is true if the item should be removed anyway.
CalculateCustomDamage( self, victim, info, health, armor ):
Called whenever a player takes damage.
Returns: health, an integer value equal to the damage taken to the player's health. armor, an integer value equal to the damage taken to the player's armor.
BeforeSetupRound( self ):
Called right before the round is set up on the map (before weapons/armor is placed)
OnRoundBegin( self ):
Called after the world reloads and prior to players being spawned
OnRoundEnd( self ):
Called once the round time ends and prior to scoring calculations
CanRoundEnd( self ):
Called whenever the game attempts to end the round due to the timer running out.
Returns: boolean, which is true if it should end.
CanMatchEnd( self ):
Called whenever the game attempts to end the match due to the timer running out.
Returns: boolean, which is true if it should end.
OnTokenSpawned( self, token ):
Called whenever the game spawns a token.
OnTokenRemoved( self, token ):
Called whenever a token is deleted.
OnTokenPicked( self, token, player ):
Called whenever a token is picked up.
OnTokenDropped( self, token, player ):
Called whenever a token is dropped. If dropped due to player death, this is called after OnPlayerKilled so the former callback has a chance to analyze the dying player's tokens.
OnTokenAttack( self, token, player, position, direction ):
Called whenever a player attacks with a token.
OnEnemyTokenTouched( self, token, player ):
Called whenever a player touches a token that they cannot pick up due to team restrictions.
OnCaptureAreaSpawned( self, area ):
Called whenever a capture area is spawned.
OnCaptureAreaRemoved( self, area ):
Called whenever a capture area is deleted.
OnCaptureAreaEntered( self, area, player, token ):
Called whenever a player touches a capture area.
OnCaptureAreaExited( self, area, player ):
Called whenever a player stops touching a capture area.
OnWeaponSpawned( self, weapon ):
Called whenever the game spawns a weapon.
OnWeaponRemoved( self, weapon ):
Called whenever a weapon is picked up or deleted.
OnArmorSpawned( self, armor ):
Called whenever the game spawns a weapon.
OnArmorRemoved( self, armor ):
Called whenever an armor vest is picked up or deleted.
OnAmmoSpawned( self, armor ):
Called whenever the game spawns a weapon.
OnAmmoRemoved( self, armor ):
Called whenever an ammo box is picked up or deleted.
def OnThink( self ):
Called every game tick, use sparingly.
def OnCVarChanged( self, name, oldvalue, newvalue ):
Called whenever a console variable is changed