• Testing when a player dies and sending a message to chat
    10 replies, posted
Hi, so Iv been messing around for a while, and I though of while playing on a deathrun server. I basically want a lua script (CLIENT SIDE) that makes me say "Oh shit, I died." when I die. I have this, but it doesnt work: [CODE] GM:PlayerDeath( Player victim, Entity inflictor, Entity attacker ) Player:Say( string Ayyyy Im not dead!!!, boolean teamOnly=false ) end[/CODE] [editline]18th December 2015[/editline] PS I am really stupid, so try explaining in Layman's terms
First off player death is a server side only hook so it won't work client side. Not sure why you insist on it being a client side only it would be far easier to make it server side. Second you should be using [URL="https://wiki.garrysmod.com/page/hook/Add"]hook.Add()[/URL] because the way you have written it you are over riding the PlayerDeath hook telling it to only use that code included there. It's much better to use hook.Add. In addition you didn't create any variable to store the data retrieved by that hook, from the looks of it you left the default stuff from the wiki inside. So let's re-write this to suite your needs better. [CODE] -- NOTE: This script will only run serverside hook.Add("PlayerDeath", "chatPrintOnDeath", function(ply) -- Since you only want to say something when you die we do not need the other variables ply:PrintMessage(3, "Oh shit I died!") -- This is the only line you will need inside end) [/CODE] I chose to use [URL="https://wiki.garrysmod.com/page/Player/PrintMessage"]player:PrintMessage() [/URL] because it was the fastest ways however there are other ways you could achieve the same results you want using other functions.
So the reason I want it be client side is so when I die it says "Peace: O sheit I ded" or something.
The code I just wrote will do that exact thing, it will display in your chat "Oh shit I died!". There are no death hooks on the client side so you will have to do part of this on the server to detect when you have died. [B]Edited:[/B] I take that back I guess if you really wanted to you could use [URL="https://wiki.garrysmod.com/page/GM/AddDeathNotice"]AddDeathNotice()[/URL] It gets more complicated doing it this way but it can be done. [CODE] hook.Add("AddDeathNotice", "chatPrintOnDeath", function(attacker, attTeam, cause, victim) -- Variables from the hook only really need the victim if (!victim == LocalPlayer()) then return end-- checking if you are the one who died chat.AddText( Color(255,0,0) , "Oh shit I died!" ) -- Adds Text that will be colored red to the chat end) [/CODE]
Uhh, uhh. Im a nub at anything code related. Please use layman's terms.
I edited my post to include a code example so you can actually see it. Is there something specifically in that code you don't understand? If so just ask and I will try to answer it the best I can.
So again, its just server side? it WONT work client side?
No the second example I included will work on the client side. If you look at the wiki entires they will tell you whether the function is client side or server side. Sometimes they are both other times they are just the one. If it is server side it will have a blue square infront of it. If it is clientside it will have an orange square. If it is both then it will display a half and half square.
Oh, so I should put this into my gmod/garrysmod/lua/autorun right?
Correct and name the file something like cl_deathchat.lua
Oh ok. [editline]18th December 2015[/editline] Hum.... its not working... I restarted my game and apon death, nothing.
Sorry, you need to Log In to post a reply to this thread.