Respawn Timer (disallow respawn without waiting x seconds)
9 replies, posted
There's not much more I can say that isn't in the title.
I'd like an admin only console command, though, that allows me to change the respawn time, so at times it could be no time at all.
You mean something like this?
[lua]
Code
-- Set the maximum time in seconds before a player must respawn
maxdeathtime = 20;
-- Create a hook for the GM:PlayerDeath() function that
-- sets our two variables when the player dies
function player_initdeath( ply, wep, killer )
ply.deathtime = 0; -- set the number of seconds dead
ply.nextsecond = CurTime() + 1; -- set the time when we will add to the number of seconds dead
end
hook.Add( "PlayerDeath", "player_initalize_dvars", player_initdeath );
function playerforcerespawn( ply )
if (CurTime()>ply.nextsecond) then --If the current time has execeeded our next second add time
if (ply.deathtime < maxdeathtime) then --If the number of seconds dead less than our max death time
ply.deathtime = ply.deathtime + 1; --add one to the number of seconds dead
ply.nextsecond = CurTime()+1; --set our next death second add time
else --Otherwise
ply.deathtime = nil; --erase our deathtime variable by seting to nil
ply.nextsecond = nil; --erase our new add time storage by seting to nil
ply:Spawn() --tell the player to spawn
end
end
end
hook.Add( "PlayerDeathThink", "player_step_forcespawn", playerforcerespawn
[/lua]
It makes them respawn in this certain time.
Here's an addon to that script to have a console command.
[lua]
concommand.Add("RespawnTime",function(ply,cmd,args)
if (ply:IsAdmin()||ply:IsSuperAdmin()) then
maxdeathtime=tonumber(args[1])
end
)
[/lua]
I don't want to force them to respawn, I just want to have players not be allowed to respawn until x seconds has passed. Thank you for those scripts, though, I may find a use for them some time and will keep them in mind.
[QUOTE=Cardcapture1;24947584]Here's an addon to that script to have a console command.
[lua]
concommand.Add("RespawnTime",function(ply,cmd,args)
if (ply:IsAdmin()||ply:IsSuperAdmin()) then
maxdeathtime=tonumber(args[1])
end
)
[/lua][/QUOTE]
ply:IsAdmin() returns true for superadmins aswell.
I tried making one for you, but I ended up failing, the only way I could think of was to make an invisible derma menu with those methods:
[b][url=http://wiki.garrysmod.com/?title=Panel.RequestFocus]Panel.RequestFocus [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[b][url=http://wiki.garrysmod.com/?title=Panel.KillFocus]Panel.KillFocus [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Maybe you can get somewhere using those 2 functions
Here you go
[lua]
CreateConVar("respawnsecs", 10, FCVAR_NOTIFY)
function SetRespawnSeconds(ply, cmd, args)
if ply:IsAdmin() then
RunConsoleCommand("respawnsecs", tonumber(args[1]))
else return end
end
concommand.Add("setrespawnsecs", SetRespawnSeconds)
local function RespawnPlayer(ply)
ply:UnLock()
ply:ChatPrint("You can respawn now")
end
function ForcePlayerRespawn(ply)
if GetConVarNumber("respawnsecs") ~= 0 then
ply:Lock()
ply:ChatPrint("You have to wait " .. GetConVarNumber("respawnsecs") .. " seconds before you can respawn")
timer.Simple(GetConVarNumber("respawnsecs"), RespawnPlayer, ply)
end
end
hook.Add("PlayerDeath", "ForcePlayerRespawn", ForcePlayerRespawn)
[/lua]
Setting respawnsecs to 0 disables this script
Working awesome, thank you so much :)
yo where do I put the code
server side
also, yo: Posting Guidelines (14th December 2018) and Developers Board Rul..
Sorry, you need to Log In to post a reply to this thread.