Ban cmd not banning offline player
#1

Hey there, i need a little help when ever i type /ban playername it says invalid id but it should ban the offline player instead its showing invalid id., here is the code:

Код:
CMD:ban(playerid,params[])
{
	if(IsMuted(playerid))return 1;
    new string[128],ID,reason[128];
	if(AdminLevel[playerid] >=2)
    {
    	if(!sscanf(params,"us[128]",ID,reason))
    	{
    		if(!IsPlayerConnectedEx(ID)||ID==playerid)return SendClientMessage(playerid,GREY,"Invalid player ID");
    		if(strlen(reason) >128) return SendClientMessage(playerid,GREY,"Reason can't be longer than 100 characters");
    		if(AdminLevel[playerid]<AdminLevel[ID])return SendClientMessage(playerid,GREY,"You can't perform this command on your seniors");
    		format(string,sizeof(string),"~%s has been banned from the server for '%s'",PlayerName(ID),reason);
			SetCameraBehindPlayer(ID);
			INI_IntSet(Acc(ID),"Banned",1);
			INI_Set(Acc(ID),"Reason",reason);
			TogglePlayerControllable(ID,false);
			SendClientMessageToAll(RED,string);
			INI_Set(Acc(ID),"Banner",PlayerName(playerid));
			Kicked[ID]=1;
 		}
    	else if(!sscanf(params,"u",ID))
    	{
    		if(!IsPlayerConnectedEx(ID)||ID==playerid)return SendClientMessage(playerid,GREY,"Invalid player ID");
    		if(AdminLevel[playerid]<AdminLevel[ID])return SendClientMessage(playerid,GREY,"You can't perform this command on your seniors");
    		format(string,sizeof(string),"~%s has been banned from the server",PlayerName(ID));
			SetCameraBehindPlayer(ID);
			INI_IntSet(Acc(ID),"Banned",1);
			INI_Set(Acc(ID),"Reason","N/A");
			TogglePlayerControllable(ID,false);
			SendClientMessageToAll(RED,string);
			INI_Set(Acc(ID),"Banner",PlayerName(playerid));
			Kicked[ID]=1;
    	}
		else if(!sscanf(params,"s[50]",reason))
		{
			new PlayerFile[50];
			if(AdminLevel[playerid]<3)return 0;
			format(PlayerFile,sizeof(PlayerFile),"Accounts/%s.ini",reason);
			if(!fexist(PlayerFile)) return SendClientMessage(playerid,GREY,"No such player found in the database");
			if(fexist(PlayerFile))
			{
			    if(INI_Int(PlayerFile,"Banned")==1)return SendClientMessage(playerid,GREY,"That player is already banned");
    			INI_IntSet(PlayerFile,"Banned",1);
    			SendClientMessage(playerid,-1,"Account Banned");
				INI_Set(PlayerFile,"Banner",PlayerName(playerid));
			}
		}else return SendClientMessage(playerid,GREY,"USAGE: /ban [playerid] [reason]")&&
		SendClientMessage(playerid,-1,"USAGE: /ban [PlayerName] [For Offline Ban]");
    }else return 0;
    return 1;
}
Reply
#2

This CMD works for banning who is Online I suppose
Also :
PHP код:
else if(!sscanf(params,"s[50]",reason))
        {
            new 
PlayerFile[50];
            if(
AdminLevel[playerid]<3)return 0;
            
format(PlayerFile,sizeof(PlayerFile),"Accounts/%s.ini",reason);
            if(!
fexist(PlayerFile)) return SendClientMessage(playerid,GREY,"No such player found in the database");
            if(
fexist(PlayerFile))
            {
                if(
INI_Int(PlayerFile,"Banned")==1)return SendClientMessage(playerid,GREY,"That player is already banned");
                
INI_IntSet(PlayerFile,"Banned",1);
                
SendClientMessage(playerid,-1,"Account Banned");
                
INI_Set(PlayerFile,"Banner",PlayerName(playerid));
            }
        } 
It doesn't work. Cause you're not banning anyone! you're just giving a reason without banning someone.
Reply
#3

you are right so anyidea how to fix it i think putting ID in place of reason wont work right?
Reply
#4

You're trying to ban an offline player, but you're still checking if he's connected.
So remove the !IsPlayerConnectedEx(ID) check.
Reply
#5

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
You're trying to ban an offline player, but you're still checking if he's connected.
So remove the !IsPlayerConnectedEx(ID) check.
Yeah my bad its fixed now thanks for correction mate, +rep for both of you guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)