Bug kick command on id 1
#1

Hello! I have a problem with kick command with id 1, even if the player is not connected command is still running and send message with " has been kicked by x. Reason: y".

Here is the code:

CMD:kick(playerid, params[])
{
if(pLogged[playerid] == 0) return LoginError(playerid);
new id, reason[100], string[100], playername[100], targetname[100];
if(PlayerInfo[playerid][pAdmin] >= 1)
{
if(sscanf(params, "ds[100]", id, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "Syntax: /kick [playerid] [reason].");
{
if(id != INVALID_PLAYER_ID)
{
if(id == playerid) return SendClientMessage(playerid, -1, "Error: You can't kick yourself.");
GetPlayerName(id, targetname, sizeof(targetname));
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "Kick: %s has been kicked by %s. Reason: %s", targetname, playername, reason);
SendClientMessageToAll(COLOR_KICK, string);
Kick(id);
}
else return SendClientMessage(playerid, COLOR_SYNTAX, "Error: Player not connected.");
}
}
else
{
AdminError(playerid);
}
return 1;
}
Reply
#2

The problem relies inside this statement
Код:
if(id != INVALID_PLAYER_ID)
INVALID_PLAYER_ID is defined as 65535, what that conditional is checking is not what you want to check there.

What you really want to check there is the returning value of the function IsPlayerConnected, and if true continue with the rest of the function.
Reply
#3

That was the problem. Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)