• Disable respawn
    6 replies, posted
Hey How do i disable respawn, like for 10 seconds.
pl.NextSpawnTime = CurTime() + 10
Okay, not what i expected, but what i asked about. So i gonna make it more clearly. How do i disable respawn until a boolean is true?
Look at the [url=https://github.com/garrynewman/garrysmod/blob/4a966f6b07d4d8bc2e8c7d18d158880cda2b2a2b/garrysmod/gamemodes/base/gamemode/player.lua#L109]PlayerDeathThink hook[/URL] in the base gamemode, where respawning is actually implemented. You can easily hook or override that, eg. [Lua] function GM:PlayerDeathThink(ply) if not ply.SomeCond then return end self.BaseClass:PlayerDeathThink(ply) end [/lua]
Exactly as Luni says; I'd recommend setting up a few helper functions ( you could also simply hook into PlayerDeathThink but if you're writing a game-mode, it would be better to recode the hooks ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/spectating_players_system.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/playerselectspawn_system.lua.html[/url] remove .html to view .lua
Luni's code doesn't work; you ideally ought to return a boolean value. You also don't need to call the hook from within it's base class again; that's unnecessary. Also, I recommend you use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url] instead of directly overwriting the hook. Use this code instead; [lua] some_boolean_value = true hook.Add( "PlayerDeathThink", "prevent_spawn", function( ply ) return some_boolean_value end ) [/lua]
[QUOTE=Maurdekye;47611258]Luni's code doesn't work; you ideally ought to return a boolean value. You also don't need to call the hook from within it's base class again; that's unnecessary. Also, I recommend you use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url] instead of directly overwriting the hook. Use this code instead; [lua] some_boolean_value = true hook.Add( "PlayerDeathThink", "prevent_spawn", function( ply ) return some_boolean_value end ) [/lua][/QUOTE] I wouldn't recommend this at all... When creating hooks, you alter specific behavior but with this hook you're essentially overwriting all other hooks and the GM function because you return non-nil... If the op is writing a game-mode and only wants people to respawn at round-start, then something like this would work but I'd still recommend using GM: instead of hook so that the behavior can be altered by addons...
Sorry, you need to Log In to post a reply to this thread.