GameBanana shows no ads to members. Sign up now!
Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

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 5y ago
    17,504 points Ranked 326th
    24 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
    access_time 2y
    URL to post:
  • Reverend V92 avatar
    Reverend V92 username pic Joined 10y ago
    HL2 Manager HL2:MMod Manager HL2:DM Manager SOURCE Manager OC Manager Syn Manager GMod Manager GMod 9 Manager
    24,451 points Ranked 220th
    41 medals 2 legendary 8 rare
    • 2019 Top Contributor Medal icon
    • Returned 5000 times Medal icon
    • 2nd Place - A Bananite's Guide to... Contest Medal icon
    • 6 years a member Medal icon
    • Returned 1000 times Medal icon
    • Received thanks 50 times Medal icon
    access_time 2y
    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:
  • access_time 1y
    It is a very interesting question that must be mentioned within the process of creation of such type script. Usually, you can also use edubirdie as the best place for the creation of such kind work. Nevertheless, they are also good in any other similar.
    URL to post:
  • tocnaza avatar
    tocnaza Joined 10mo ago
    access_time 10mo edit 10mo
    URL to post:
  • Juliet123 avatar
    Juliet123 Joined 7d ago
    access_time 7d
    URL to post:
  • Ewald22 avatar
    Ewald22 Joined 11d ago
    access_time 5d edit 5d
    I bought the game today and played a round with my friend, i didnt know the chances were so slim because i did it 1st try. Viagra pills that are very helpful to solve male related issue and it effective for any person if you buy theses quality product you can visit. here and find best Viagra supplement for you
    Bananite avatar
    URL to post:


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


Ink Child avatar
Ink Child Joined 4y ago
219 points Ranked 56166th
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
  • 1
  • 1.8k
  • 6
  • 2y

More Customization Threads