GMod gLua Hook & Library Reference
Searchable cheat-sheet for the most-used Garry's Mod Lua hooks and global library functions.
Each entry shows the realm tag (SERVER / CLIENT / SHARED) and a copy-paste hook.Add() skeleton.
Called when a player spawns into the world.
hook.Add("PlayerSpawn", "MyAddon_PlayerSpawn", function(ply)
-- your code here
end)
Called when a player dies. Args: victim, inflictor, attacker.
hook.Add("PlayerDeath", "MyAddon_PlayerDeath", function(victim, inflictor, attacker)
-- your code here
end)
Called when a player takes damage.
hook.Add("PlayerHurt", "MyAddon_PlayerHurt", function(victim, attacker, healthRemaining, damageTaken)
-- your code here
end)
Called when a player sends a chat message. Return "" to block the message.
hook.Add("PlayerSay", "MyAddon_PlayerSay", function(sender, text, teamChat)
-- return "" to block
end)
Runs every game tick. Keep logic minimal — runs very frequently.
hook.Add("Think", "MyAddon_Think", function()
-- runs every tick
end)
Called when the gamemode is first initialized.
hook.Add("Initialize", "MyAddon_Initialize", function()
-- setup code
end)
Called after all entities in the map have been initialized.
hook.Add("InitPostEntity", "MyAddon_InitPostEntity", function()
-- all entities ready
end)
Called when a player disconnects from the server.
hook.Add("PlayerDisconnected", "MyAddon_PlayerDisconnected", function(ply)
-- cleanup code
end)
Called when any entity takes damage. Return true to override damage.
hook.Add("EntityTakeDamage", "MyAddon_EntityTakeDamage", function(target, dmginfo)
-- modify dmginfo here
end)
Called when a player spawns a prop entity.
hook.Add("PlayerSpawnedProp", "MyAddon_PlayerSpawnedProp", function(ply, model, ent)
-- track spawns
end)
Check whether a player can spawn more of a given entity type. Return false to block.
hook.Add("PlayerCheckLimit", "MyAddon_CheckLimit", function(ply, limitType, current, max)
-- return false to block
end)
Called each frame after the HUD is drawn. Use draw.* functions here.
hook.Add("HUDPaint", "MyAddon_HUDPaint", function()
draw.SimpleText("Hello", "Default", 10, 10, Color(255,255,255))
end)
Return false to hide a specific HUD element by name.
hook.Add("HUDShouldDraw", "MyAddon_HUDShouldDraw", function(name)
if name == "CHudHealth" then return false end
end)
Called after all HUD elements have been drawn.
hook.Add("PostDrawHUD", "MyAddon_PostDrawHUD", function()
-- post-HUD drawing
end)
Called when a custom entity is first spawned and initialized.
function ENT:Initialize()
self:SetModel("models/props_phx/construct/metal_plate1x1.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
end
Called each tick for a custom entity's think routine.
function ENT:Think()
-- per-tick entity logic
self:NextThink(CurTime() + 0.1)
return true
end
Called when a player presses +use on this entity.
function ENT:Use(activator, caller, useType, value)
if activator:IsPlayer() then
-- player used entity
end
end
Called just before a custom entity is removed from the world.
function ENT:OnRemove()
-- cleanup timers, etc.
end
Called when the player fires the primary weapon.
function SWEP:PrimaryAttack()
self:ShootBullet(10, 1, 0.02)
self:SetNextPrimaryFire(CurTime() + 0.1)
end
Called when the player fires the secondary (right-click) weapon.
function SWEP:SecondaryAttack()
self:SetNextSecondaryFire(CurTime() + 0.5)
end
Called when this weapon is equipped/drawn by a player.
function SWEP:Deploy()
self:SendWeaponAnim(ACT_VM_DRAW)
return true
end
Run your own Garry's Mod server.
Rent a private Garry's Mod server on real hardware — full control-panel access, your mods, your configs, your rules. It's your server; run it your way.
Don't want to run it yourself? Our managed services & consulting team will set it up and keep it running for you — game servers, Windows, Linux, and cloud, from 10+ years of MSP work.