Problem with GetPlayerID
#1

I need to get specific player's ID from their name. Now I don't know what seems to be the problem, but I still get an error.

So here's the function:
pawn Код:
stock GetPlayerId(Name[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
        new pName2[MAX_PLAYER_NAME];
        GetPlayerName(i, pName2, sizeof(pName2));
            if(!strcmp(Name, pName2))
            {
                return i;
            }
        }
    }
    return -1;
}
Here is where I'm trying to use it:
pawn Код:
new manager;
manager = GetPlayerId(Allen_Blaxland[]);
GivePlayerCash(manager, 25);
GivePlayerCash(playerid, -25);
SendClientMessage(playerid, COLOR_WHITE, "{CC3333}NOTICE: {ffffff}You have paid $25 for using the bank.");
Here is the error:
pawn Код:
error 017: undefined symbol "Allen_Blaxland"
I'm basically trying to make it so, that when someone uses the bank, the owner gets 25 dollars from the user's 'pocket'.
Reply
#2

pawn Код:
manager = GetPlayerId("Allen_Blaxland");
Reply
#3

Quote:
Originally Posted by BaubaS
Посмотреть сообщение
pawn Код:
manager = GetPlayerId("Allen_Blaxland");
Aciu labai! +rep.
Reply
#4

I have a suggestion to make about this loop of yours.
1. You should create the string outside of the loop.
2. You don't need the IsPlayerConnected check assuming that GetPlayerName returns 0 in case of an unconnected player.

pawn Код:
new pName[MAX_PLAYER_NAME+1];
for(i = 0; i != MAX_PLAYERS; i++)
{
    if(!GetPlayerName(i, pName, sizeof(pName))
    {
        if(!strcmp(Name, pName))
        {
            return i;
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)