• Spawn protection?
    6 replies, posted
does anyone know a code to setup spawn protection. Here's mine but i can't get it to work in the init.lua file in the gamemode. [B] ply:GodEnable() timer.Simple( 5, function() ply:GodDisable() function GM:PlayerSpawn( ply ) ply:SetModel("models/player/group01/male_07.mdl") ply:GiveGamemodeWeapons() ply:GodEnable() timer.Simple( 5, function() ply:GodDisable() end thanks for your help if you can help :)
[lua]hook.Add( "PlayerSpawn", "SetSpawnTime", function( ply ) ply:SetNWInt( "Spawn", CurTime() ) end ) hook.Add( "PlayerShouldTakeDamage", "StopDamage", function( victim, attacker ) return ( math.floor( CurTime() - victim:GetNWFloat( "Spawn" ) ) < 4 ) or ( math.floor( CurTime() - killer:GetNWFloat( "Spawn" ) ) < 4 ) end )[/lua] This is what I use.
[QUOTE=Internet1001;43136987][lua]hook.Add( "PlayerSpawn", "SetSpawnTime", function( ply ) ply:SetNWInt( "Spawn", CurTime() ) end ) hook.Add( "PlayerShouldTakeDamage", "StopDamage", function( victim, attacker ) return ( math.floor( CurTime() - victim:GetNWFloat( "Spawn" ) ) < 4 ) or ( math.floor( CurTime() - killer:GetNWFloat( "Spawn" ) ) < 4 ) end )[/lua] This is what I use.[/QUOTE] this seems to give perma god
ply:SetNWFloat( "Spawn"... not ply:SetNWInt( "Spawn"... Sorry. Had to modify it a bit.
[QUOTE=Internet1001;43137295]ply:SetNWFloat( "Spawn"... not ply:SetNWInt( "Spawn"... Sorry. Had to modify it a bit.[/QUOTE] sorry to say but it still dosen't seem to wrok am i doing somethign wrong :S sorry if im anoying u
[QUOTE=Internet1001;43136987][lua]hook.Add( "PlayerSpawn", "SetSpawnTime", function( ply ) ply:SetNWInt( "Spawn", CurTime() ) end ) hook.Add( "PlayerShouldTakeDamage", "StopDamage", function( victim, attacker ) return ( math.floor( CurTime() - victim:GetNWFloat( "Spawn" ) ) < 4 ) or ( math.floor( CurTime() - killer:GetNWFloat( "Spawn" ) ) < 4 ) end )[/lua] This is what I use.[/QUOTE] Not sure why you're making your own godmode function when GMod already has one.. [lua] local GodMode = { Settings = { Length = 3 } } function GodMode:PlayerSpawn(ply) if !IsValid(ply) then return end ply:GodEnable() ply.GodEnabled = true timer.Simple(self.Settings.Length, function() if !IsValid(ply) then return end ply:GodDisable() ply.GodEnabled = false end) end hook.Add("PlayerSpawn", "GE.PlayerSpawn", function(...) GodMode:PlayerSpawn(...) end) [/lua]
[QUOTE=brandonj4;43137424]Not sure why you're making your own godmode function when GMod already has one.. [lua] local GodMode = { Settings = { Length = 3 } } function GodMode:PlayerSpawn(ply) if !IsValid(ply) then return end ply:GodEnable() ply.GodEnabled = true timer.Simple(self.Settings.Length, function() if !IsValid(ply) then return end ply:GodDisable() ply.GodEnabled = false end) end hook.Add("PlayerSpawn", "GE.PlayerSpawn", function(...) GodMode:PlayerSpawn(...) end) [/lua][/QUOTE] many thanks :)
Sorry, you need to Log In to post a reply to this thread.