SA-MP Forums Archive
How to loop through all gangs? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to loop through all gangs? (/showthread.php?tid=175317)



How to loop through all gangs? - mrcoolballs - 09.09.2010

Im trying to create my own gang system for my server, which Is going pretty well, just im trying to create a /gangs command which displays all the current gangs, this is what i have:

pawn Код:
stock GetGangs(playerid)
{
    new str[78];
    SendClientMessage(playerid, ORANGE, "Gangs:");
    for (new i = -1; i < GangID; i++)
    {
        if(GangInfo[i][Name]) continue;
        format(str,sizeof(str),"Name: %s(ID:%d) Leader: %s",GangInfo[i][Name],GangID,GangInfo[i][Leader]);
    }
    SendClientMessage(playerid, ORANGE, str);
}
the GangID is the count that i use for the gangs, like when someone types /creategang it goes up by 1 and it starts at 0.
anyone know how i would get this to display all the gangs?


Re: How to loop through all gangs? - cessil - 09.09.2010

if GangID starts at 0 why doesn't i? also all of the gangs will return the last GangID as their ID in that script.

what happens when you execute that command?


Re: How to loop through all gangs? - mrcoolballs - 09.09.2010

GangID starts at -1 so when the first gang is created it gets plus 1 so the first gang will be ID 0, when i use that code it displays
Gangs:
SERVER: Unknown Command


Re: How to loop through all gangs? - cessil - 09.09.2010

well that code starts from -1 - x make i = 0. I think its having a problem reading GangInfo[-1][Name] so that should fix it


Re: How to loop through all gangs? - [HiC]TheKiller - 09.09.2010

SendClientMessage should be in the loop.

Also
pawn Код:
if(GangInfo[i][Name]) continue;
should be
pawn Код:
if(!strlen(GangInfo[i][Name])) continue;
~[HiC]TheKiller


Re: How to loop through all gangs? - Relixious - 09.09.2010

You can never have a variable of -1, it all starts with 0!


Re: How to loop through all gangs? - mrcoolballs - 09.09.2010

I changed it around a little bit and its almost working, now when if i type /creategang cool gang and then i type /creategang cool gang2 it will only display the first one, then if i type /creategang cool gang3 it will display cool gang 1 and 2 without the third, this is what it looks like now

pawn Код:
stock GetGangs(playerid)
{
    new str[78];
    SendClientMessage(playerid, ORANGE, "Gangs:");
    for (new i; i < GangID; i++)
    {
        if(i == GangID) continue;
        format(str,sizeof(str),"Name: %s(ID:%d) Leader: %s",GangInfo[i][Name],i,GangInfo[i][Leader]);
        SendClientMessage(playerid, ORANGE, str);
     }
   
}
i have already tried change it so i = 0 and i = -1


Re: How to loop through all gangs? - [HiC]TheKiller - 09.09.2010

Take out that
pawn Код:
if(i == GangID) continue;



Re: How to loop through all gangs? - mrcoolballs - 09.09.2010

do i replace it with anything?

EDIT: just tested it out and it does the same thing


Re: How to loop through all gangs? - [HiC]TheKiller - 09.09.2010

It should work fine just like that or you can add

pawn Код:
if(!strlen(GangInfo[i][Name])) continue;