CMD:kick(playerid, params[])
{
new
targetid,
Reason[256],
pName[MAX_PLAYER_NAME],
tName[MAX_PLAYER_NAME],
string[256]
;
GetPlayerName(playerid, pName, sizeof(pName));
GetPlayerName(targetid, tName, sizeof(tName));
format(string, sizeof(string), "{4286f4}(Information):{FFFFFF} Administrator {FF0000}%s{FFFFFF} has kicked {00FF00}%s{FFFFFF}! | Reason: {FFFF00}%s", pName, tName, Reason);
if(P_DATA[playerid][aLevel] < 1)return SendClientMessage(playerid, -1, "{FF0000}(ERROR):{FFFFFF} You must be Moderator to use this command!");
if(sscanf(params, "ds[256]", targetid, Reason))return SendClientMessage(playerid, -1, "{FF9900}(Usage):{FFFFFF} /kick [ID] [Reason]");
if(!IsPlayerConnected(targetid))return SendClientMessage(playerid, -1, "{FF0000}(ERROR):{FFFFFF} This player is not connected!");
SendClientMessageToAll(-1, string);
SetTimerEx("KickTimer", 1000, false, "i", targetid);
return 1;
}
Getting the player's name before sscanf will always get the name of the player with ID 0 as "targetid" will be by default 0 and hasn't been assigned a value yet. Move it after sscanf and IsPlayerConnected check.
Checking if "targetid" is INVALID_PLAYER_ID is much better than calling IsPlayerConnected function. |