[HELP] How to make iterators - 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: [HELP] How to make iterators (
/showthread.php?tid=624072)
[HELP] How to make iterators -
Eoussama - 10.12.2016
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,
Re: [HELP] How to make iterators -
SyS - 10.12.2016
Using
Iter_Add function
Re: [HELP] How to make iterators -
JaKe Elite - 10.12.2016
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;
}
Re: [HELP] How to make iterators -
Eoussama - 10.12.2016
Is using an extra include necessary ?
Re: [HELP] How to make iterators -
JaKe Elite - 10.12.2016
Yep, You need foreach (or the YSI version of it, y_iterate)
Re: [HELP] How to make iterators -
Eoussama - 10.12.2016
OK, but is there a tutorial on this matter which you can recommend for me?