• PlayerDeath hook is causing some strange issues in TTT
    6 replies, posted
What I have setup is a custom leaderboard system that uses mysql and puts it on a web interface. Basically registers anything that the player does in-game that would call the hook (such as dying, or killing someone) and then sends that to the mysql database. This has all been working 100%, infact all of them work except for the deaths one. It is a simple script that counts total player's deaths in TTT. The hook is called when the player dies (hence PlayerDeath) and which then runs to check if its a player, and then runs the function that will write to the database. Here is just the hook. If anyone wasn't positive, updateDeathInfo is the function I have calling, and that is not the concern here. That function works just fine and so does calling it, as I have it working 100% in a couple other similar scripts. [CODE] hook.Add("PlayerDeath", "hs_log_player", function( ply ) for _, ply in pairs( player.GetAll() ) do if ply:IsPlayer() and !ply:IsBot() then updateDeathInfo( ply ) end end end) [/CODE] Now, the problem I'm having is weird. It may just be a TTT thing. When players die, it registers and adds them to the database, however they never "fully die". What I mean by this is, say a player dies, and they are supposed to be now MIA/confirmed dead, and their mic is usually yellow (generally most TTT's are like that). Well, they stay able to talk in alive voice chat, have a green(alive) voice box, and so on. But their body is dead, and that's about it. Now, this [I]only[/I] happens IF they are killed by the world. Any regular player kills them and this problem does not happen. Interestingly enough though, sometimes it doesn't register. I could have sworn it was working perfectly for a day then suddenly someone pointed out that when someone dies to the world, this happens. I have tried many variations of that hook, one of them being using "for k, v in pairs" and a different one removing the entire for k, v line, and replacing any "ply" with vic or kill usually.
That for statement is not what you want; that will update the player death info every time someone dies for everyone in the server. Remove the loop.
[QUOTE=code_gs;47252438]That for statement is not what you want; that will update the player death info every time someone dies for everyone in the server. Remove the loop.[/QUOTE] Would this be more ideal? [CODE] hook.Add("PlayerDeath", "hs_log_player", function( ply ) if ply:IsPlayer() and !ply:IsBot() then updateDeathInfo( ply ) end end) [/CODE] If so, with this hook we were still having the issue that I said up above with the whole "not fully dying" thing edit: Actually, what we had before that was working but did the same "not dead" thing was this: [CODE] hook.Add("PlayerDeath", "hs_log_player", function( vic, wep, ply ) if vic:IsPlayer() and !vic:IsBot() then updateDeathInfo( ply ) end end) [/CODE] It was vic, wep, ply I believe because I copied it over from my "kills" script that works.
[QUOTE=Jerpy;47252478]Would this be more ideal? [CODE] hook.Add("PlayerDeath", "hs_log_player", function( ply ) if ply:IsPlayer() and !ply:IsBot() then updateDeathInfo( ply ) end end) [/CODE] If so, with this hook we were still having the issue that I said up above with the whole "not fully dying" thing edit: Actually, what we had before that was working but did the same "not dead" thing was this: [CODE] hook.Add("PlayerDeath", "hs_log_player", function( vic, wep, ply ) if vic:IsPlayer() and !vic:IsBot() then updateDeathInfo( ply ) end end) [/CODE] It was vic, wep, ply I believe because I copied it over from my "kills" script that works.[/QUOTE] vic (1st argument) = player killed ply (2nd argument) = attacker/killer In the first script, you are sending the dead player into the function. In the second, you are sending in the killer or the alive player. I don't know how this is causing the "not fully dying" issue. If you remove the code completely, does it still occur?
Yes, removing the script completely from the server solves the issue. I also just noticed something. From a completely different scoreboard addon that I am no longer using since it causes some major lag issues, here is its death counter: [CODE] hook.Add("PlayerDeath", "ttt_stats_death", function( vic, wep, kil ) if vic:IsPlayer() and !vic:IsBot() then vic:SetNWInt("STATS_DEATH", vic:GetNWInt("STATS_DEATH") + 1) end end) [/CODE] obviously that is for local data, as this old scoreboard that I wont be using just sets all its info in data/tttstats/ So I'm going to replace that line that's after the 'then' with the function to run in my deathcounter, and I'll update you with how that works. Even though it is extremely similar to my second one posted above, it's got a couple differences. We'll see.
Sounds like a problem with your custom death function then, since all that does is network the deaths.
Well, turns out in the end having it as this worked: [CODE] hook.Add("PlayerDeath", "hs_log_player_tttdeaths", function( vic, wep, kil ) if vic:IsPlayer() and !vic:IsBot() then updateDeathInfo( vic ) end end) [/CODE] It updates just fine and only does it for the person that died, so this seems to be working. Solved.
Sorry, you need to Log In to post a reply to this thread.