28.06.2020, 10:43
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:
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.
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;
}
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.