[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(gZeroplayerid))
            
Iter_Add(gZeroplayerid);
    }
    else if(
GetPlayerTeam(playerid) == 1)
    {
        if(!
Iter_Contains(gOneplayerid))
            
Iter_Add(gOneplayerid);
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    if(
GetPlayerTeam(playerid) == 0)
    {
        if(
Iter_Contains(gZeroplayerid))
            
Iter_Remove(gZeroplayerid);
    }
    else if(
GetPlayerTeam(playerid) == 1)
    {
        if(
Iter_Contains(gOneplayerid))
            
Iter_Remove(gOneplayerid);
    }
    return 
1;
}
// ZCMD
CMD:teams(playeridparams[])
{
    foreach(new 
gZero)
    {
        
// Loops through iterator gZero (Team #0)
    
}
    foreach(new 
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: 1 Guest(s)