Array loop
#1

Hi, i need help with looping arrays.
So when i have 50 Objects and i want to do like this:
pawn Code:
Object[0] = CreateObject...
...
...
Object[50] = CreateObject...
And Later i want
pawn Code:
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?
Reply
#2

Code:
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]);
     }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)