Problem with a loop
#2

pawn Код:
CMD:gcreate(playerid,params[])
{
    if(playerGang[playerid]>0)
        return SendClientMessage(playerid, -1, ""COL_RED"ERROR:{FFFFFF} You are already in a gang.");
    if(!strlen(params[0]))
        return SendClientMessage(playerid, -1, ""COL_LIGHTBLUE"Usage:{FFFFFF} /gcreate <gangname> (Max 16 char)");
    new string[128];
    for(new i = 1; i < MAX_GANGS; i++)
    {
        if(gangInfo[i][0]==0)
        {
            //name gang
            format(gangNames[i], MAX_GANG_NAME, "%s", params[0]);
            //Gang exists
            gangInfo[i][0]=1;
            //There is one member
            gangInfo[i][1]=1;
            //Gang color is player's color
            gangInfo[i][2]=PlayerColors[playerid];
            //Player is the first gang member
            gangMembers[i][0] = playerid;
            format(string, sizeof(string),"You have created the gang '%s' (id: %d)", gangNames[i], i);
            SendClientMessage(playerid, COLOR_GREEN, string);
            playerGang[playerid]=i;
            return 1;
        }
    }
    return 1;
}
We return a value in the loop when an un-occupied gang slot is found, so that the loop does not continue running trying to find an empty slot (Can also use break). I do believe that is what you're looking for. Additionally as you can see I removed the use of sscanf, as there's no need to unformat a string that doesn't need to be unformatted, all you want to know is if the player entered a value for it or not. Either way you should also check the length of the entered parameter, to make sure the player didn't go over your 16 character limit.
Reply


Messages In This Thread
Problem with a loop - by OldDirtyBastard - 28.02.2011, 11:52
Re: Problem with a loop - by JaTochNietDan - 28.02.2011, 11:55
Re: Problem with a loop - by OldDirtyBastard - 28.02.2011, 11:58
Re: Problem with a loop - by JaTochNietDan - 28.02.2011, 12:00
Re: Problem with a loop - by OldDirtyBastard - 28.02.2011, 12:18
Re: Problem with a loop - by OldDirtyBastard - 28.02.2011, 12:27

Forum Jump:


Users browsing this thread: 1 Guest(s)