• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Function Get ID by name
#7
Code:
IdByName(const name[])
{
    new
         iPlayer = INVALID_PLAYER_ID,
         names[MAX_PLAYER_NAME];
        
    foreach(new i : Player)
    {
        GetPlayerName(i, names, sizeof(names));
        
        if(strcmp(name, names, true)) {
            continue;
        }
            
        iPlayer = i;
        break;
    }
    return iPlayer;
}
Idk if this will help but at least it's code

...or...

Code:
IdByName(const name[]) //Lol
{
    new
        tmpID = INVALID_PLAYER_ID,
        tmpName[MAX_PLAYER_NAME];
        
    if (!sscanf(name, "r", tmpID))
    {
        GetPlayerName(tmpID, tmpName, sizeof(tmpName));
        
        if (strcmp(name, tmpName, true)) {
            tmpID = INVALID_PLAYER_ID;
        }
    }
    return tmpID;
}

...or...

Code:
IdByName(const name[]) //Lol v2
{
    new
        tmpID = INVALID_PLAYER_ID,
        tmpName[MAX_PLAYER_NAME];
        
    sscanf(name, "r", tmpID);
    
    if (!GetPlayerName(tmpID, tmpName, sizeof(tmpName)) {
        return tmpID;
    }

    if (strcmp(name, tmpName, true)) {
        tmpID = INVALID_PLAYER_ID;
    }
    
    return tmpID;
}
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply


Messages In This Thread
Function Get ID by name - by GospodinX - 2021-03-16, 01:34 PM
RE: Function Get ID by name - by Y_Less - 2021-03-16, 01:42 PM
RE: Function Get ID by name - by GospodinX - 2021-03-16, 04:22 PM
RE: Function Get ID by name - by Radical - 2021-03-16, 03:39 PM
RE: Function Get ID by name - by Y_Less - 2021-03-16, 04:30 PM
RE: Function Get ID by name - by GospodinX - 2021-03-16, 06:39 PM
RE: Function Get ID by name - by Pinch - 2021-03-17, 03:01 AM

Forum Jump: