Hi, I ask you to bare with me as I am very new to Lua coding (just started to learn ~1 week ago).
I'm currently starting up my first ever Garry's Mod server, and have no previous experience with this stuff, and I've basically learned everything I know about setting stuff up as I went along. Right now, I'm trying to add a killer notifier, which tells you who killed you, and their role when you die. I've tried adding a couple that I've found while lurking google, but all of them so far have failed to work (something causes dead people to be seen as alive and unable to spectate people and able to talk in all chat). I'm not sure if that's because of some sort of conflict with other things (I've read it has something to do with the hook), but I've been trying to add another one, and I can't seem to figure out where to add the script.
The code is:
[code]
function TTTDeath(ply, attacker, dmginfo)
if IsValid(attacker) and attacker:IsPlayer() then
if attacker:IsTraitor() then
ply:ChatPrint("You were killed by "..attacker:Nick().." who is a traitor.")
elseif attacker:IsInnocent() then
ply:ChatPrint("You were killed by "..attacker:Nick().." who is an innocent.")
else not attacker:IsPlayer() then
ply:ChatPrint("You were killed by the world.")
end
end
end
hook.Add("DoPlayerDeath", "TTTDeaths", TTTDeath)
[/code]
My first question is whether this code will actually work (again, I'm very new to Lua, so forgive me if it's an extremely stupid question). My second question is if it will work, where would I put the code?
Thanks a bunch for taking a look at this, and I once again do apologize if I seem ignorant or if I'm asking what is a simple question. Any help is greatly appreciated, even if it's only pointing me in the right direction.
[B]EDIT:[/B]
[B]The working code is posted here:[/B]
[code]
function TTTDeath(ply, attacker, dmginfo)
if IsValid(attacker) and attacker:IsPlayer() then
if attacker:IsTraitor() then
ply:ChatPrint("You were killed by "..attacker:Nick().." who is a traitor.")
else
ply:ChatPrint("You were killed by "..attacker:Nick().." who is an innocent.")
end
else
ply:ChatPrint("You were killed by the world.")
end
end
hook.Add("DoPlayerDeath", "TTTDeaths", TTTDeath)
[/code]
"Killed by the world" won't work because you checked at the beginning if the attacker is a player.
Thank you! I think I may have fixed it now, I moved the "Killed by the world" part outside of that if statement and made it into an elseif portion of the first one. Not sure if this is 100% correct, but I've changed it to look like this:
[code]
function TTTDeath(ply, attacker, dmginfo)
if IsValid(attacker) and attacker:IsPlayer() then
if attacker:IsTraitor() then
ply:ChatPrint("You were killed by "..attacker:Nick().." who is a traitor.")
elseif attacker:IsInnocent() then
ply:ChatPrint("You were killed by "..attacker:Nick().." who is an innocent.")
end
elseif IsValid(attacker) and not attacker:IsPlayer() then
ply:ChatPrint("You were killed by the world.")
end
end
hook.Add("DoPlayerDeath", "TTTDeaths", TTTDeath)
[/code]
Would it work now?
If it does, where exactly would I put it? (I'm assuming lua/autorun/server, but I'm not completely sure)
Thanks again for the help, I appreciate it.
seems like it'd work to me.
Alright, so I tried the script out, and there was a problem with it. Once it was in, the traitor killer notifiers worked fine (showed the death message if it was a traitor that killed you), but if it was an innocent or another source of damage, the body of the killed person would disappear and there would be no death message. I tweaked it a bit and finally got it to work flawlessly (so far). I'm guessing the issue was in the "attacker:IsInnocent()" bit, due to the fact that once I edited it and removed that part, it began working for everyone. I put this in lua/autorun/server.
I'll go ahead and post the code here, just in case any other lost soul is about to waste hours of their time looking for something like this.
[code]
function TTTDeath(ply, attacker, dmginfo)
if IsValid(attacker) and attacker:IsPlayer() then
if attacker:IsTraitor() then
ply:ChatPrint("You were killed by "..attacker:Nick().." who is a traitor.")
else
ply:ChatPrint("You were killed by "..attacker:Nick().." who is an innocent.")
end
else
ply:ChatPrint("You were killed by the world.")
end
end
hook.Add("DoPlayerDeath", "TTTDeaths", TTTDeath)
[/code]
Thanks again for the help, I hope I can return the favor to someone with this.
Sorry, you need to Log In to post a reply to this thread.