SA-MP Forums Archive
Problem with GetPlayerID - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with GetPlayerID (/showthread.php?tid=350242)



Problem with GetPlayerID - Gytis0 - 11.06.2012

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'.


Re: Problem with GetPlayerID - BaubaS - 11.06.2012

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



Re: Problem with GetPlayerID - Gytis0 - 11.06.2012

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


Re: Problem with GetPlayerID - AndreT - 11.06.2012

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;
        }
    }
}