[TTT] Best way to check for round-ending death?


What is the best way to test if a player death in TTT is the final, round-winning death of a TTT round? My current solution (which feels ugly and inefficient) is to count up how many players are left alive in each role and check the role of the dead player, in a PlayerDeath hook. It crossed my mind to delay the check a few seconds and use GetRoundState(), but with slow motion setting up the timer with the right delay is a little finicky. There is a hook for the round ending, but how would I get the data of the last death?

Are there some utility functions somewhere that can help? Where would I find them (I have found util.GetAlivePlayers() and CountTraitors())?

Any help would be appreciated.

in the death hook, count the number of alive players in the role of the person that died. If the number is 0, then the guy that just died is the last of his role.

local last_death
hook.Add(“PlayerDeath”, “CoolHookName_”, function(ply)
last_death = ply

hook.Add(“TTTEndRound”, “CoolHookName_2”, function®
if last_death then
print(r, last_death)
– no one died

hook.Add(“TTTBeginRound”, “CoolHookName_3”, function() – this function is necessary because if no one dies then the person who died the previous round gets “credit”
last_death = nil

This is essentially exactly what my current solution is, and I am not happy with it. (As an aside, counting players on death seems inconsistent. I wasn’t getting the right result sometimes.)

Genius, thanks a bunch!

(I have no idea why that was marked “dumb,” but them I say: this is as clean and simple as you can possibly get and is orders of magnitude more efficient than just about every other solution I have seen in many existing popular scripts.)