Problem with player.GetAll

I trying to make this script to work in a right way, but it doesn’t work. It’s probably work but not in a way that i want.
Yes, it spawn fire, but it romove fire anyway, not remove for firs joined player, why it so happening?

There my function to spawn fire

[LUA]
function Fire()

local pos = { Vector( -1730, -1349, -128 ), Vector( -1088, -2484, 80 ), Vector( -1711, 127, 227 ), Vector( 659, 1344, -131 ), Vector( -870, -1172, 4 ), Vector( -893, -1176, 132 ), Vector( -863, -1180, 260 ), Vector( -919, -1445, 132 ), Vector( -963, -1457, 4 ), Vector( -966, -2014, -131 ), Vector( -946, -2113, -3 ), Vector( -946, -2113, -3 ), Vector( -929, -1778, 124 ), Vector( -947, -1796, -3 ), Vector(  661, 314, -131 ), Vector( -486, 1834, -131 ), Vector( 1372, 283, -131 ), Vector(  1389, 284, -7 ), Vector( 1347, 2368, 36 ), Vector( 1690, 1703, -131 ), Vector( 1483, -1384, -127 ), Vector( -199, -1427, 48 ), Vector( -303, 2734, -137 ), Vector( -4255, 2708, -143 ), Vector( -4666, 4666, -139 ), Vector( -6142, 4565, -139 ), Vector(  -4851, 6717, -145 ), Vector( -3407, 6757, -117 ), Vector( -1709, 6768, -146 ) }

for k,v in pairs(player.GetAll()) do
	if ( v:Team() == TEAM_FIREMAN ) and ( game.GetMap( ) == "rp_downtown_v2g" ) then
		local fire = ents.Create( "ent_fire" );
		fire:SetPos( table.Random( pos ) );
		fire:Spawn( );
	end
end
print ("Fire Spawned") --Check

end
timer.Create( “FireTimer”, placefire, 0, Fire )
[/LUA]

There to remove fire if no firemans on the server

[LUA]
for k, v in pairs(player.GetAll()) do
if not ( v:Team() == TEAM_FIREMAN ) then
self:KillFire()
end
end
[/LUA]

How to make this work? Or help to fix

[lua]function MakeFire()

local pos = { Vector( -1730, -1349, -128 ), Vector( -1088, -2484, 80 ), Vector( -1711, 127, 227 ), Vector( 659, 1344, -131 ), Vector( -870, -1172, 4 ), Vector( -893, -1176, 132 ), Vector( -863, -1180, 260 ), Vector( -919, -1445, 132 ), Vector( -963, -1457, 4 ), Vector( -966, -2014, -131 ), Vector( -946, -2113, -3 ), Vector( -946, -2113, -3 ), Vector( -929, -1778, 124 ), Vector( -947, -1796, -3 ), Vector(  661, 314, -131 ), Vector( -486, 1834, -131 ), Vector( 1372, 283, -131 ), Vector(  1389, 284, -7 ), Vector( 1347, 2368, 36 ), Vector( 1690, 1703, -131 ), Vector( 1483, -1384, -127 ), Vector( -199, -1427, 48 ), Vector( -303, 2734, -137 ), Vector( -4255, 2708, -143 ), Vector( -4666, 4666, -139 ), Vector( -6142, 4565, -139 ), Vector(  -4851, 6717, -145 ), Vector( -3407, 6757, -117 ), Vector( -1709, 6768, -146 ) }
 
for k,v in pairs(player.GetAll()) do
    if ( v:Team() == TEAM_FIREMAN ) and ( game.GetMap( ) == "rp_downtown_v2g" ) and (team.GetPlayers(TEAM_FIREMAN) > 0) then
        local fire = ents.Create( "ent_fire" );
        fire:SetPos( table.Random( pos ) );
        fire:Spawn( );
		elseif team.GetPlayers(TEAM_FIREMAN) <= 0 then
		if IsValid(fire) then
			SafeRemoveEntity(fire)
		end
    end
end
print ("Fire Spawned") --Check

end
timer.Create( “FireTimer”, placefire, 0, MakeFire ) //placefire should be a number
[/lua]

If you want multiple fires do [lua]fire* = ents.Create(“ent_fire”)
[/lua]

Same to remove

[ERROR] Attempt compare table with number

[LUA]
elseif team.GetPlayers(TEAM_FIREMAN) <= 0 then
[/LUA]

[LUA]
elseif #team.GetPlayers(TEAM_FIREMAN) <= 0 then
[/LUA]

Fire spawn but doesn’t remove on player change job, i use this scrip on the server side

Try
[lua]elseif ( v:Team() ~= TEAM_FIREMAN ) and ( #team.GetPlayers(TEAM_FIREMAN) <= 0 ) then
print(“Is being called”)
[/lua]
Tell us if it gets called when you changed team

Works, or this is not right way to solve?

[LUA]
elseif #team.GetPlayers(TEAM_FIREMAN) <= 0 then
for _, ent in pairs(ents.FindByClass(“ent_fire”)) do
if IsValid(ent) then
ent:Remove()
end
end
[/LUA]

Yeah you can do it that way too but you’re looping in a loop.

How is that a problem? The whole game is nothing but a series of loops within loops.

When more players join you’ll see the problem.

You don’t seem to have any idea of what are you talking of.

There might be a problem if this was called in a Think function, but this is only called every so often

[editline]22nd November 2012[/editline]

I think he’s referring to efficiency, which is valid. He’s not correct in thinking it will cause major problems, though

A loop within a loop is inefficient, as in Big O notation it is O(n^2) http://en.wikipedia.org/wiki/Big_O_notation

But this is really insignificant, running this loop within a loop seems a perfectly logical way of doing things

[editline]22nd November 2012[/editline]

Actually, on the second iteration the count returned by ents.findbyclass will be 0 anyway, since we’re removing all of them in the first iteration…so it’s not an issue at all really

1st grader? :v:

Ninja, rather than rating everyone dumb and trying to insult them, why don’t you explain in what way you feel this would be detrimental to performance?
I have explained above that you were partially right, but not in this situation…

NinjaS rates everyone dumb because he thinks he knows what he is talking about, when he really doesn’t. The whole loop-within-a-loop thing is a really dumb argument, when it comes down to it the amount of time it takes to iterate is so little it’s not even worth getting into efficiency arguments until you’re doing large calculations or preforming large operation inside each iteration. At some point trying to optimize is pointless, this case is a prime example.

Clearly you’re dumb, since you’re so butthurt I’ll continue to rate you dumb.

I don’t rate everyone dumb?


(User was banned for this post ("Flaming" - Autumn))