Writing Hook to onplayerdeath

A Forum Thread for Garry's Mod

Hey everyone, I'm new to lua scripting (meaning I'm useless) I want to learn just a simple hook.
Okay, my friends and I were talking about hooking a player death to a caht bind, EG when I die in PH I saw in chat "Well that was an unexpected discovery" or when someone else dies it'll instantly say "[there name] couldn't handle the heat" instead of binding it to a key and pressing it when they die. I know this seems like a really amateur request, I've just been wanting to do this for a while now. Cheers
Sign up to access this!


  • ficool2 avatar
    ficool2 username pic Joined 4y ago
    12,315 points Ranked 381st
    23 medals 4 legendary 4 rare
    • 2017 Top Contributor Medal icon
    • 30 submissions featured Medal icon
    • Reached 100 subscribers Medal icon
    • Returned 5000 times Medal icon
    • Returned 1000 times Medal icon
    • 10 submissions featured Medal icon
    URL to post:
  • Reverend V92 avatar
    Reverend V92 username pic Joined 8y ago
    4,755 points Ranked 1090th
    22 medals 3 rare
    • 2nd Place - A Bananite's Guide to... Contest Medal icon
    • 6 years a member Medal icon
    • Returned 1000 times Medal icon
    • Building Bridges Entrant Medal icon
    • Became a Studio Leader Medal icon
    • Reached 1,000 Points Medal icon
    There's several ways to do this. For a gamemode, this is the hook you're looking for.

    However, you're going to need access to the game mode itself to use that one, as it's a gamemode hook.

    If you just want to make a hook that runs on every player death, consider using the PlayerDeath hook.

    Rough untested example of this:
    if !ConVarExists( "vnt_death_messages" ) then CreateConVar(    "vnt_death_messages" , "0" , { FCVAR_REPLICATED , FCVAR_ARCHIVE } , "(Boolean) Toggles custom death messages when players die." ) end

    local function VNTPlayerDeathChatPrint( vic, atk, kil )
        if GetConVarNumber( "vnt_death_messages" ) != 0 then
            local PlayerList = player.GetAll( )
            local Victim = vic
            local Killer = kil
            if Victim:IsPlayer( ) then

                if Killer != nil then
                    PlayerList:PrintMessage( HUD_PRINTCENTER , Victim .. " has been killed by " .. Killer )


                    PlayerList:PrintMessage( HUD_PRINTCENTER , Victim .. " has been killed!" )


    hook.Add("PlayerDeath", "VNTPlayerDeathChatPrint", VNTPlayerDeathChatPrint)

    Source Engine Wizard avatar
    Source Engine Wizard
    URL to post:


Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code


Ink Child avatar
Ink Child Joined 2y ago
215 points Ranked 18942nd

Ink Child
Sign up to access this!
Sign up to access this!
Sign up to access this!


Sign up to access this!



  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • Share on Google+


  • 2 Posts
  • 3moSubmitted

More Customization Threads

bcp.crwdcntrl.net tracking pixel