Find player by name
#4

To give some extra info about stock: Using keyword stock you indeed tell the compiler the piece of code is not required to use (thus not showing a warning if it's unused).
In gamemodes, you usually only create functions when you need them so the use of stock is really not needed. 'stock' is not a keyword you need to create a function. You can even declare variables as stock.

Apart from that:
pawn Code:
GetIDFromName(const name[])
{
    new ret_id;
    sscanf(name, "u", ret_id);
    return ret_id;
}
INVALID_PLAYER_ID is returned if the player wasn't found. -1 is returned if no name was entered. Otherwise it returns the playerid.
The upside of this is that it is faster than looping through players, comparing their name in strcmp(). And partly names work (if there aren't multiple matches).
If player "SuperPlayerxTF" is online, using GetIDFromName("Super") would return the ID of SuperPlayerxTF.
Reply


Messages In This Thread
Find player by name - by PowerF - 28.06.2020, 04:51
Re: Find player by name - by algorhitmically - 28.06.2020, 07:24
Re: Find player by name - by SkyFlare - 28.06.2020, 10:13
Re: Find player by name - by Kwarde - 28.06.2020, 10:43

Forum Jump:


Users browsing this thread: 1 Guest(s)