06.04.2017, 16:07
PHP код:
stock GetPlayerID(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;
}
You also need to check if the player is connected in your id command.
PHP код:
CMD:id(playerid, params[])
{
new id,string[150],name[24],pname[24];
if(sscanf(params, "u", name)) return SendClientMessage(playerid,-1,"Usage: /id [name]");
id = GetPlayerID(name);
if(id=INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player not connected!");
GetPlayerName(id,pname,24);
format(string,sizeof(string),"%d %s",id,pname);
SendClientMessage(playerid,COLOR_LIGHTGRAY,string);
return 1;
}