Cant get my for statement to work the right way!
#1

Can someone help me please i am working on a script that shows who is in your team.

When i test this script with the account Testuser it shows Team: ALPHA Member: (0)Testuser
When i start up a second account Testuser2 (id:1) and i do it on his side it shows: No one is in your team!
And when i test it on Testuser (id:0) again it shows again: ALPHA Member: (0)Testuser

Here is the code part i am working on

pawn Код:
CMD:myteam(playerid, params[])
{
    new team[32];
    if     (gTeam[playerid] == T_ALPHA) team = ("ALPHA");
    else if(gTeam[playerid] == T_BRAVO) team = ("BRAVO");
    else if(gTeam[playerid] == T_CHARLIE) team = ("CHARLIE");
    else if(gTeam[playerid] == T_DELTA) team = ("DELTA");
    new bool:First2 = false;
    new Count, string[128];
    new i;
    for(i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new team2[32];
            if     (gTeam[i] == T_ALPHA) team2 = ("ALPHA");
            else if(gTeam[i] == T_BRAVO) team2 = ("BRAVO");
            else if(gTeam[i] == T_CHARLIE) team2 = ("CHARLIE");
            else if(gTeam[i] == T_DELTA) team2 = ("DELTA");
            if(team[playerid] == team2[i])
            {
                Count++;
                new PlayerName2[MAX_PLAYER_NAME];
                GetPlayerName(i, PlayerName2, sizeof(PlayerName2));
                if(!First2)
                {
                    format(string, sizeof(string), "Team: %s Member: (%d)%s", team, i, PlayerName2[i]);
                    First2 = true;
                }
                else format(string,sizeof(string),"%s, (%d)%s", string, i, PlayerName2[i]);
            }
        }
        if(Count == 0)
        return SendClientMessage(playerid,C_WHITE,"No one is in your team!");
        else return SendClientMessage(playerid,C_WHITE,string);
    }
    return 1;
}
Reply
#2

Your entire command is way longer and more complicated than it has to be, let me redo it a bit:

pawn Код:
CMD:myteam(playerid, params[])
{
    new bool:First2 = false;
    new Count, string[80]; //I changed string to 80 cells, as you won't be needing more
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && gTeam[playerid] == gTeam[i])
        {
            Count++;
            new PlayerName2[MAX_PLAYER_NAME];
            GetPlayerName(i, PlayerName2, sizeof(PlayerName2));
            if(!First2)
            {
                new team[32];
                if     (gTeam[playerid] == T_ALPHA) team = ("ALPHA");
                else if(gTeam[playerid] == T_BRAVO) team = ("BRAVO");
                else if(gTeam[playerid] == T_CHARLIE) team = ("CHARLIE");
                else if(gTeam[playerid] == T_DELTA) team = ("DELTA");
                format(string, sizeof(string), "Team: %s Member: (%d)%s", team, i, PlayerName2);
                First2 = true;
            }
            else
                format(string,sizeof(string),"%s, (%d)%s", string, i, PlayerName2);
        }
    }
    if(Count == 0)
        return SendClientMessage(playerid,C_WHITE,"No one is in your team!");
    else
        return SendClientMessage(playerid,C_WHITE,string);
}
Try this.

EDIT: Sorry I forgot to include the team names, let me fix it fast.

EDIT2: Fixed now - it should work.
Reply
#3

thx for the help its working now i only changed 1 thing in your version.

pawn Код:
for(new ii = 0; i < MAX_PLAYERS; i++)
to
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Reply
#4

Quote:
Originally Posted by HireMe
Посмотреть сообщение
thx for the help its working now i only changed 1 thing in your version.

pawn Код:
for(new ii = 0; i < MAX_PLAYERS; i++)
to
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
No problem

Ah and yes, that was simply a typ0.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)