GetPlayer ID from Number
#1

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
}
Reply
#2

Код:
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?
Reply
#3

@_@ :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.
Reply
#4

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

Код:
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.
Reply
#6

I'll test this! ty


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

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.
Reply
#8

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

Thanks guys ! =D
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)