/ban CMD
#1

Can someone make /ban CMD ? I'm using ZCMD, thanks.
Reply
#2

are you using sscanf ?
Reply
#3

Sscanf and ZCMD.
Reply
#4

pawn Код:
CMD:ban(playerid,params[])

{
    new Target,Reason;
    if(!sscanf(params,"us[124]",Target,Reason))
    {
        if(IsPlayerConnected(Target))
        {
            if(pInfo[Target][Admin] > pInfo[playerid][Admin])
            {
                SendClientMessage(playerid,-1,"WARNING: An error occured. [Reason: Banning higher level admins is forbidden.");
            }
            else
            {
                new String[124],Name[MAX_PLAYER_NAME];
                GetPlayerName(Target,Name,sizeof(Name));
                format(String,sizeof(String),"%s has been banned. [Reason: %s]",Name,Reason);
                SendClientMessageToAll(-1,String);
                Ban(Target);
            }
        }
        else
        {
            SendClientMessage(playerid,-1,"WARNING: An error occured. [Reason: Player is not connected.");
        }
    }
    else
    {
        SendClientMessage(playerid,-1,"USAGE: /Ban [Playerid] [Reason]");
    }
    return 1;
}
Reply
#5

try this above
Reply
#6

pawn Код:
CMD:ban(playerid, params[])
{
    new pID, reason[68], msg[128], name[MAX_PLAYER_NAME], bannername[MAX_PLAYER_NAME];
    if(sscanf(params, "us", pID, reason)) return SendClientMessage(playerid, 0xDF0000FF, "USAGE: /ban [playerid] [reason]");
    {
        GetPlayerName(pID, name, sizeof(name));
        GetPlayerName(pID, bannername, sizeof(bannername));
        format(msg, sizeof(msg), "[AdmCmd]: %s has been banned by %s, reason: %s", name, bannername, reason);
        SendClientMessageToAll(0xDF0000FF, msg);
        BanEx(pID, reason);
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by Anthony ©
Посмотреть сообщение
pawn Код:
CMD:ban(playerid, params[])
{
    new pID, reason[68], msg[128], name[MAX_PLAYER_NAME], bannername[MAX_PLAYER_NAME];
    if(sscanf(params, "us", pID, reason)) return SendClientMessage(playerid, 0xDF0000FF, "USAGE: /ban [playerid] [reason]");
    {
        GetPlayerName(pID, name, sizeof(name));
        GetPlayerName(pID, bannername, sizeof(bannername));
        format(msg, sizeof(msg), "[AdmCmd]: %s has been banned by %s, reason: %s", name, bannername, reason);
        SendClientMessageToAll(0xDF0000FF, msg);
        BanEx(pID, reason);
    }
    return 1;
}
pawn Код:
if(sscanf(params, "us", pID, reason))
You will get a warning in the Console.

It should be:

pawn Код:
if(sscanf(params, "us[68]", pID, reason))
If you need help(topic creator) tell me and I'll help you.
Reply
#8

Script work, but had a bug: The admin (who ban player) and banned player are the same..
Reply
#9

I made this quickly, I tested it and it works, this is 100% compatible, if you're using sscanf2 that is, if you're not then simply remove the '[64]' in the sscanf check.
pawn Код:
COMMAND:ban(playerid, params[])
{
    new targetId, banReason[64];
    if(!IsPlayerAdmin(playerid) /* Or change to a variable */) return SendClientMessage(playerid, COLOR_RED, "You're not an administrator!");
    else if(sscanf(params, "us[64]", targetId, banReason)) return SendClientMessage(playerid, COLOR_ORANGE, "Usage: /ban [id][reason]");
    else if(!IsPlayerConnected(targetId)) return SendClientMessage(playerid, COLOR_RED, "That player isn't connected!");
    else
    {
        new playerName[MAX_PLAYER_NAME], targetName[MAX_PLAYER_NAME], banMessage[128];
       
        GetPlayerName(playerid, playerName, sizeof(playerName));
        GetPlayerName(targetId, targetName, sizeof(targetName));
       
        format(banMessage, sizeof(banMessage), "Administrator %s(%d) has banned player %s(%d). Reason: %s", playerName, playerid, targetName, targetId, banReason);
        SendClientMessageToAll(COLOR_RED, banMessage);
        print(banMessage);
       
        format(banMessage, sizeof(banMessage), "Banned by %s. Reason: %s", playerName, banReason);
        BanEx(targetId, banMessage);
    }
    return 1;
}
Also, make sure you have the colours red and orange defined, if not, they're here.

pawn Код:
#define COLOR_RED 0xFF0000FF
#define COLOR_ORANGE 0xFF8000FF
What's up with this Anthony?

Quote:
Originally Posted by Anthony ©
Посмотреть сообщение
pawn Код:
CMD:ban(playerid, params[])
{
    new pID, reason[68], msg[128], name[MAX_PLAYER_NAME], bannername[MAX_PLAYER_NAME];
    if(sscanf(params, "us", pID, reason)) return SendClientMessage(playerid, 0xDF0000FF, "USAGE: /ban [playerid] [reason]");
    {
        GetPlayerName(pID, name, sizeof(name));
        GetPlayerName(pID, bannername, sizeof(bannername));
        format(msg, sizeof(msg), "[AdmCmd]: %s has been banned by %s, reason: %s", name, bannername, reason);
        SendClientMessageToAll(0xDF0000FF, msg);
        BanEx(pID, reason);
    }
    return 1;
}
Seriously? You're getting the name of the same player twice, and ANYONE can execute this command, even regular players, it's worth adding a RCON admin check in there.
Reply
#10

If i change to variable:

if(PlayerInfo[playerid][pAdmin] == 1)) return SendClientMessage(playerid, 0xDEEE20FF, "You're not an administrator!");

I got many errors:

C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 556) : error 029: invalid expression, assumed zero
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 556) : warning 215: expression has no effect
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 556) : error 001: expected token: ";", but found "return"
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 557) : warning 225: unreachable code
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 557) : error 029: invalid expression, assumed zero
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 557) : warning 215: expression has no effect
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 557) : error 001: expected token: ";", but found "if"
C:\Users\Lauryno\Desktop\Servas\gamemodes\bom.pwn( 55 : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.


And i got the same problem:



I doesn't ban my self, i ban another nick.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)