SA-MP Forums Archive
Array loop - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Array loop (/showthread.php?tid=556760)



Array loop - finelaq - 11.01.2015

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?


Re: Array loop - Divergent - 11.01.2015

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