PDA

View Full Version : Array loop


finelaq
11/01/2015, 03:40 PM
Hi, i need help with looping arrays.
So when i have 50 Objects and i want to do like this:

Object[0] = CreateObject...
...
...
Object[50] = CreateObject...


And Later i want

if(IsPlayerInRangeOfPoint(i, 1, ObjectX[0], ObjectY[0], ObjectZ[0]))
{
DestroyObject(Object[0]);
}
else if(IsPlayerInRangeOfPoint(i, 1, ObjectX[1], ObjectY[1], ObjectZ[1]))
{
DestroyObject(Object[1]);
}
..
..
..
else if(IsPlayerInRangeOfPoint(i, 1, ObjectX[50], ObjectY[50], ObjectZ[50]))
{
DestroyObject(Object[50]);
}


So it's very boring and can i use loop to do this?

Divergent
11/01/2015, 04:10 PM
for(new i = 0; i < sizeof(Object); i++) // 'Object' is your array
{
new Float:X, Float:Y, Float:Z;
GetObjectPos(Object[i], X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 1, X, Y, Z);
{
DestroyObject(Object[i]);
}
}