SA-MP Forums Archive
GetPlayer ID from Number - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetPlayer ID from Number (/showthread.php?tid=237456)



GetPlayer ID from Number - Ricop522 - 09.03.2011

I trying to get the ID of player by the number, but this don't work.

pawn Код:
stock GetPlayerNumber(numero)
{
    for(new i = 0; i <= MAX_PLAYERS; ++i)
    {
        if(PlayerInfo[i][numero])
        {
            new tnome[MAX_PLAYER_NAME];
            GetPlayerName(i, tnome, sizeof(tnome) );
            if(strcmp(tnome, i, true, strlen(i)) == 0)
            {
                return i;
            }
        }
    }
    return INVALID_PLAYER_ID;    //ID Invбlido
}



Re: GetPlayer ID from Number - DJDhan - 09.03.2011

Код:
for(new i = 0; i <= MAX_PLAYERS; ++i)
You are scanning player ids...

Код:
if(PlayerInfo[i][numero])
Don't know what you are trying to do here...

Код:
new tnome[MAX_PLAYER_NAME];            
GetPlayerName(i, tnome, sizeof(tnome) );
Now you have the name of the player in the string tnome...

Код:
if(strcmp(tnome, i, true, strlen(i)) == 0)
Here, you are comparing his name to his playerid, which will always return false.
strcmp only needs the name of two strings as arguments to compare.

Can you explain a little more on exactly what "number" means in this code?


Re: GetPlayer ID from Number - Ricop522 - 09.03.2011

@_@ :S

I'm trying to get the ID of player by the Cellnumber ..

GetPlayerNumber( number )


using:

Number = what he put on dialog to call to another player.

I wanna get the ID of this player. '-'



thanks for the help.


Respuesta: GetPlayer ID from Number - Code8976Man - 09.03.2011

pawn Код:
if(PlayerInfo[i][pPnumber] == numero)



Re: GetPlayer ID from Number - DJDhan - 09.03.2011

Код:
stock GetPlayerNumber(numero)
{    
     for(new i = 0; i <= GetMaxPlayers(); i++)    
     {        
              if(PlayerInfo[i][CellNumber] == numero) return i;   // Playerinfo[i][Cellnumber]  is where you store the cell number of each player
     }    
     return INVALID_PLAYER_ID;
}
Code8976man is right. Try the above code.

Also, it's more efficient to use GetMaxPlayers instead of looping 500 times when the maximum your server allows is, say 100.


Re: GetPlayer ID from Number - Ricop522 - 09.03.2011

I'll test this! ty


((
I put this on the top
#undef MAX_PLAYERS
#define MAX_PLAYERS 65
Its good ??))


Re: GetPlayer ID from Number - Cameltoe - 09.03.2011

Quote:
Originally Posted by Ricop522
Посмотреть сообщение
I'll test this! ty


((
I put this on the top
#undef MAX_PLAYERS
#define MAX_PLAYERS 65
Its good ??))
Yes, then it wouldn't need to loop through 500 players.


Re: GetPlayer ID from Number - Marricio - 09.03.2011

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
Yes, then it wouldn't need to loop through 500 players.
OR use foreach.


Re: GetPlayer ID from Number - Ricop522 - 09.03.2011

Thanks guys ! =D