Spawn protection?

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.

** 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 :slight_smile:

[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.

this seems to give perma god

ply:SetNWFloat( “Spawn”… not ply:SetNWInt( “Spawn”…
Sorry. Had to modify it a bit.

sorry to say but it still dosen’t seem to wrok am i doing somethign wrong :S sorry if im anoying u

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]

many thanks :slight_smile: