[HELP] How to make iterators
#1

Hello there,
well as the title says, although I'm not sure they are called iterators, but what I wanted to mean is something like playerid, vehicleid, houseid, factionid, exempleid...etc
like you set up a limit e.g #define MAX_ITEMS 100 and then new Variable[MAX_ITEMS], and here comes the part I'm stuck at, how can I define/initialize something like itemid (Variable[itemid])

I hope you get what I mean,
Reply
#2

Using Iter_Add function
Reply
#3

Iter_Add and Iter_Remove I assume?

PHP код:
new Iterator:gZero<100>, Iterator:gOne<100>;
public 
OnPlayerSpawn(playerid)
{
    if(
GetPlayerTeam(playerid) == 0)
    {
        if(!
Iter_Contains(gZero, playerid))
            
Iter_Add(gZero, playerid);
    }
    else if(
GetPlayerTeam(playerid) == 1)
    {
        if(!
Iter_Contains(gOne, playerid))
            
Iter_Add(gOne, playerid);
    }
    return 
1;
}
public 
OnPlayerDisconnect(playerid, reason)
{
    if(
GetPlayerTeam(playerid) == 0)
    {
        if(
Iter_Contains(gZero, playerid))
            
Iter_Remove(gZero, playerid);
    }
    else if(
GetPlayerTeam(playerid) == 1)
    {
        if(
Iter_Contains(gOne, playerid))
            
Iter_Remove(gOne, playerid);
    }
    return 
1;
}
// ZCMD
CMD:teams(playerid, params[])
{
    foreach(new 
i : gZero)
    {
        
// Loops through iterator gZero (Team #0)
    
}
    foreach(new 
i : gOne)
    {
        
// Loops through iterator gOne (Team #1)
    
}
    return 
1;
} 
Reply
#4

Is using an extra include necessary ?
Reply
#5

Yep, You need foreach (or the YSI version of it, y_iterate)
Reply
#6

OK, but is there a tutorial on this matter which you can recommend for me?
Reply


Forum Jump:


Users browsing this thread: