any way to get players id form the part of name
#10

Probably this will help:

pawn Код:
CMD:getid(playerid, params[])
{
    new string[128], name[25];
    if(sscanf(params, "s[25]", name))
    {
        format(string, sizeof (string), "[USAGE]: /getid (name).");
        SendClientMessage(playerid, 0xFF0000FF, string);
        return 1;
    }
    if(!IsPlayerConnected(GetPlayerIDFromName(name)))
    {
        format(string, sizeof (string), "[ERROR]: The player entered is unknown.");
        SendClientMessage(playerid, 0xFF0000FF, string);
        return 1;
    }
    format(string, sizeof (string), "%s's player id is %d.", PlayerName(GetPlayerIDFromName(name)), GetPlayerIDFromName(name));
    SendClientMessage(playerid, 0xFFFFFFFF, string);
    return 1;
}

stock GetPlayerIDFromName(playername[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new playername2[MAX_PLAYER_NAME];
            GetPlayerName(i, playername2, sizeof(playername2));
            if(strcmp(playername2, playername, true, strlen(playername)) == 0)
            {
                return i;
            }
        }
    }
    return INVALID_PLAYER_ID;
}

stock PlayerName(playerid)
{
    new pname[25];
    GetPlayerName(playerid, pname, sizeof(pname));
    return pname;
}
Have fun
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)