How to loop through all gangs?
#1

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?
Reply
#2

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?
Reply
#3

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
Reply
#4

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
Reply
#5

SendClientMessage should be in the loop.

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

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

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
Reply
#8

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

do i replace it with anything?

EDIT: just tested it out and it does the same thing
Reply
#10

It should work fine just like that or you can add

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


Forum Jump:


Users browsing this thread: 2 Guest(s)