Quote:
Originally Posted by Flynn
You could run at the very least a standard debugging approach by printing out the two vectors and the given distance to figure out why.
Your uh, entity code is what I'd call 'highly bastardised' (incredibly confusing - the more so, the more likely there are to be bugs in it).
Just to pick out some peices...
Code:
new ent = -1;
while ((ent = FindEntityByClassname2(ent, "weapon_first_aid_kit_spawn")) != -1)
Code:
stock FindEntityByClassname2(startEnt, const String:classname[])
{
/* If startEnt isn't valid shifting it back to the nearest valid one */
while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
return FindEntityByClassname(startEnt, classname);
}
Bastardised parts highlighted. You're starting from -1, with a loop that breaks out on -1 (with a deincrementation operation), and returns ??? because FindEntity is given -1;
A better question is why is your code even able to remove medkits?
Edit: I presume FindEntity starts from -1, counts up, returns the first entity, the loop deincrements it back down, and because FindEntity only returns -1 when it -cannot find any more medkits- it gets trapped in an infinite loop until every single one is removed (which, when the player arrives at the finale spot, gets removed because the operation is still continuously operating - because there are still kits out there).
In short; Assumption and Presumption fail.
|
That code is fine. 'ent' is initted to -1 because the FindEntityByClassname looks for entities PAST the index given. If you want to start at 0, the index needs to be -1. The new entity found is then past into the 'ent' variable making it no longer equal to -1, and hence making the boolean expression true. Then after the loop, that new ent is then passed into the FindEntity function, and it starts again. The FindEntity function will return -1 when no entity is found, exitting the loop.
If no entity is found, the ent value will then be equal to -1, which is why his next code checks for the ent value to be greater than -1 so that it wont operate on a none existant entity.
I use this loop allot, and it works fine for me. I dont play L4D, so I cant help you with your actual problem xD