GM
Hooks that are available for all gamemodes based on base gamemode.
See also: GM structure.
Events
Called when a map I/O event occurs.
See also Entity:Fire and Entity:Input for functions to fire Inputs on entities.
GM:AddDeathNotice( string attacker, number attackerTeam, string inflictor, string victim, number victimTeam )
Adds a death notice entry.
Allows you to adjust the mouse sensitivity.
Called when a player tries to pick up something using the "use" key, return to override.
This hook will not be called if sv_playerpickupallowed is set to 0.
See GM:GravGunPickupAllowed for the Gravity Gun pickup variant.
See GM:PhysgunPickup for the Physics Gun pickup variant.
This hook is used to calculate animations for a player.
This hook must return the same values at the same time on both, client and server. On client for players to see the animations, on server for hit detection to work properly.
Called from GM:CalcView when player is in driving a vehicle.
This hook may not be called in gamemodes that override GM:CalcView.
Allows override of the default view.
Vector, Angle GM:CalcViewModelView( Weapon wep, Entity vm, Vector oldPos, Angle oldAng, Vector pos, Angle ang )
Allows overriding the position and angle of the viewmodel.
Called whenever a players tries to create an undo.
Called when a variable is edited on an Entity (called by Edit Properties. . . menu), to determine if the edit should be permitted.
See Editable entities for more details about the system.
Determines if the player can exit the vehicle on their own. Player:ExitVehicle will bypass this hook.
See GM:CanPlayerEnterVehicle for the opposite hook.
See also GM:PlayerLeaveVehicle for a hook that will be called whenever a player exits any vehicle for any reason.
Determines whether or not a given player player can enter the given vehicle. Player:EnterVehicle will still call this hook.
Called just before GM:PlayerEnteredVehicle. See also GM:CanExitVehicle.
Determines if the player can kill themselves using the concommands kill or explode.
Determines if the player can unfreeze the entity.
Controls if a property can be used or not.
GM:CaptureVideo()
Called each frame to record demos to video using IVideoWriter.
This hook is called every frame regardless of whether or not a demo is being recorded
Called when a message is printed to the chat box. Note, that this isn't working with player messages even though there are arguments for it.
For player messages see GM:PlayerSay and GM:OnPlayerChat
GM:ChatTextChanged( string text )
Called whenever the content of the user's chat input box is changed.
boolean, string GM:CheckPassword( string steamID64, string ipAddress, string svPassword, string clPassword, string name )
Called when a non local player connects to allow the Lua system to check the password.
The default behaviour in the base gamemodes emulates what would normally happen. If sv_password is set and its value matches the password passed in by the client - then they are allowed to join. If it isn't set it lets them in too.
Called when a player's sign on state changes.
You cannot get a valid player object from the userID at any point during this hook. Issue Tracker: 4899
GM:CloseDermaMenus()
Called when derma menus are closed with CloseDermaMenus.
Called whenever an entity becomes a clientside ragdoll.
See GM:CreateEntityRagdoll for serverside ragdolls.
Called when a serverside ragdoll of an entity has been created.
See GM:CreateClientsideRagdoll for clientside ragdolls.
Allows you to change the players movements before they're sent to the server.
See Game Movement for an explanation on the move system.
Due to this hook being clientside only, it could be overridden by the user allowing them to completely skip your logic, it is recommended to use GM:StartCommand in a shared file instead.
GM:CreateTeams()
Teams are created within this hook using team. SetUp.
This hook is called before GM:PreGamemodeLoaded.
Called upon an animation event, this is the ideal place to call player animation functions such as Player:AddVCDSequenceToGestureSlot, Player:AnimRestartGesture and so on.
Handles the player's death.
This hook is not called if the player is killed by Player:KillSilent. See GM:PlayerSilentDeath for that.
GM:PlayerDeath is called after this hook
GM:PostPlayerDeath is called after that
Player:Alive will return false in this hook.
This hook is called every frame to draw all of the current death notices.
GM:DrawMonitors()
Called every frame before drawing the in-game monitors ( Breencast, in-game TVs, etc ), but doesn't seem to be doing anything, trying to render 2D or 3D elements fail.
GM:DrawOverlay()
Called after all other 2D draw hooks are called. Draws over all VGUI Panels and HUDs.
Unlike GM:HUDPaint, this hook is called with the game paused and while the Camera SWEP is equipped.
Only gets called when r_drawvgui is enabled. This is a rendering hook which provides a 2d rendering context.
boolean GM:DrawPhysgunBeam( Player ply, Weapon physgun, boolean enabled, Entity target, number physBone, Vector hitPos )
Allows you to override physgun effects rendering.
This is still called when physgun_drawbeams is set to 0, because this hook is also capable of overriding physgun sprite effects, while the convar does not.
Called right before an entity stops driving. Overriding this hook will cause it to not call drive. End and the player will not stop driving.
Called whenever a sound has been played. This will not be called clientside if the server played the sound without the client also calling Entity:EmitSound.
Called every time a bullet is fired from an entity.
This hook is called directly from Entity:FireBullets. Due to this, you cannot call Entity:FireBullets inside this hook or an infinite loop will occur crashing the game.
Called when a key-value pair is set on an entity on map spawn. Is not called by Entity:SetKeyValue.
See ENTITY:KeyValue for a scripted entities hook, and its scripted weapon alternative: WEAPON:KeyValue.
Called when an NW2Var is changed.
If a NW2Var is set on an entity that is based on a Lua Entity could result in the NW2Var being mixed up with other ones and being updated multiple times. Issue Tracker: 5455This hook is fired before the client value is actually changed. Calling the GetNW2 function for the specified variable name within this hook will return the old value, not the current/updated one.
This hook gets called for all NW2Vars on all Entities in a full update. The old value will be nil in this case.
If this hook seems to be called for no apparent reason, check if it's caused by a full update.
Called right before removal of an entity.
This hook is called clientside during full updates due to how networking works in the Source Engine.
This can happen when the client briefly loses connection to the server, and can be simulated via cl_fullupdate for testing purposes.
Called when an entity takes damage. You can modify all parts of the damage info in this hook.
Applying damage from this hook to the entity taking damage will lead to infinite loop/crash.
This hook polls the entity the player use action should be applied to.
The default behavior of this hook is in CBasePlayer::FindUseEntity. Despite CBasePlayer::FindUseEntity being defined shared, it is only called serverside in practice, so this hook will be only called serverside, as well. It is possible for modules to call it clientside, so the Lua code should still be treated as shared.
GM:FinishChat()
Runs when user cancels/finishes typing.
Called after GM:Move, applies all the changes from the CMoveData to the player.
See Game Movement for an explanation on the move system.
string GM:ForceDermaSkin()
Called to allow override of the default Derma skin for all panels.
This hook is only called on Lua start up, changing its value (or adding new hooks) after it has been already called will not have any effect.
GM:GameContentChanged()
Called when game content has been changed, for example an addon or a mountable game was (un)mounted.
An internal function used to get an untranslated string to show in the kill feed as the entity's name. See GM:SendDeathNotice
Called when a player takes damage from falling, allows to override the damage.
string GM:GetGameDescription()
Called when the game(server) needs to update the text shown in the server browser as the gamemode.
This hook (and the sv_gamename_override command) may not work on some popular gamemodes like DarkRP or Trouble Terrorist Town. This is not a bug, it's just how it works. See here for more information.
Also, it only works on dedicated servers and is called at regular intervals (about one second) even if the server has no players and the hibernation function is enabled.
number, number, number, number GM:GetMotionBlurValues( number horizontal, number vertical, number forward, number rotational )
Allows you to modify the Source Engine's motion blur shaders.
Called to determine preferred carry angles for the entity. It works for both, +use pickup and gravity gun pickup.
Due to nature of the gravity gun coding in multiplayer, this hook MAY seem to not work ( but rest assured it does ), due to clientside prediction not knowing the carry angles. The +use pickup doesn't present this issue as it doesn't predict the player carrying the object clientside ( as you may notice by the prop lagging behind in multiplayer )This hook can not override preferred carry angles of props such as the sawblade and the harpoon.
Returns the color for the given entity's team. This is used in chat and deathnotice text.
Returns the team color for the given team index.
GM:GrabEarAnimation( Player ply )
Override this hook to disable/change ear-grabbing in your gamemode.
Called when an entity is released by a gravity gun.
See GM:PhysgunDrop for the Physics Gun drop variant.
Called when an entity is picked up by a gravity gun.
See GM:OnPlayerPhysicsPickup for the player +use pickup variant.
See GM:OnPhysgunPickup for the Physics Gun pickup variant.
Called every tick to poll whether a player is allowed to pick up an entity with the gravity gun or not.
See GM:AllowPlayerPickup for the +USE pickup variant.
See GM:PhysgunPickup for the Physics Gun pickup variant.
Calls ENTITY:GravGunPickupAllowed on the entity being hovered every frame in Sandbox-derived gamemodes.
Called when an entity is about to be punted with the gravity gun (primary fire).
By default this function makes ENTITY:GravGunPunt work in Sandbox derived gamemodes.
Called when the mouse has been double clicked on any panel derived from CGModBase, such as the panel used by gui. EnableScreenClicker and the panel used by Panel:ParentToHUD.
By default this hook calls GM:GUIMousePressed.
Called whenever a players presses a mouse key on the context menu in Sandbox or on any panel derived from CGModBase, such as the panel used by gui. EnableScreenClicker and the panel used by Panel:ParentToHUD.
See GM:VGUIMousePressed for a hook that is called on all VGUI elements.
Called whenever a players releases a mouse key on the context menu in Sandbox or on any panel derived from CGModBase, such as the panel used by gui. EnableScreenClicker and the panel used by Panel:ParentToHUD.
Called to handle player armor reduction, when player receives damage.
Clarify hook order with other damage hooks.
Allows to override player driving animations.
Allows to override player crouch animations.
Called every frame by the player model animation system. Allows to override player jumping animations.
Called every frame by the player model animation system. Allows to override player landing animations.
Allows to override player noclip animations.
Allows to override player swimming animations.
Allows to override player flying ( in mid-air, not noclipping ) animations.
GM:HideTeam()
Hides the team selection panel.
Called when the client has picked up ammo. Override to disable default HUD notification.
GM:HUDDrawPickupHistory()
Renders the HUD pick-up history. Override to hide default or draw your own HUD.
GM:HUDDrawScoreBoard()
Called every frame to render the scoreboard.
It is recommended to use Derma and VGUI for this job instead of this hook. Called right after GM:HUDPaint.
This is a rendering hook which provides a 2d rendering context.
boolean GM:HUDDrawTargetID()
Called from GM:HUDPaint to draw player info when you hover over a player with your crosshair or mouse.
GM:HUDItemPickedUp( string itemName )
Called when an item has been picked up. Override to disable the default HUD notification.
GM:HUDPaint()
Called whenever the HUD should be drawn.
This is the ideal place to draw custom HUD elements.
To prevent the default game HUD from drawing, use GM:HUDShouldDraw.
This hook does not get called when the Camera SWEP is held, or when the esc menu is open.
If you need to draw in those situations, use GM:DrawOverlay instead.
This is a rendering hook which provides a 2d rendering context.
GM:HUDPaintBackground()
Called before GM:HUDPaint when the HUD background is being drawn.
Just like GM:HUDPaint, this hook will not be called when the main menu is visible. GM:PostDrawHUD does not have this behavior.
Things rendered in this hook will always appear behind things rendered in GM:HUDPaint.
This is a rendering hook which provides a 2d rendering context.
Called when the Gamemode is about to draw a given element on the client's HUD (heads-up display).
This hook is called HUNDREDS of times per second (more than 5 times per frame on average). You shouldn't be performing any computationally intensive operations.
GM:HUDWeaponPickedUp( Weapon weapon )
Called when a weapon has been picked up. Override to disable the default HUD notification.
GM:Initialize()
Called after the gamemode loads and starts.
No entities would be present at the time this hook is called, please see GM:InitPostEntity for a one time fire hook after all map entities have been initialized.
GM:InitPostEntity()
Called after all the entities are initialized. Starting from this hook LocalPlayer will return valid object.
At this point the client only knows about the entities that are within the spawnpoints' PVS (Potential Visibility Set). For instance, if the server sends an entity that is not within this PVS, the client will receive it as NULL entity.
Allows you to modify the supplied User Command with mouse input. This could be used to make moving the mouse do funky things to view angles.
Check if a player can spawn at a certain spawnpoint.
Called whenever a player pressed a key included within the IN keys.
For a more general purpose function that handles all kinds of input, see GM:PlayerButtonDown.
Despite being a predicted hook, it will still be called in singleplayer for your convenience.
Due to this being a predicted hook, ParticleEffects created only serverside from this hook will not be networked to the client, so make sure to do that on both realms.
Runs when a IN key was released by a player.
For a more general purpose function that handles all kinds of input, see GM:PlayerButtonUp.
Despite being a predicted hook, it will still be called in singleplayer for your convenience.
This is used internally - although you're able to use it you probably shouldn't.
Called from gm_load when the game should load a map.
Called while an addon from the Steam workshop is downloading. Used by default to update details on the fancy workshop download panel.
GM:MenuStart()
Called when menu. lua has finished loading.
GM:MouthMoveAnimation( Player ply )
Override this gamemode function to disable mouth movement when talking on voice chat.
The Move hook is called for you to manipulate the player's MoveData.
You shouldn't adjust the player's position in any way in the move hook. This is because due to prediction errors, the netcode might run the move hook multiple times as packets arrive late. Therefore you should only adjust the movedata construct in this hook.
Generally you shouldn't have to use this hook - if you want to make a custom move type you should look at the drive system.
This hook is called after GM:PlayerTick.
See Game Movement for an explanation on the move system.
boolean GM:NeedsDepthPass()
Returning true in this hook will cause it to render depth buffers defined with render. GetResolvedFullFrameDepth.
GM:NetworkEntityCreated( Entity ent )
Called when an entity has been created over the network.
Called when a player's SteamID has been validated by Steam.
See also GM:PlayerAuthed and Player:IsFullyAuthenticated.
This hook doesn't work intentionally in singleplayer because the SteamID is not validated in that case. This also applies to sv_lan 1 servers for every duplicate -multirun client.
Called whenever this entity changes its transmission state for this LocalPlayer, such as exiting or re entering the PVS (Potential Visibility Set).
This is the best place to handle the reset of Entity:SetPredictable, as this would be usually called when the player lags and requests a full packet update.
When the entity stops transmitting, Entity:IsDormant will only return true after this hook.
Called when a player has achieved an achievement. You can get the name and other information from an achievement ID with the achievements library.
Called when the local player presses TAB while having their chatbox opened.
boolean GM:OnCloseCaptionEmit( string soundScript, number duration, boolean fromPlayer, string fullText )
Called when a caption has been emitted to the closed caption box.
GM:OnContextMenuClose()
Called when the context menu keybind (+menu_context) is released, which by default is C.
This hook will not run if input. IsKeyTrapping returns true.
See also GM:OnContextMenuOpen.
GM:OnContextMenuOpen()
Called when the context menu keybind (+menu_context) is pressed, which by default is c.
See also GM:OnContextMenuClose.
Called when the crazy physics detection detects an entity with Crazy Physics.
Called when a player has been hurt by an explosion. Override to disable default sound effect.
GM:OnEntityCreated( Entity entity )
Called as soon as the entity is created. Very little of the entity's properties will be initialized at this stage. (keyvalues, classname, flags, anything), especially on the serverside.
Some entities on initial map spawn are passed through this hook, and then removed in the same frame. This is used by the engine to precache things like models and sounds, so always check their validity with IsValid. Removing the created entity during this event can lead to unexpected problems. Use timer. Simple( 0, . . . . ) to safely remove the entity.
Called when the Entity:WaterLevel of an entity is changed.
0 - The entity isn't in water.
1 - Slightly submerged (at least to the feet).
2 - The majority of the entity is submerged (at least to the waist).
3 - Completely submerged.
This hook can be considered a physics callback, so changing collision rules (Entity:SetSolidFlags) in it may lead to a crash!
GM:OnGamemodeLoaded()
Called when the gamemode is loaded.
LocalPlayer() returns NULL at the time this is run.
Called when a Lua error occurs.
On the server realm, this hook will only account for server-side errors, not client-side ones.
Called when a Addon Conflict occurs, only works in the Menu realm.
Called whenever an NPC is killed.
Called when the main menu has been blocked by GM:OnPauseMenuShow four times in a small interval. This is used internally to explain to the user that they can hold ⇧ shift to force open the main menu.
boolean GM:OnPauseMenuShow()
Called when the pause menu is attempting to be opened. Allows you to prevent the main menu from being opened that time.
The user can hold ⇧ shift to not call this hook. If the main menu is blocked multiple times in short succession, a warning will be displayed to the end user on how to bypass the hook.
GM:OnPermissionsChanged()
Called when a permission gets Granted or Revoked.
Called when a player freezes an entity with the physgun.
This is not called for players or NPCs being held with the physgun. Issue Tracker: 723
Called to when a player has successfully picked up an entity with their Physics Gun.
Not to be confused with GM:PhysgunPickup which is called multiple times to ask if the player should be able to pick up an entity.
See GM:GravGunOnPickedUp for the Gravity Gun pickup variant.
See GM:OnPlayerPhysicsPickup for the player +use pickup variant.
Called when a player reloads with the physgun. Override this to disable default unfreezing behavior.
We advise against using this. It may be changed or removed in a future update.
Use GM:PlayerChangedTeam instead, which works for every Player:SetTeam call.
Called when a player has changed team using GM:PlayerJoinTeam.
This hook will not work with hook. Add and it is only called manually from GM:PlayerJoinTeam by the base gamemode
Called whenever a player sends a chat message. For the serverside equivalent, see GM:PlayerSay.
The text input of this hook depends on GM:PlayerSay. If it is suppressed on the server, it will be suppressed on the client. This also means, that a message surpressed with this hook will be still visible to other clients.
Called when a player makes contact with the ground after a jump or a fall.
Called when a player jumps.
Called when a player +use drops an entity.
Called when a player +use pickups up an entity. This will be called after the entity passes though GM:AllowPlayerPickup.
See GM:GravGunOnPickedUp for the Gravity Gun pickup variant.
See GM:OnPhysgunPickup for the Physics Gun pickup variant.
GM:OnReloaded()
Called when gamemode has been reloaded by auto refresh.
It seems that this event can be triggered more than once for a single refresh event.
Called when the player's screen resolution of the game changes.
ScrW and ScrH will return the new values when this hook is called.
GM:OnSpawnMenuClose()
Called when a player releases the +menu bind on their keyboard, which is bound to Q by default.
GM:OnSpawnMenuOpen()
Called when a player presses the +menu bind on their keyboard, which is bound to q by default.
GM:OnTextEntryGetFocus( Panel panel )
Called when a DTextEntry gets focus.
This hook is run from DTextEntry:OnGetFocus and PANEL:OnMousePressed of DTextEntry.
GM:OnTextEntryLoseFocus( Panel panel )
Called when a DTextEntry loses focus.
Called when the player changes their weapon to another one - and their viewmodel model changes.
This is not always called clientside. Issue Tracker: 2473
Called when a player drops an entity with the Physgun.
See GM:GravGunOnDropped for the Gravity Gun drop variant.
Called to determine if a player should be able to pick up an entity with the Physics Gun.
See GM:OnPhysgunPickup for a hook which is called when a player has successfully picked up an entity.
See GM:GravGunPickupAllowed for the Gravity Gun pickup variant.
See GM:AllowPlayerPickup for the +USE pickup variant.
Called after player's reserve ammo count changes.
Called after the player gets their Player:UniqueID set for the first time. This hook will also be called in singleplayer.
See GM:NetworkIDValidated for a hook that is called with the player's SteamID is validated by Steam.
Runs when a bind has been pressed. Allows to block commands.
By using the "alias" console command, this hook can be effectively circumvented. To prevent this use input. TranslateAlias.
To stop the user from using +attack, +left and any other movement commands of the sort, please look into using GM:StartCommand instead. The third argument will always be true. Issue Tracker: 1176This does not run for function keys binds (F1-F12). Issue Tracker: 2888
Called when a player presses a button.
This will not be called if player has a panel opened with keyboard input enabled, use PANEL:OnKeyCodePressed instead.
Called when a player releases a button.
This will not be called if player has a panel opened with keyboard input enabled, use PANEL:OnKeyCodeReleased instead.
Decides whether a player can hear another player using voice chat.
This hook is called several times a tick, so ensure your code is efficient.
Returns whether or not a player is allowed to join a team
Returns whether or not a player is allowed to pick an item up. (ammo, health, armor)
Returns whether or not a player is allowed to pick up a weapon.
If this returns false, Player:Give won't work.
boolean GM:PlayerCanSeePlayersChat( string text, boolean teamOnly, Player listener, Player speaker )
Returns whether or not the player can see the other player's chat.
The speaker parameter does not have to be a valid Player object which happens when console messages are displayed for example.
Called when a player has changed team using Player:SetTeam.
Avoid calling Player:SetTeam in this hook as it may cause an infinite loop!Player:Team inside this hook will return oldTeam.
Called whenever a player is about to spawn something to see if they hit a limit for whatever they are spawning.
This hook will not be called in singleplayer, as singleplayer does not have limits.
This is used internally - although you're able to use it you probably shouldn't.
Called whenever a player's class is changed on the server-side with player_manager. SetPlayerClass.
Executes when a player connects to the server. Called before the player has been assigned a UserID and entity. See the player_connect gameevent for a version of this hook called after the player entity has been created.
This is only called clientside for listen server hosts. This is not called clientside for the local player.
Called when a player is killed by Player:Kill or any other normal means.
This hook is not called if the player is killed by Player:KillSilent. See GM:PlayerSilentDeath for that.
GM:DoPlayerDeath is called before this hook.
GM:PostPlayerDeath is called after this hook.
See Player:LastHitGroup if you need to get the last hit hitgroup of the player.
Player:Alive will return false in this hook.
Returns whether or not the default death sound should be muted.
Called every think while the player is dead. The return value will determine if the player respawns.
Overwriting this function will prevent players from respawning by pressing space or clicking.
This hook is not called for players with the FL_FROZEN flag applied. Issue Tracker: 1577
GM:PlayerDisconnected( Player ply )
Called when a player leaves the server. See the player_disconnect gameevent for a shared version of this hook.
This is not called in single-player or listen servers for the host. Issue Tracker: 3523
GM:PlayerDriveAnimate( Player ply )
Called to update the player's animation during a drive.
Called when a weapon is dropped by a player via Player:DropWeapon.
Also called when a weapon is removed from a player via Player:StripWeapon.
See also GM:WeaponEquip for a hook when a player picks up a weapon.
The weapon's Entity:GetOwner will be NULL at the time this hook is called.
WEAPON:OnDrop will be called before this hook is.
GM:PlayerEndVoice( Player ply )
Called when player stops using voice chat.
Called when a player enters a vehicle.
Called just after GM:CanPlayerEnterVehicle.
See also GM:PlayerLeaveVehicle.
Called before firing clientside animation events on a player model.
See GM:PlayerHandleAnimEvent for the serverside version.
boolean GM:PlayerFootstep( Player ply, Vector pos, number foot, string sound, number volume, CRecipientFilter filter )
Called whenever a player steps. Return true to mute the normal sound.
See GM:PlayerStepSoundTime for a related hook about footstep frequency.
This hook is called on all clients.
Called when a player freezes an object.
GM:PlayerHandleAnimEvent( Player ply, number event, number eventTime, number cycle, number type, string options )
Called before firing serverside animation events on the player models.
See GM:PlayerFireAnimationEvent for the clientside version.
Called when a player gets hurt.
Called when the player spawns for the first time.
See GM:PlayerSpawn for a hook called every player spawn.
This hook is called before the player has fully loaded, when the player is still in seeing the Starting Lua screen. For example, trying to use the Entity:GetModel function will return the default model (models/player. mdl). You can send net messages starting from the player_activate game event. Due to the above note, sending net messages to the spawned player in this hook are highly unreliable, and they most likely won't be received (more information here: https://github. com/Facepunch/garrysmod-requests/issues/718).
Workaround without networking:
local load_queue = {}
hook. Add( "PlayerInitialSpawn", "myAddonName/Load", function( ply )
load_queue[ ply ] = true
end )
hook. Add( "StartCommand", "myAddonName/Load", function( ply, cmd )
if load_queue[ ply ] and not cmd:IsForced() then
load_queue[ ply ] = nil
-- Send what you need here!
end
end )
With networking:
-- CLIENT
hook. Add( "InitPostEntity", "Ready", function()
net. Start( "cool_addon_client_ready" )
net. SendToServer()
end )-- SERVER
util. AddNetworkString( "cool_addon_client_ready" )
net. Receive( "cool_addon_client_ready", function( len, ply )
-- Send what you need here!
end )
Makes the player join a specified team. This is a convenience function that calls Player:SetTeam and runs the GM:OnPlayerChangedTeam hook.
Called when a player leaves a vehicle for any reason, including Player:ExitVehicle.
See GM:PlayerEnteredVehicle for the opposite hook.
For vehicles with exit animations, this will be called at the end of the animation, not at the start!
GM:PlayerLoadout( Player ply )
Called to give players the default set of weapons.
This function may not work in your custom gamemode if you have overridden your GM:PlayerSpawn and you do not use self. BaseClass. PlayerSpawn or hook. Call.
Called when a player tries to switch noclip mode.
GM:PlayerPostThink( Player ply )
Called after the player's think, just after GM:FinishMove.
On the client side, it is only called for the local player.
Request a player to join the team. This function will check if the team is available to join or not.
This hook is called when the player runs "changeteam" in the console.
To prevent the player from changing teams, see GM:PlayerCanJoinTeam
Called when a player dispatched a chat message. For the clientside equivalent, see GM:OnPlayerChat.
It may be more reliable to use gameevent/player_say to read messages serverside because addons commonly return values in this hook to change chat messages.
Called to determine a spawn point for a player to spawn at.
The spawn point entity will also impact the player's eye angle. For example, if the entity is upside down, the player's view will be as well.
Find a team spawn point entity for this player.
Called whenever view model hands needs setting a model. By default this calls PLAYER:GetHandsModel and if that fails, sets the hands model according to his player model.
GM:PlayerSetModel( Player ply )
Called whenever a player spawns and must choose a model. A good place to assign a model to a player.
This function may not work in your custom gamemode if you have overridden your GM:PlayerSpawn and you do not use self. BaseClass. PlayerSpawn or hook. Call.
Returns true if the player should take damage from the given attacker.
Applying damage from this hook to the player taking damage will lead to infinite loop/crash.
Allows to suppress player taunts.
GM:PlayerSilentDeath( Player ply )
Called when the player is killed by Player:KillSilent.
The player is already considered dead when this hook is called.
See GM:PlayerDeath for a hook which handles all other death causes.
GM:PostPlayerDeath is called after this hook.
Player:Alive will return true in this hook.
Called whenever a player spawns, including respawns.
See GM:PlayerInitialSpawn for a hook called only the first time a player spawns.
See the player_spawn gameevent for a shared version of this hook.
By default, in "base" derived gamemodes, this hook will also call GM:PlayerLoadout and GM:PlayerSetModel, which may override your Entity:SetModel and Player:Give calls. Consider using the other hooks or a 0-second timer.
GM:PlayerSpawnAsSpectator( Player ply )
Called to spawn the player as a spectator.
Determines if the player can spray using the impulse 201 console command.
Called when player starts taunting.
Called when a player starts using voice chat.
Set mp_show_voice_icons to 0, if you want disable icons above player.
Allows you to override the time between footsteps.
See GM:PlayerFootstep for a related hook about footstep sounds themselves.
This hook is called on all clients.
Called whenever a player attempts to either turn on or off their flashlight, returning false will deny the change.
Also gets called when using Player:Flashlight.
Called when a player attempts to switch their weapon.
Primary usage of this hook is to prevent/allow weapon switching, not to detect weapon switching. It will not be called for Player:SetActiveWeapon.
The Move hook is called for you to manipulate the player's CMoveData. This hook is called moments before GM:Move and GM:PlayerNoClip.
This hook will not run when inside a vehicle. GM:VehicleMove will be called instead.
Called when a player has been hit by a trace and damaged (such as from a bullet). Returning true overrides the damage handling and prevents GM:ScalePlayerDamage from being called.
Called when a player unfreezes an object.
Triggered when the player presses use on an object. Continuously runs until USE is released but will not activate other Entities until the USE key is released; dependent on activation type of the Entity.
GM:PopulateMenuBar( Panel menubar )
Called when it's time to populate the context menu menu bar at the top.
GM:PostCleanupMap()
Called right after the map has cleaned up (usually because game. CleanUpMap was called)
See also GM:PreCleanupMap.
GM:PostDraw2DSkyBox()
Called right after the 2D skybox has been drawn - allowing you to draw over it.
This is a rendering hook which provides a 3d rendering context.
GM:PostDrawEffects()
Called after rendering effects. This is where halos are drawn. Called just before GM:PreDrawHUD.
This is a rendering hook which provides a 2d rendering context.
GM:PostDrawHUD()
Called after GM:PreDrawHUD, GM:HUDPaintBackground and GM:HUDPaint but before GM:DrawOverlay.
Unlike GM:HUDPaint(Background) hooks, this will still be called when the main menu is visible. And so will be GM:PreDrawHUD
This is a rendering hook which provides a 2d rendering context.
GM:PostDrawOpaqueRenderables( boolean bDrawingDepth, boolean bDrawingSkybox, boolean isDraw3DSkybox )
Called after drawing opaque entities.
See also GM:PostDrawTranslucentRenderables and GM:PreDrawOpaqueRenderables.
This is a rendering hook which provides a 3d rendering context.
Called after the player hands are drawn.
GM:PostDrawSkyBox()
Called after drawing the 3D skybox. This will not be called if skybox rendering was prevented via the GM:PreDrawSkyBox hook.
See also GM:PostDraw2DSkyBox.
This is a rendering hook which provides a 3d rendering context.
GM:PostDrawTranslucentRenderables( boolean bDrawingDepth, boolean bDrawingSkybox, boolean isDraw3DSkybox )
Called after all translucent entities are drawn.
See also GM:PostDrawOpaqueRenderables and GM:PreDrawTranslucentRenderables.
This is a rendering hook which provides a 3d rendering context. This is still called when r_drawentities or r_drawopaquerenderables is disabled. Issue Tracker: 3295This is not called when r_drawtranslucentworld is disabled. Issue Tracker: 3296
Called after view model is drawn.
This is a rendering hook which provides a 3d rendering context. The 3D rendering context in this event is different from the main view. Every render operation will only be accurate with the view model entity.
Called every time a bullet pellet is fired from an entity.
This hook is called directly from Entity:FireBullets. Due to this, you cannot call Entity:FireBullets inside this hook or an infinite loop will occur crashing the game.
Called when an entity receives a damage event, after passing damage filters, etc.
Applying damage from this hook to the entity taking damage will lead to infinite loop/crash.
GM:PostGamemodeLoaded()
Called after the gamemode has loaded.
GM:PostPlayerDeath( Player ply )
Called right after GM:DoPlayerDeath, GM:PlayerDeath and GM:PlayerSilentDeath.
This hook will be called for all deaths, including Player:KillSilent
Player:Alive will return false in this hook.
Called after a player in your PVS (Potential Visibility Set) was drawn.
This is a rendering hook which provides a 3d rendering context.
Allows you to suppress post processing effect drawing.
GM:PostRender()
Called after the frame has been rendered.
GM:PostRenderVGUI()
Called after the VGUI has been drawn.
This is a rendering hook which provides a 2d rendering context.
GM:PreCleanupMap()
Called right before the map cleans up (usually because game. CleanUpMap was called)
See also GM:PostCleanupMap.
GM:PreDrawEffects()
Called just after GM:PreDrawViewModel and can technically be considered "PostDrawAllViewModels".
This is a rendering hook which provides a 3d rendering context.
GM:PreDrawHalos()
Called before rendering the halos. This is the place to call halo. Add. This hook is actually running inside of GM:PostDrawEffects.
This is a rendering hook which provides a 3d rendering context.
GM:PreDrawHUD()
Called just after GM:PostDrawEffects. Drawing anything in it seems to work incorrectly.
boolean GM:PreDrawOpaqueRenderables( boolean isDrawingDepth, boolean isDrawSkybox, boolean isDraw3DSkybox )
Called before all opaque entities are drawn.
See also GM:PreDrawTranslucentRenderables and GM:PostDrawOpaqueRenderables.
This is a rendering hook which provides a 3d rendering context.
Called before the player hands are drawn.
boolean GM:PreDrawSkyBox()
Called before the 3D sky box is drawn. This will not be called for maps with no 3D skybox, or when the 3d skybox is disabled. (r_3dsky 0)
See also GM:PostDrawSkyBox
This is a rendering hook which provides a 3d rendering context.
boolean GM:PreDrawTranslucentRenderables( boolean isDrawingDepth, boolean isDrawSkybox, boolean isDraw3DSkybox )
Called before all the translucent entities are drawn.
See also GM:PreDrawOpaqueRenderables and GM:PostDrawTranslucentRenderables.
This is a rendering hook which provides a 3d rendering context. This is still called when r_drawentities or r_drawopaquerenderables is disabled. Issue Tracker: 3295This is not called when r_drawtranslucentworld is disabled. Issue Tracker: 3296
Called before the view model has been drawn. This hook by default also calls this on weapons, so you can use WEAPON:PreDrawViewModel.
You can use GM:PreDrawEffects as a "PostDrawViewModel" hook as it is called just after the view model(s) are drawn.
This is a rendering hook which provides a 3d rendering context.
GM:PreDrawViewModels()
Called before view models and entities with RENDERGROUP_VIEWMODEL are drawn.
You can use GM:PreDrawEffects as a PostDrawViewModel hook as it is called just after the view model(s) are drawn.
This is a rendering hook which provides a 3d rendering context.
GM:PreGamemodeLoaded()
Called before the gamemode is loaded.
Called before the player is drawn.
Called by scripted_ents. Register.
Called when a Scripted Weapon (SWEP) is about to be registered, allowing addons to alter the weapon's SWEP table with custom data for later usage. Called internally from weapons. Register.
This will prevent in_attack from sending to server when player tries to shoot from C menu.
Render the scene. Used by the Stereoscopy post-processing effect.
Materials rendered in this hook require $ignorez parameter to draw properly.
Used to render post processing effects.
This is a rendering hook which provides a 2d rendering context.
GM:Restored()
Called when the game is reloaded from a Source Engine save system ( not the Sandbox saves or dupes ).
See GM:Saved for a hook that is called when such a save file is created.
GM:Saved()
Called when the game is saved using the Source Engine save system (not the Sandbox saves or dupes).
See GM:Restored for a hook that is called when such a save file is loaded.
See also the saverestore for relevant functions.
Called when an NPC takes damage.
This hook is called only when a specific hit group of the NPC is hit. In cases where the hitgroup doesn't matter, you should use GM:EntityTakeDamage instead!
This hook allows you to change how much damage a player receives when one takes damage to a specific body part.
This is called only for bullet damage a player receives, you should use GM:EntityTakeDamage instead if you need to detect ALL damage.
GM:ScoreboardHide()
Called when player released the scoreboard button (tab by default).
boolean GM:ScoreboardShow()
Called when player presses the scoreboard button (tab by default).
An internal function used to send a death notice event to all clients.
Sets player run and sprint speeds.
This is not a hook. Treat this as a utility function to set the player's speed.
SetupMove is called before the engine process movements. This allows us to override the players movement.
See Game Movement for an explanation on the move system.
Allows you to add extra positions to the player's PVS (Potential Visibility Set). This is the place to call AddOriginToPVS.
Allows you to use render. Fog* functions to manipulate skybox fog.
This will not be called for maps with no 3D skybox, or when the 3d skybox is disabled. (r_3dsky 0)
boolean GM:SetupWorldFog()
Allows you to use render. Fog* functions to manipulate world fog.
Called to decide whether a pair of entities should collide with each other. This is only called if Entity:SetCustomCollisionCheck was used on one or both entities.
Where applicable, consider using constraint. NoCollide or a logic_collision_pair entity instead - they are considerably easier to use and may be more appropriate in some situations.
This hook must return the same value consistently for the same pair of entities. If an entity changed in such a way that its collision rules change, you must call Entity:CollisionRulesChanged on that entity immediately - not in this hook and not in physics callbacks. The default Entity:CollisionRulesChanged has been found to be ineffective in preventing issues in this hook, a more reliable alternative can be found in the examples below. As long as you religiously follow the rules set by the examples this hook will work reliably without breaking, even a small mistake will break physics. This hook can cause all physics to break under certain conditions. Issue Tracker: 642
Called to determine if the LocalPlayer should be drawn.
If you're using this hook to draw a player for a GM:CalcView hook, then you may want to consider using the drawviewer variable you can use in your CamData structure table instead.
This hook has an internal cache that is reset at the start of every frame. This will prevent this hook from running in certain cases. This cache is reset in cam. Start and in a future update in render. RenderView when rendering extra views.
Called when a player executes gm_showhelp console command. (Default bind is f1)
GM:ShowSpare1( Player ply )
Called when a player executes gm_showspare1 console command ( Default bind is f3 ).
GM:ShowSpare2( Player ply )
Called when a player executes gm_showspare2 console command ( Default bind is f4 ).
Called when a player executes gm_showteam console command. ( Default bind is f2 )
GM:ShutDown()
Called whenever the Lua environment is about to be shut down, for example on map change, or when the server is going to shut down.
Player:SteamID, Player:SteamID64, and the like will return nil for the listen host here but work fine for other players.
Called when spawn icon is generated.
GM:SpawnMenuCreated()
Called when the Spawnmenu is Created.
Runs when the user tries to open the chat box.
Returning true won't stop the chatbox from taking VGUI focus. Issue Tracker: 855
Allows you to change the players inputs before they are processed by the server. This function is also called for bots, making it the best solution to control them.
This is basically a shared version of GM:CreateMove.
This hook is predicted, but not by usual means, it is called when a CUserCmd is generated on the client, and on the server when it is received, so it is necessary for this hook to be called clientside even on singleplayer
Called right before an entity starts driving. Overriding this hook will cause it to not call drive. Start and the player will not begin driving the entity.
GM:StartGame()
Called when you start a new game via the menu.
GM:Think()
Called every frame. This will be the same as GM:Tick on the server when there is no lag, but will only be called once every processed server frame during lag.
See GM:Tick for a hook that runs every tick on both the client and server.
On server, this hook WILL NOT run if the server is empty, unless you set the ConVar sv_hibernate_think to 1.
GM:Tick()
Called every server tick. Serverside, this is similar to GM:Think.
This hook WILL NOT run if the server is empty, unless you set the ConVar sv_hibernate_think to 1
Isn't call when CalcMainActivity return a valid override sequence id
Allows you to translate player activities.
Animation updates (pose params etc) should be done here.
Called when a variable is edited on an Entity (called by Edit Properties. . . menu). See Editable Entities for more information.
Called when you are driving a vehicle. This hook works just like GM:Move.
This hook is called before GM:Move and will be called when GM:PlayerTick is not.
Called when user clicks on a VGUI panel.
Called when a mouse button is pressed on a VGUI element or menu.
Called as a weapon entity is picked up by a player.
See also GM:PlayerDroppedWeapon.
At the time when this hook is called Entity:GetOwner will return NULL. The owner is set on the next frame. This will not be called when picking up a weapon you already have as the weapon will be removed and WEAPON:EquipAmmo will be called instead.
Called when an addon from the Steam workshop finishes downloading. Used by default to update details on the workshop downloading panel.
Called when an addon from the Steam workshop begins downloading. Used by default to place details on the workshop downloading panel.
GM:WorkshopDownloadProgress( number id, number imageID, string title, number downloaded, number expected )
Called while an addon from the Steam workshop is downloading. Used by default to update details on the fancy workshop download panel.
Called after GM:WorkshopStart.
GM:WorkshopEnd()
Called when downloading content from Steam workshop ends. Used by default to hide fancy workshop downloading panel.
Called while an addon from the Steam workshop is extracting. Used by default to update details on the fancy workshop download panel.
GM:WorkshopStart()
Called when downloading content from Steam workshop begins. Used by default to show fancy workshop downloading panel.
The order of Workshop hooks is this:
WorkshopStart
WorkshopDownloadTotals
These are called for each new item:
WorkshopDownloadFile
WorkshopDownloadProgress - This is called until the file is finished
WorkshopDownloadedFile
WorkshopEnd (this ones called once)
Called when UGC subscription status changes.
GM:WorkshopSubscriptionsMessage( string message )
Called when a Workshop Message is received?. Currently, it seems like the message will be #ugc. mounting every time.
When does this exactly get called?. If an addon is subscribed, unsubscribed, error occurs or on any event?
This is used internally - although you're able to use it you probably shouldn't.
Called by the engine when the game initially fetches subscriptions to be displayed on the bottom of the main menu screen.