Just a quick help with a command
#1

Hey,

So I've just been wondering where the hell did I mess up with the ban command here? It does not give me errors, however, whichever ID I ban, it always inserts ID 0's player's name. So, let's say I ban ID 8, it actually bans the correct ID, however, ID 0's name gets called in the format.

Code is below. I might be blind a bit here, but I can't see where did I mess up. Ty in advance ;-;

Код:
 CMD:ban(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 2) {
            new Playerid;
            new reason[64]; 
            new str[128]; 
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; 
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); 
 	  		GetPlayerName(Playerid, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", Playerid,reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ban [playerid] [reason]");

            if(!IsPlayerConnected(Playerid))
                return SendClientMessage(playerid, COLOR_WHITE, "ERROR: Player is not connected!");

            format(str, sizeof(str), "[ADMIN ACTION] %s have been banned by Administrator %s [Reason: %s] ", Playername, Adminname, reason);
  		BanEx(Playerid);

        }
        else
        {
            SendClientMessage(playerid, COLOR_WHITE, "ERROR: You are not authorised to use this command!"); 
        }
        return 1;
    }
Reply
#2

Try getting the name after the params check
Reply
#3

Quote:
Originally Posted by Daddy Yankee
Посмотреть сообщение
Try getting the name after the params check
Not try, you're actually right he does need to get the player's name after the params check that's why for him its returning id 0's name at all times,

@OP it should look like this:
PHP код:
 CMD:ban(playeridparams[])
    {
        if(
PlayerInfo[playerid][pAdmin] >= 2) {
            new 
Playerid;
            new 
reason[64]; 
            new 
str[128]; 
            new 
Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; 
            
GetPlayerName(playeridAdminnamesizeof(Adminname)); 
            if(
sscanf(params"us[64]"Playerid,reason)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /ban [playerid] [reason]");

            if(!
IsPlayerConnected(Playerid))
                return 
SendClientMessage(playeridCOLOR_WHITE"ERROR: Player is not connected!");
            
GetPlayerName(PlayeridPlayernamesizeof(Playername));//moved
            
format(strsizeof(str), "[ADMIN ACTION] %s have been banned by Administrator %s [Reason: %s] "PlayernameAdminnamereason);
          
BanEx(Playerid);

        }
        else
        {
            
SendClientMessage(playeridCOLOR_WHITE"ERROR: You are not authorised to use this command!"); 
        }
        return 
1;
    } 
Reply
#4

Yup, you both are right.

Cheers guys, it totally dropped from me there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)