16.08.2013, 09:37
Hello,
I want to make this loop -
But in foreach way.
So how do I do it ?
Thanks alot!
I want to make this loop -
Код:
for(new i;i<90;i++)
So how do I do it ?
Thanks alot!
for(new i;i<90;i++)
foreach (new i : 90)
new Iterator:_Admins<MAX_PLAYERS>;
Iter_Add(_Admins, playerid);
Iter_Remove(_Admins, playerid );
foreach(_Admins, i)
You have to create the Iterator then add and remove values from it, then you can use foreach.
Like this: pawn Код:
|
for(new i;i<90;i++)
#include <a_samp>
#include <zcmd>
#include <YSI\y_iterate>
// Initialize a new iterator
new Iterator:TestIter<90>;
// Add some random iterations
public OnFilterScriptInit()
{
Iter_Add(TestIter, 2);
Iter_Add(TestIter, 5);
Iter_Add(TestIter, 10);
Iter_Add(TestIter, 53);
Iter_Add(TestIter, 63);
return 1;
}
// Add a new iteration
CMD:additer(playerid, arg[])
{
// Find the next free iteration
new index = Iter_Free(TestIter);
// Make sure there is a free slot
if(index > -1)
{
new line[128];
format(line, sizeof(line), "Iterator Added Index: %i", index);
SendClientMessage(playerid, -1, line);
// Add the new iterator
Iter_Add(TestIter, index);
}
// Iterator has no free indexes
else SendClientMessage(playerid, -1, "Iterator is full!");
return 1;
}
// Remove a specific iteration
CMD:removeiter(playerid, arg[])
{
// Get the input value
new index = strval(arg);
// Does this index actually exist in the iterator?
if(Iter_Contains(TestIter, index))
{
new line[128];
format(line, sizeof(line), "Iterator Removed Index: %i", index);
SendClientMessage(playerid, -1, line);
// Remove the iterator
Iter_Remove(TestIter, index);
}
// Index did not exist
else SendClientMessage(playerid, -1, "Iterator does not exist!");
return 1;
}
// Show all iterations
CMD:showiter(playerid, arg[])
{
// Loop through the test iterator and show values this should message the player with by defaul
// Iterator found at index: 2
// Iterator found at index: 5
// Iterator found at index: 10
// Iterator found at index: 53
// Iterator found at index: 63
foreach(new i : TestIter)
{
new line[128];
format(line, sizeof(line), "Iterator found at index: %i", i);
SendClientMessage(playerid, -1, line);
}
return 1;
}