Rage Quit

Im using this code TTT.


local function PlaySound( )
if GetRoundState() == ROUND_ACTIVE then
ChatPrint(Nick()…" is a pussy.")

hook.Add(“PlayerDisconnected”, “GuyLeft”, PlaySound)

Instead how would I make it so it only plays the sound if they disconnect 10 seconds after dieing.

start a timer right after the player death, when the timer ends check if the player is connected if not then play the sound.

I’d do it so the timer starts on player death and when it does it sets a variable to true. Then in 10 seconds it would set it to false. But while it is true, if the player leaves, then play the sound.

Or you could just do
[lua]ply.LastDeathTime = CurTime()[/lua]
Each time a player dies then when someone leaves do the check, that way you are not doing pointless checks every think

You’re not doing pointless checks with every think the way we’re doing it. You only check when the player disconnects. But yes, your way is probably best.

[lua]hook.Add( “PlayerDeath”, “WhenDidThePlayerDie?”, function( Player )
Player.DeathTime = CurTime()
end )

hook.Add( “PlayerDisconnected”, “PlayerDisconnectedDuh”, function( Player )
if Player.DeathTime and CurTime() - Player.DeathTime <= 10 and GetRoundState() == ROUND_ACTIVE then
BroadcastLua( “surface.PlaySound( ‘ragequit.mp3’ )” )
PrintMessage( HUD_PRINTTALK, Player:Nick() … " ragequit." )
end )[/lua]

Have fun.

And would this go into a serverside file or autorun?