I would like to have a delay for the following code, I have looked on other facepunch posts but their examples dont seem to be working.
[CODE]util.AddNetworkString( "PosionCLP1" )
function ENT:Touch( ply )
// i want it to have a 7 second delay before doing the following
net.Start("PosionCLP1")
net.Send(ply)
local health = ply:Health()
timer.Simple(5,function()
ply:SetHealth(health - 20)
end)
timer.Simple(10,function()
ply:SetHealth(health - 20)
end)
timer.Simple(15,function()
ply:SetHealth(health - 20)
end)
timer.Simple(20,function()
ply:SetHealth(health - 40)
end)
end[/CODE]
anyway to do that?
Do you want to delay the whole code?
Or delay the next touch on the player?
Or delay the next touch on everything it touches?
delay the whole code
[editline]23rd March 2016[/editline]
for example; you have to hold the entity on the player for 7 seconds before it performs the rest of the code
bump
So Touch() is ran every frame the player is within range, meaning those timers are gonna be called repeatedly
Use this instead:
[url]https://wiki.garrysmod.com/page/ENTITY/StartTouch[/url]
Ok I have the following code
[CODE]util.AddNetworkString( "PosionCLP1" )
function ENT:StartTouch( ply )
timer.Simple(5, function()
self:Remove()
net.Start("PosionCLP1")
net.Send(ply)
local health = ply:Health()
timer.Simple(5,function()
ply:SetHealth(health - 100)
if ply:Health() <= 0 then
ply:Kill()
ply:EmitSound( Sound( "vo/npc/Barney/ba_pain03.wav" ), ply:GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
end
end)
end)[/CODE]
how do I make ENT:EndTouch stop all those timers
[QUOTE=FelixCrimson;49988815]Ok I have the following code
how do I make ENT:EndTouch stop all those timers[/QUOTE]
You're going to need the functions timer.Create and timer.Remove. Timers created with timer.Simple cannot be stopped.
[QUOTE=Maravis;49988836]You're going to need the functions timer.Create and timer.Remove. Timers created with timer.Simple cannot be stopped.[/QUOTE]
Could use timer.Create but could also apply a variable to a player on EndTouch and check aganist it at the start of each timer.
Sorry, you need to Log In to post a reply to this thread.