[Green Horn Question] Igniting

Howdy everyone, I am creating an entity that will cause a player to ignite once they are in a certain range. What I can’t seem to grasp is how to implement the range and duration pairs. In the base script: [lua]function ignite()
for k, v in pairs( ents.FindByClass( “prop_physics” ) ) do
v:Ignite( 30 )
end
end[/lua]
I see the radius variable is below, but I’m not seeing where I would inplement the burn time. The method I tried was to make k a local variable and throw it at the top of the script, but I’m not getting any ignition upon testing.
I’d appreciate any feedback and thanks.

use the DistToSqr/Distance functions to check for distance.
I’m not sure what you mean by burn time, you can specify how long you want someone to stay ignited for in the Player.Ignite(time) function.

Also, unless you’re calling your function in other files, there’s no need for it to be global.

Thanks for the quick reply! I’m playing with it now

[editline]19th July 2015[/editline]

Hmm, I’m using this code right here but it’s not working:
[lua]function ignite()
local tooclose = 250;
local currentposition = ply:GetPos():DistToSqr(LocalPlayer():GetPos());
if (currentposition < tooclose) then
function ignite(ply)
for k, v in pairs( ents.FindByClass( “prop_physics” ) ) do
v:Ignite( 30 )
end
end
end
end[/lua]

DistToSqr will produce numbers much larger - it is a performance thing to reduce a call to sqrt.

Your tooclose value should be 250 ^ 2 ( 62500 ).

But what you want is probably this:



for k, v in pairs( ents.GetAll( ) ) do
  if v:GetPos( ):DistToSqr( some_point ) <= some_value then
    if not v:IsOnFire( ) then
      v:Ignite( some_value )
    end
  end
end

Not all states have an existing function to check for it ( like being poisoned ), but in this case we can check if the entity is on fire so we don’t just spam calls to Ignite when it isn’t needed.