So I have no idea on how respawn players in gmod with a timer. I want to make a 5 second Respawn Timer for players and disable Left click to respawn.
You want to use the hook GM/PlayerDeathThink then
local allowed = false -- set allowed to spawn false
// check if player can spawn or not
hook.Add("PlayerDeathThink","RespawnTimer",function(ply)
if allowed == false then -- check if allowed = false
timer.Create("timername",5,0,function() return true end) -- create timer for make the function
else
return allowed -- return false to spawn
end
end)
this is the basic code if you want to add left click button or something else use with Garry's Mod wiki
you must edit this code cause it setup to all players in the server and not to single client
Garry's Mod Wiki - Click here
That won't work at all.
hook.Add("PlayerDeathThink", "RespawnTimer", function(ply)
if (ply.NextRespawn <= CurTime()) then
return false
end
end)
you may override other addons if you always return a value
yes and then anybody will be able to respawn by pressing attack or jump with your code. Read the comments in my code please.
but we check if (ply.NextRespawn <= CurTime()) returns false then we return false?
if it returns true it may override other addons lmao
That's the point. Why would you want more than one method of respawning?
you don't need to return true so he can respawn :s
You still have to call Player:Spawn if you don't return true.
just test it, oof also fixed code
I'm not going to test something I know won't work. How do you think hooks in gmod work? If there's no return value from hooks added by hook.Add then it'll call the GM hook. If you don't return true here it's just going to stop the player spawning for an extra x amount of time until they can spawn using the GM's PlayerDeathThink hook which in most cases will be the one from '/gamemodes/base/'. If you read the OP you'll see that the OP doesn't want to use the default hook so in my code I stop it running and automatically spawn the player after x amount of seconds.
oof you are right, forgot that he wants to disable Left click to respawn lmao
For some reason this makes no one respawn after 5 seconds and makes them stay dead??
i find the best way is to override the default function for PlayerDeathThink
local delay = 5
hook.Add("PlayerDeath", "RespawnTimer", function(ply)
ply.NextRespawn = CurTime() + delay
end)
hook.Add("PlayerSilentDeath", "RespawnTimer", function(ply)
ply.NextRespawn = CurTime() + delay
end)
hook.Add("OnGamemodeLoaded", "PlayerDeathThink", function()
function GAMEMODE:PlayerDeathThink(ply)
local nextRespawn = ply.NextRespawn
if (nextRespawn && nextRespawn >= CurTime()) then return end
ply:Spawn()
end
end)
Returning a value (true or false) constantly on the hook itself would also override the gamemode hook tho-
Unless you want to allow other hooks to run as well
Aye this code worked thanks guys.
lmao i know that, sneaky confused me and made me think this hook will respawn players automatically if returned true
That's what I assumed from the wiki page.
GM/PlayerDeathThink
"The return value will determine if the player respawns."
I believe you could probably find the death think hook nutscript uses and that should work fine, I think I edited that while ago to allow you to also click or press space to resplendent quicker and auto respawn you 30 seconds after death but I don't know if I have that anymore. It’s fairly easy, just stitched the sandbox and nutscript playerdeaththink hooks together with a few edits in some places
Sorry, you need to Log In to post a reply to this thread.