Untested, but it should do something valuable.
function SetNLRZone( ply ) --Making a function for this because I said so.
if SERVER then
ply.deathpos = ply:GetPos()
timer.Destroy(ply:EntIndex() .. "NLRTimer") -- We don't want a billion timers floating around.
timer.Create(ply:EntIndex() .. "NLRTimer", 1, 300, function() -- 5 minutes is only 300 seconds. howdoimath.org
if not IsValid(ply) then return end -- Because dead players are invalid. This'll spam errors unless we only run if the player is alive... I think.
local playerpos = ply:GetPos()
local targetpos = ply.deathpos -- Not sure if continually defining this is efficient, but I do what I want.
if playerpos:Distance( targetpos ) < 800 && not ply.nlrimmune && ply:Alive() then -- nlrimmune is to make sure a player isn't continually spawn-killed for dying at a spawn point.
ply:ChatPrint("You got too close to your death zone, and have been slain! (Don't do it again or I'll cut you. (again.))")
hook.Add("PlayerDeath", "NLR.DeathZone", function( ply, inflictor, killer )
if not killer == ply then
if killer:IsPlayer() then -- Only run the function if the killer was a player. Otherwise, why would we care?
SetNLRZone( ply ) -- I've only ever ran functions like this with C#, so forgive me if this is incorrect.
timer.Destroy(ply:EntIndex() .. "nlrimmune") -- Simple timers cannot be stopped as far as I am aware. And we need to stop this
hook.Add("PlayerSpawn", "NLR.SpawnImmunity", function( ply )
if SERVER then
ply.nlrimmune = true
timer.Create(ply:EntIndex() .. "nlrimmune", 30, 1, function() -- Creating a timer here because we want to be able to end it.
ply.nlrimmune = false
[editline]2nd November 2013[/editline]
Why am I being rated dumb? I tested the code and it works exactly as intended?