So I have coded my safezone script..but I am trying to find a way when the player leaves the safezone..start a timer for 20 seconds giving them god mode...then after the 20 seconds remove god mode..
I am not so good with timers..and my code is below..some help would be much appreciated :smile:
[CODE]
------------------------------
-- sh_safezone Script --
------------------------------
local Ply = FindMetaTable("Player")
------------------
-- Check if the player is in the safezone.
function Ply:InSafezone()
if (self:GetPos() - Vector( 509, -11650, -639)):LengthSqr() < 1200000 then
return true
end
return false
end
-- Damage negation
if SERVER then
hook.Add( "PlayerShouldTakeDamage", "SafezoneDamage", function( vic, atk )
if !vic:IsPlayer() or !atk:IsPlayer() then return true end
if vic:InSafezone() or atk:InSafezone() then
return false
end
return true
end)
end
-- Safezone notice.
if CLIENT then
hook.Add( "HUDPaint", "Safezone", function()
local Ply = LocalPlayer()
if Ply:InSafezone() then
local text = "Safezone"
surface.SetFont("SZInfo")
local w,h = surface.GetTextSize( text )
w = w + 40
h = h + 20
draw.RoundedBox( 6, ScrW() / 2 - w/2, ScrH() / w + 10, w, h, Color( 0, 0, 0, 150 ) )
draw.SimpleText( text, "SZInfo", ScrW()/2, 20 + h/2, Color( 255, 255, 255, 200 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
end)
end[/CODE]
I dont think you are doing the function right, I may be wrong though.
[CODE]
function Ply:InSafezone() -- Change that to this function InSafezone(ply)
and then ply:InSafezone should work.
Also, would it not be easier to find the players in a sphere?
[/CODE]
It's probably best to just use an infinite timer with a delay of one second to check if the player has left the area and protect them if necessary. I only recommend one second for the sake of not putting too much strain on the server, but you can put it lower if you need/want. I've commented throughout my example to explain it.
[lua]timer.Create( "SafeArea", 1, 0, function()
for k, v in pairs( player.GetAll() ) do
-- if you don't know, doing table.item = 10 is basically setting the value to a key in the table
-- you can do the same to a player because it's a table object
if v:InSafezone() then v.was_in_safezone = true return end -- Mark that the player was in the safezone last run
if not v:InSafezone() and v.was_in_safezone then
v.safezone_protected = true -- Tell the server that the player is not to be harmed
v.was_in_safezone = false -- Remove the tag telling the server the player was in the safezone
end
timer.Simple( 20, function() -- delay this by 20 secs
if not v:IsValid() then return end -- Always good practice, the player could have quit by then, make sure they're still there
v.safezone_protected = false -- Remove the marker telling the server is not to be harmed
end )
end
end )
hook.Add( "PlayerShouldTakeDamage", "SafezoneProtect", function( vic, att )
return not( vic:InSafezone() or vic.safezone_protected or att:InSafezone or att.safezone_protected )
-- Basically return the opposite of whether the player is protected or not, using the variables and the distance check
end )[/lua]
[editline]4th April 2014[/editline]
@AIX-Who, it should be fine, he's using FindMetaTable.
is this influenced by Nether? lol
[QUOTE=Internet1001;44450844]It's probably best to just use an infinite timer with a delay of one second to check if the player has left the area and protect them if necessary. I only recommend one second for the sake of not putting too much strain on the server, but you can put it lower if you need/want. I've commented throughout my example to explain it.
[lua]timer.Create( "SafeArea", 1, 0, function()
for k, v in pairs( player.GetAll() ) do
-- if you don't know, doing table.item = 10 is basically setting the value to a key in the table
-- you can do the same to a player because it's a table object
if v:InSafezone() then v.was_in_safezone = true return end -- Mark that the player was in the safezone last run
if not v:InSafezone() and v.was_in_safezone then
v.safezone_protected = true -- Tell the server that the player is not to be harmed
v.was_in_safezone = false -- Remove the tag telling the server the player was in the safezone
end
timer.Simple( 20, function() -- delay this by 20 secs
if not v:IsValid() then return end -- Always good practice, the player could have quit by then, make sure they're still there
v.safezone_protected = false -- Remove the marker telling the server is not to be harmed
end )
end
end )
hook.Add( "PlayerShouldTakeDamage", "SafezoneProtect", function( vic, att )
return not( vic:InSafezone() or vic.safezone_protected or att:InSafezone or att.safezone_protected )
-- Basically return the opposite of whether the player is protected or not, using the variables and the distance check
end )[/lua]
[editline]4th April 2014[/editline]
[/QUOTE]
Thanks I will check this out and see if it works!
@Judd no no I dont even play Nether..Just had to make a way to avoid safezone camping and gibberish.
@Internet1001
The code doesnt actually give the player some sort of immunity..and it doesnt prevent them from being able to kill another player while they left the zone....how can this all be done?
Bump
Sorry, you need to Log In to post a reply to this thread.