What's wrong with this loop?
#1

I haven't made that many loops before, and the loops I've made has been pretty simple.

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(strfind(result, NameTagInfo[playerid][nFirstName], true) != -1 || strfind(result, NameTagInfo[playerid][nLastName], true) != -1)
        {
            while(GetDistanceBetweenPlayers(playerid, i) < 10)
            {
                if(NameTagInfo[i][nFriend1] == 0)
                {
                    NameTagInfo[i][nFriend1] = PlayerInfo[playerid][pSQLID];
                    SaveFriends(i);
                }
                else if(NameTagInfo[i][nFriend2] == 0)
                {
                    SendClientMessage(i, COLOR_YELLOW, "It didn't work");
                    SendClientMessage(playerid, COLOR_YELLOW, "It didn't work");
                }
            }
            SendClientMessage(playerid, COLOR_YELLOW, "It worked!");
            return 1;
        }
    }
    return true;
I does work, but it also affects the players that types the command, and I want it to only affect the players around the player who types in the command.

It's just something I made for fun I guess, a piece where a player have to type in their name, and then the other players in range, can see his name.
Reply
#2

Quote:
Originally Posted by Knappen
View Post
I haven't made that many loops before, and the loops I've made has been pretty simple.

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(strfind(result, NameTagInfo[playerid][nFirstName], true) != -1 || strfind(result, NameTagInfo[playerid][nLastName], true) != -1)
        {
            while(GetDistanceBetweenPlayers(playerid, i) < 10)
            {
                if(NameTagInfo[i][nFriend1] == 0)
                {
                    NameTagInfo[i][nFriend1] = PlayerInfo[playerid][pSQLID];
                    SaveFriends(i);
                }
                else if(NameTagInfo[i][nFriend2] == 0)
                {
                    SendClientMessage(i, COLOR_YELLOW, "It didn't work");
                    SendClientMessage(playerid, COLOR_YELLOW, "It didn't work");
                }
            }
            SendClientMessage(playerid, COLOR_YELLOW, "It worked!");
            return 1;
        }
    }
    return true;
I does work, but it also affects the players that types the command, and I want it to only affect the players around the player who types in the command.

It's just something I made for fun I guess, a piece where a player have to type in their name, and then the other players in range, can see his name.
Add another check like

pawn Code:
if(i != playerid) {
//rest of your code
}
This will skip the player that typed the command.
Reply
#3

It worked! Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)