SA-MP Forums Archive
Something is wrong with the ban command. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Something is wrong with the ban command. (/showthread.php?tid=593551)



Something is wrong with the ban command. - Ercha - 06.11.2015

Hello. So I have made a ban command, but when I ban someone, it bans me too, just says "The server closed the connection". How to fix that?

Here is my code:

PHP код:
CMD:ban(playerid,params[])
{
    if(
pInfo[playerid][pAdminLevel] >= 2)
    {
        if(
IsPlayerConnected(playerid))
        {
            new 
targetid,reason[105],ip[50],string[256];
            if(
sscanf(params"us[105]"targetid,reason)) return SendClientMessage(playerid,-1,"{C0C0C0}USAGE: /ban [playerid] [reason]");
            if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""chat" Player is not online.");
            
format(stringsizeof(string), "{DC143C}Administrator %s has banned %s [Reason: %s]",PlayerName(playerid),PlayerName(targetid),reason);
            
SendClientMessageToAll(-1,string);
            
format(string,sizeof(string), "You are banned from the server!\n\n{DC143C}Banned by{ffffff}: %s\n{DC143C}Reason{ffffff}: %s\n\nYou can post Ban Appeal on our Forums:\n{FFFF33}www.blablabla.com",PlayerName(playerid), reason);
            
ShowPlayerDialog(targetid,DIALOG_HELP,DIALOG_STYLE_MSGBOX,"{DC143C}BANNED",string,"Close","");
            
pInfo[targetid][pBanned] = 1;
            
GetPlayerIp(targetidipsizeof(ip));
            
format(stringsizeof(string), "banip %s",ip);
            
SetTimerEx("BanTimer"1000false"i"playerid);
        }
    }
    else {
        
//SendClientMessage(playerid,-1,""chat""COL_LIGHTBLUE" You do not have the right admin permissions for this command!");
    
}
    return 
1;
}
public 
BanTimer(playerid)
{
    
Ban(playerid);
    return 
1;
}
forward BanTimer(playerid); 
Thanks in advance for the help!


Re: Something is wrong with the ban command. - [ABK]Antonio - 06.11.2015

SetTimerEx("BanTimer", 1000, false, "i", playerid); is playerid instead of targetid


Re: Something is wrong with the ban command. - AnthonyDaSexy - 06.11.2015

The reason why you get banned is because you have specified the playerid parameter in the timer:
pawn Код:
SetTimerEx("BanTimer", 1000, false, "i", playerid);
Instead of specifying the playerid specify the targetid:
pawn Код:
SetTimerEx("BanTimer", 1000, false, "i", targetid);
Edit: Too late, someone already posted before me.


Re: Something is wrong with the ban command. - Ercha - 06.11.2015

Ah, thanks. Silly me for not noticing the mistake.

+REP both of ya.