/ban and /kick causing crash?
#1

Ok the command works if you try to kick a different player but if a admin tries to ban himself or even kick himself the server crashes.

Heres the codes:

Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
		new PID, pName[MAX_PLAYER_NAME], Sender[MAX_PLAYER_NAME];
    	if(sscanf(params, "u", PID)) return SendClientMessage(playerid, COLOR_GREY, "[pr0adm]USAGE: /ban [playerid]");
    	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_GREY, "[pr0adm]Player is not connected!");

		new Str[128];
		GetPlayerName(PID, pName, sizeof(pName));
    	GetPlayerName(playerid, Sender, sizeof(Sender));
        SendClientMessageToAll(COLOR_ORANGE,"[pr0adm]%s has banned %s.",PID,Sender);
		format(Str, sizeof(Str), "[pr0adm]You banned %s!", PID);
    	SendClientMessage(playerid, COLOR_LIGHTBLUE, Str);
		BanEx(PID,"banned");

	}
	else
	{
	    SendClientMessage(playerid, COLOR_GREY, "[pr0adm]You must be level 4 pr0admin to use this command!");
	}
	return 1;
}
Код:
CMD:kick(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
		new PID, pName[MAX_PLAYER_NAME], Sender[MAX_PLAYER_NAME];
    	if(sscanf(params, "u", PID)) return SendClientMessage(playerid, COLOR_GREY, "[pr0adm]USAGE: /kick [playerid]");
    	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_GREY, "[pr0adm]Player is not connected!");

		new Str[128];
		GetPlayerName(PID, pName, sizeof(pName));
    	GetPlayerName(playerid, Sender, sizeof(Sender));

		format(Str, sizeof(Str), "[pr0adm]You kicked %s!", PID);
    	SendClientMessage(playerid, COLOR_LIGHTBLUE, Str);
    	new string[128];
            GetPlayerName(playerid, pName, sizeof(pName));
            format(string, sizeof(string), "[pr0adm]%s has kicked %s", Sender, PID);
            return SendClientMessageToAll(COLOR_BLUE, string);
		    Kick(PID);

	}
	else
	{
	    SendClientMessage(playerid, COLOR_GREY, "[pr0adm]You must be level 2 pr0admin to use this command!");
	}
	return 1;
}
As i said,they work but crash server if someone attempts to use it on themself.Any help plz?
Reply
#2

just add
bellow
if(sscanf(params, "u", PID))....

Код:
if(playerid == PID) return SendClientMessage(playerid, COLOR_GREY, "You can't ban yourself!");
// your code...
Reply
#3

These lines:
pawn Код:
format(Str, sizeof(Str), "[pr0adm]You kicked %s!", PID);
format(string, sizeof(string), "[pr0adm]%s has kicked %s", Sender, PID);
PID is not %s (string) it's an integer so you should use %d or %i. Maybe this will help also, but yes, add the line what the previous poster posted.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)