Respawning Delay

How can I create a delay that when we die, we respawn after 30 seconds?? I know the timer.Create function, but im unable to include in my code…

[lua]function respawn( ply )
if ply:Alive() then
else
//If not (You are Dead)
timer.Create(“respawndelay”, 20, 1, ply:ConCommand(“rp_team1”))
ply:ChatPrint(“You are dead, you paied 50$ for the hospital and you will now respawn as a citizen…”)
ply:ConCommand( “rp_team1” )
end
end[/lua]

This is how to do it;
[lua]
function respawn( ply )
if ply:Alive() then return
elseif !ply:Alive() then
ply:ChatPrint(“You are dead, you paied 50$ for the hospital and you will now respawn as a citizen…”)
ply:Lock()
timer.Simple( 30, ply:UnLock() )
ply:ConCommand( “rp_team1” )
end
end
[/lua]
I made it in the Chatbox, so if you get an error, come back.
Oh and by the way, you added me so that I could help you, why didn’t you ask? :stuck_out_tongue:

I dont know why, your not in my steam friend and your profile link dont work… Add me in steam “bilbasio703”.

Thank you

[editline]02:41AM[/editline]

Its not working, but I think I havent specified what I wanted to do, I want to do that the player cant respawn and he respawns after 30 seconds. if you tried doing that, it didnt worked, but thank you anyway, you make me learn a new function :slight_smile:

Try using a hook so it’s called when you die something like:

[LUA]function SpawnDelay( ply, weapon, killer )

ply:Lock()

ply:ChatPrint(“You are dead, you paied 50$ for the hospital and you will now respawn as a citizen…”)

ply:ConCommand( “rp_team1” )

timer.Create(“DeathTimer”, 120, 1, function()
ply:UnLock()
ply:Spawn()
end)

end
hook.Add(“PlayerDeath”,“SpawnDelay”,SpawnDelay) [/LUA]

Hope that helps

Yah that one should work as I thought he had already hooked or concommanded his function somewhere.

Timer.create = bad idea since if someone else dies it will TAKE OVER the timer, Thus the person who first died will be stuck forever till he rejoins.

[lua]
function SpawnDelay( ply, weapon, killer )
ply:Lock()
ply:ChatPrint(“You are dead, you paied 50$ for the hospital and you will now respawn as a citizen…”)
– ply:AddMoney(-50) – Idk if your meta function is that or not
ply:ConCommand( “rp_team1” )

timer.Create("DeathTimer"..ply:UserID(), 120, 1, function()  
	ply:UnLock()  
	ply:Spawn()  
end)

end
hook.Add(“PlayerDeath”,“SpawnDelay”,SpawnDelay)
[/lua]

Simply append the users id to the timer and it’ll be unique. :buddy:

could do… Could also use to string ply

could do… Could also use md5 hash of to string ply

just use timer.Simple
10x times easier and sovlves that problem

I usually use

if ply.TIMER > CurTime() then DO SHIT HERE end

:stuck_out_tongue:

In most cases, so do I.