Portal SAMP
[Ajuda] Pegar ID do jogador - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] Pegar ID do jogador (/showthread.php?tid=659)



Pegar ID do jogador - Sants - 16/01/2021

Olá,

Gostaria de saber como pega ID do jogador pelo nick?


RE: Pegar ID do jogador - guikommander2 - 16/01/2021

Código PHP:
stock GetPlayerID(nick[])
{
    new 
sNick[MAX_PLAYER_NAME];

    for(new 
pMAX_PLAYERS; ++p)
    {
        if(
IsPlayerConnected(p))
        {
            
GetPlayerName(psNicksizeof(sNick));
            
            if(!
strcmp(sNicknick))
            {
                return 
p;
            }
        }
    }
    
    return 
INVALID_PLAYER_ID;
}

public 
OnPlayerConnect(playerid)
{
    
// Exemplo de uso:
    
new id GetPlayerID("bolsonaro");

    if(
id != INVALID_PLAYER_ID)
    {
        
SendClientMessage(id, -1"Você claramente é o borsonaro!");
    }

    return 
1;