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.

GM:PlayerSpawn SERVER

Called when a player spawns into the world.

hook.Add("PlayerSpawn", "MyAddon_PlayerSpawn", function(ply)
    -- your code here
end)
GM:PlayerDeath SERVER

Called when a player dies. Args: victim, inflictor, attacker.

hook.Add("PlayerDeath", "MyAddon_PlayerDeath", function(victim, inflictor, attacker)
    -- your code here
end)
GM:PlayerHurt SERVER

Called when a player takes damage.

hook.Add("PlayerHurt", "MyAddon_PlayerHurt", function(victim, attacker, healthRemaining, damageTaken)
    -- your code here
end)
GM:PlayerSay SERVER

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)
GM:Think SHARED

Runs every game tick. Keep logic minimal — runs very frequently.

hook.Add("Think", "MyAddon_Think", function()
    -- runs every tick
end)
GM:Initialize SERVER

Called when the gamemode is first initialized.

hook.Add("Initialize", "MyAddon_Initialize", function()
    -- setup code
end)
GM:InitPostEntity SHARED

Called after all entities in the map have been initialized.

hook.Add("InitPostEntity", "MyAddon_InitPostEntity", function()
    -- all entities ready
end)
GM:PlayerDisconnected SERVER

Called when a player disconnects from the server.

hook.Add("PlayerDisconnected", "MyAddon_PlayerDisconnected", function(ply)
    -- cleanup code
end)
GM:EntityTakeDamage SERVER

Called when any entity takes damage. Return true to override damage.

hook.Add("EntityTakeDamage", "MyAddon_EntityTakeDamage", function(target, dmginfo)
    -- modify dmginfo here
end)
GM:PlayerSpawnedProp SERVER

Called when a player spawns a prop entity.

hook.Add("PlayerSpawnedProp", "MyAddon_PlayerSpawnedProp", function(ply, model, ent)
    -- track spawns
end)
GM:PlayerCheckLimit SERVER

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)
GM:HUDPaint CLIENT

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)
GM:HUDShouldDraw CLIENT

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)
GM:PostDrawHUD CLIENT

Called after all HUD elements have been drawn.

hook.Add("PostDrawHUD", "MyAddon_PostDrawHUD", function()
    -- post-HUD drawing
end)
ENTITY:Initialize SHARED

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
ENTITY:Think SHARED

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
ENTITY:Use SERVER

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
ENTITY:OnRemove SERVER

Called just before a custom entity is removed from the world.

function ENT:OnRemove()
    -- cleanup timers, etc.
end
WEAPON:PrimaryAttack SHARED

Called when the player fires the primary weapon.

function SWEP:PrimaryAttack()
    self:ShootBullet(10, 1, 0.02)
    self:SetNextPrimaryFire(CurTime() + 0.1)
end
WEAPON:SecondaryAttack SHARED

Called when the player fires the secondary (right-click) weapon.

function SWEP:SecondaryAttack()
    self:SetNextSecondaryFire(CurTime() + 0.5)
end
WEAPON:Deploy SHARED

Called when this weapon is equipped/drawn by a player.

function SWEP:Deploy()
    self:SendWeaponAnim(ACT_VM_DRAW)
    return true
end
Private Garry's Mod hosting

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.

Rent a Garry's Mod server Real hardware · Full control panel · 98% SLA

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.