Garry's Mod Wiki

GM

Hooks that are available for all gamemodes based on base gamemode.

See also: GM structure.

Events

boolean GM:AcceptInput( Entity ent, string input, Entity activator, Entity caller, any value )
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.
number GM:AdjustMouseSensitivity( number defaultSensitivity )
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.
table GM:CalcView( Player ply, Vector origin, Angle angles, number fov, number znear, number zfar )
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.
boolean GM:CanEditVariable( Entity ent, Player ply, string key, string val, table editor )
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.
boolean GM:CanPlayerEnterVehicle( Player player, Vehicle vehicle, number role )
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.
boolean GM:CanPlayerUnfreeze( Player player, Entity entity, PhysObj phys )
Determines if the player can unfreeze the entity.
boolean GM:CanProperty( Player ply, string property, Entity ent )
Controls if a property can be used or not.
boolean GM:CanUndo( Player ply, table undo )
Called whenever a players tries to undo.
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
boolean GM:ChatText( number index, string name, string text, string type )
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
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.
GM:ClientSignOnStateChanged( number userID, number oldState, number newState )
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
Called when derma menus are closed with CloseDermaMenus.
GM:CreateClientsideRagdoll( Entity entity, Entity ragdoll )
Called whenever an entity becomes a clientside ragdoll. See GM:CreateEntityRagdoll for serverside ragdolls.
GM:CreateEntityRagdoll( Entity owner, Entity ragdoll )
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.
Teams are created within this hook using team. SetUp. This hook is called before GM:PreGamemodeLoaded.
number GM:DoAnimationEvent( Player ply, number event, number data = 0 )
Called upon an animation event, this is the ideal place to call player animation functions such as Player:AddVCDSequenceToGestureSlot, Player:AnimRestartGesture and so on.
GM:DoPlayerDeath( Player ply, Entity attacker, CTakeDamageInfo dmg )
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.
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.
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.
string GM:EntityKeyValue( Entity ent, string key, string value )
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.
GM:EntityNetworkedVarChanged( Entity ent, string name, any oldval, any newval )
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.
GM:EntityRemoved( Entity ent, boolean fullUpdate )
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.
Entity GM:FindUseEntity( Player ply, Entity defaultEnt )
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.
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.
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.
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.
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.
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.
GM:GUIMouseDoublePressed( number mouseCode, Vector aimVector )
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.
GM:GUIMousePressed( number mouseCode, Vector aimVector )
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.
GM:GUIMouseReleased( number mouseCode, Vector aimVector )
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.
boolean GM:HandlePlayerLanding( Player ply, Vector velocity, boolean onGround )
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.
GM:HUDAmmoPickedUp( string itemName, number amount )
Called when the client has picked up ammo. Override to disable default HUD notification.
Renders the HUD pick-up history. Override to hide default or draw your own HUD.
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.
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.
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.
Called when a weapon has been picked up. Override to disable the default HUD notification.
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.
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.
boolean GM:IsSpawnpointSuitable( Player ply, Entity spawnpoint, boolean makeSuitable )
Check if a player can spawn at a certain spawnpoint.
GM:KeyPress( Player ply, number key )
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.
GM:KeyRelease( Player ply, number key )
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.
GM:LoadGModSave( string data, string map, number timestamp )
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.
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.
Returning true in this hook will cause it to render depth buffers defined with render. GetResolvedFullFrameDepth.
Called when an entity has been created over the network.
GM:NetworkIDValidated( string name, string steamID, string ownerID )
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.
GM:NotifyShouldTransmit( Entity entity, boolean shouldtransmit )
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.
GM:OnAchievementAchieved( Player ply, number achievement )
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.
Called when the player cleans up something.
boolean GM:OnCloseCaptionEmit( string soundScript, number duration, boolean fromPlayer, string fullText )
Called when a caption has been emitted to the closed caption box.
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.
Called when the context menu keybind (+menu_context) is pressed, which by default is c. See also GM:OnContextMenuClose.
GM:OnCrazyPhysics( Entity ent, PhysObj physobj )
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!
Called when the gamemode is loaded. LocalPlayer() returns NULL at the time this is run.
GM:OnLuaError( string error, string realm, table stack, string name, string id )
Called when a Lua error occurs. On the server realm, this hook will only account for server-side errors, not client-side ones.
GM:OnNotifyAddonConflict( string addon1, string addon2, string fileName )
Called when a Addon Conflict occurs, only works in the Menu realm.
GM:OnNPCKilled( NPC npc, Entity attacker, Entity inflictor )
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.
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.
Called when a permission gets Granted or Revoked.
GM:OnPhysgunFreeze( Entity weapon, PhysObj physobj, Entity ent, Player ply )
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
GM:OnPhysgunPickup( Player ply, Entity ent )
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.
GM:OnPlayerChangedTeam( Player ply, number oldTeam, number newTeam )
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
boolean GM:OnPlayerChat( Player ply, string text, boolean teamChat, boolean isDead )
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.
boolean GM:OnPlayerHitGround( Entity player, boolean inWater, boolean onFloater, number speed )
Called when a player makes contact with the ground after a jump or a fall.
GM:OnPlayerJump( Entity player, number speed )
Called when a player jumps.
GM:OnPlayerPhysicsDrop( Player ply, Entity ent, boolean thrown )
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.
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.
GM:OnScreenSizeChanged( number oldWidth, number oldHeight, number newWidth, number newHeight )
Called when the player's screen resolution of the game changes. ScrW and ScrH will return the new values when this hook is called.
Called when a player releases the +menu bind on their keyboard, which is bound to Q by default.
Called when a player presses the +menu bind on their keyboard, which is bound to q by default.
Called when a DTextEntry gets focus. This hook is run from DTextEntry:OnGetFocus and PANEL:OnMousePressed of DTextEntry.
Called when a DTextEntry loses focus.
boolean GM:OnUndo( string name, string customText )
Called when the player undoes something.
GM:OnViewModelChanged( Entity viewmodel, string oldModel, string newModel )
Called when the player changes their weapon to another one - and their viewmodel model changes. This is not always called clientside. Issue Tracker: 2473
GM:PhysgunDrop( Player player, Entity entity )
Called when a player drops an entity with the Physgun. See GM:GravGunOnDropped for the Gravity Gun drop variant.
boolean GM:PhysgunPickup( Player player, Entity entity )
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.
GM:PlayerAmmoChanged( Player ply, number ammoID, number oldCount, number newCount )
Called after player's reserve ammo count changes.
GM:PlayerAuthed( Player ply, string steamid, string uniqueid )
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.
boolean GM:PlayerBindPress( Player ply, string bind, boolean pressed, number code )
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
GM:PlayerButtonDown( Player ply, number button )
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.
GM:PlayerButtonUp( Player ply, number button )
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.
GM:PlayerChangedTeam( Player ply, number oldTeam, number newTeam )
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.
boolean GM:PlayerCheckLimit( Player ply, string limitName, number current, number defaultMax )
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.
GM:PlayerClassChanged( Player ply, number newID )
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.
GM:PlayerConnect( string name, string ip )
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.
GM:PlayerDeath( Player victim, Entity inflictor, Entity attacker )
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
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
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.
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.
GM:PlayerFrozeObject( Player ply, Entity ent, PhysObj physobj )
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.
GM:PlayerHurt( Player victim, Entity attacker, number healthRemaining, number damageTaken )
Called when a player gets hurt.
GM:PlayerInitialSpawn( Player player, boolean transition )
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 )
GM:PlayerJoinTeam( Player ply, number team )
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!
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.
boolean GM:PlayerNoClip( Player ply, boolean desiredState )
Called when a player tries to switch noclip mode.
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
string GM:PlayerSay( Player sender, string text, boolean teamChat )
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.
Entity GM:PlayerSelectSpawn( Player ply, boolean transition )
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.
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.
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.
GM:PlayerSpawn( Player player, boolean transition )
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.
Called to spawn the player as a spectator.
boolean GM:PlayerSpray( Player sprayer )
Determines if the player can spray using the impulse 201 console command.
GM:PlayerStartTaunt( Player ply, number act, number length )
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.
boolean GM:PlayerSwitchWeapon( Player player, Weapon oldWeapon, Weapon newWeapon )
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.
GM:PlayerTick( Player player, CMoveData mv )
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.
GM:PlayerUnfrozeObject( Player ply, Entity ent, PhysObj physobj )
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.
Called right after the map has cleaned up (usually because game. CleanUpMap was called) See also GM:PreCleanupMap.
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.
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.
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.
GM:PostDrawPlayerHands( Entity hands, Entity vm, Player ply, Weapon weapon )
Called after the player hands are drawn.
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
GM:PostDrawViewModel( Entity viewmodel, Player player, Weapon weapon )
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.
Called after the gamemode has loaded.
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.
GM:PostPlayerDraw( Player ply, number flags )
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.
Called after the frame has been rendered.
Called after the VGUI has been drawn. This is a rendering hook which provides a 2d rendering context.
GM:PostUndo( table undo, number count )
Called just after performing an undo.
Called right before the map cleans up (usually because game. CleanUpMap was called) See also GM:PostCleanupMap.
Called just after GM:PreDrawViewModel and can technically be considered "PostDrawAllViewModels". This is a rendering hook which provides a 3d rendering context.
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.
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.
boolean GM:PreDrawPlayerHands( Entity hands, Entity vm, Player ply, Weapon weapon )
Called before the player hands are drawn.
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.
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.
Called before the gamemode is loaded.
boolean GM:PrePlayerDraw( Player player, number flags )
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.
Called before the renderer is about to start rendering the next frame.
GM:PreUndo( table undo )
Called just before performing an undo.
This will prevent in_attack from sending to server when player tries to shoot from C menu.
GM:PropBreak( Player attacker, Entity prop )
Called when a prop has been destroyed.
boolean GM:RenderScene( Vector origin, Angle angles, number fov )
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.
GM:ScaleNPCDamage( NPC npc, number hitgroup, CTakeDamageInfo dmginfo )
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.
Called when player released the scoreboard button (tab by default).
Called when player presses the scoreboard button (tab by default).
GM:SendDeathNotice( Entity attacker, Entity inflictor, Entity victim, number flags )
An internal function used to send a death notice event to all clients.
GM:SetPlayerSpeed( Player ply, number walkSpeed, number runSpeed )
Sets player run and sprint speeds. This is not a hook. Treat this as a utility function to set the player's speed.
GM:SetupMove( Player ply, CMoveData mv, CUserCmd cmd )
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.
GM:SetupPlayerVisibility( Player ply, Entity viewEntity )
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)
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.
GM:ShowHelp( Player ply )
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 ).
GM:ShowTeam( Player ply )
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.
GM:SpawniconGenerated( string lastmodel, string imagename, number modelsleft )
Called when spawn icon is generated.
Called when the Spawnmenu is Created.
boolean GM:StartChat( boolean isTeamChat )
Runs when the user tries to open the chat box. Returning true won't stop the chatbox from taking VGUI focus. Issue Tracker: 855
GM:StartCommand( Player ply, CUserCmd ucmd )
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.
GM:UpdateAnimation( Player ply, Vector velocity, number maxSeqGroundSpeed )
Animation updates (pose params etc) should be done here.
GM:VariableEdited( Entity ent, Player ply, string key, string val, table editor )
Called when a variable is edited on an Entity (called by Edit Properties. . . menu). See Editable Entities for more information.
GM:VehicleMove( Player ply, Vehicle veh, CMoveData mv )
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.
GM:VGUIMousePressed( Panel pnl, number mouseCode )
Called when a mouse button is pressed on a VGUI element or menu.
GM:WeaponEquip( Weapon weapon, Player owner )
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.
GM:WorkshopDownloadFile( number id, number imageID, string title, number size )
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.
GM:WorkshopDownloadTotals( number remain, number total )
Called after GM:WorkshopStart.
Called when downloading content from Steam workshop ends. Used by default to hide fancy workshop downloading panel.
GM:WorkshopExtractProgress( number id, number ImageID, string title, number percent )
Called while an addon from the Steam workshop is extracting. Used by default to update details on the fancy workshop download panel.
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.
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.