Gamemode Hooks
From GMod Wiki
m (Reverted edits by 76561198002370135 (talk) to last revision by 76561197960279927) |
m (Remove sandbox shared.) |
||
Line 37: | Line 37: | ||
{{:Serverside:Sandbox}} | {{:Serverside:Sandbox}} | ||
- | |||
- | |||
- | |||
| valign="top" style="padding-left: 1.0em; padding-right: 1.0em;" | | | valign="top" style="padding-left: 1.0em; padding-right: 1.0em;" | |
Latest revision as of 17:17, 18 June 2011
How Gamemode Hooks Work
Hooks are how you make functions run when certain things happen in-game. For example, whenever a player dies the "PlayerDeath" hook is called on the server. In order to make these functions useful, each hook sends different arguments to the functions you add to the hook, like the player who's dying, the player who killed him, and the weapon that was used. The hooks below are all default hooks you find in their respective gamemodes. To use these hooks, you can either use hook.Add which runs in addition to all existing hooks, or override the function entirely using GAMEMODE:hook_Name/GM:hook_name which ignores all other hooks from hook. Add or those established in the gamemode.
The format for adding a gamemode hook is hook.Add( String hook_name, String unique_name, Function callback ).
To override, use GM:hook_name. ( ie GM:PlayerSpawn(ply) ).
For hook_name, use the name you want from the list below. Unique name is used to make sure that if your code is loaded twice, it's still only hooked once, For callback specify the function you wish to be called for the hook event. See Internal gamemode workings for information on the working of gamemodes.
If you're making your own gamemode, it'd be better to override some of these functions.
All Gamemodes
Sandbox Hooks