PDA

View Full Version : Problem with GetPlayerID


Gytis0
11/06/2012, 09:22 PM
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:

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:

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:

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

BaubaS
11/06/2012, 09:23 PM
manager = GetPlayerId("Allen_Blaxland");

Gytis0
11/06/2012, 09:32 PM
manager = GetPlayerId("Allen_Blaxland");

Aciu labai! +rep. :cool:

AndreT
11/06/2012, 09:36 PM
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.

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