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;
}
...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.
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.