Reason on ban
#1

Hi. I am currently creating a roleplay server from scratch and I have made the basics such as storing skins, levels, loading possitions from where you crashed etc. but now it is time for me to create admin commands. I just converted to YCMD, and I am not very familiar with this system, so if anyone could help me with the ban command, I'd be very grateful.

My current ban command is:

pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
    new str[128];
    new id;
    id = strval(params);
    new playername[MAX_PLAYER_NAME+1];
    new bannedname[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, playername, sizeof(playername));
    GetPlayerName(id, bannedname, sizeof(bannedname));
    format(str, sizeof(str), "AdmCmd: %s was banned by %s", bannedname, playername);
    SendClientMessageToAll(COLOR_RED, str2);
    BanPlayer(id);
    }
    return 1;
}
So that's okay, but I'd like to add a reason for the ban but I don't know how to add that.
Reply
#2

you want like /ban [id] [reason] ?

if yes, you should use sscanf. and replcae BanPlayer(id); with BanEx(id, reason);
Reply
#3

simplest way is using sscanf
Reply
#4

Quote:
Originally Posted by kirollos
Посмотреть сообщение
you want like /ban [id] [reason] ?

if yes, you should use sscanf. and replcae BanPlayer(id); with BanEx(id, reason);
BanPlayer is a custom function I made. However, how would I add the reason if I were to use BanEx?

pawn Код:
forward BanPlayer(playerid);
public BanPlayer(playerid)
{
    PlayerInfo[playerid][pBanned] = 1;
    Kick(playerid);
    return 1;
}
Yes, I want /ban [id] [reason]
Reply
#5

So, never mind the BanPlayer();

What about this?
pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
    new str[128], id, reason[128];
    if(!sscanf(params, "is[128]", id, reason))
    {
    new playername[MAX_PLAYER_NAME+1];
    new bannedname[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, playername, sizeof(playername));
    GetPlayerName(id, bannedname, sizeof(bannedname));
    format(str, sizeof(str), "AdmCmd: %s was banned by %s (Reason: %s)", bannedname, playername, reason);
    SendClientMessageToAll(COLOR_RED, str);
    BanPlayer(id);
    } else return SendClientMessage(playerid, 0xEE0000FF, "USAGE: /ban [id] [reason]");
    } else return SendClientMessage(playerid, 0xEE0000FF, "You are not allowed to use this command!");
    return 1;
}
This should Work;

Have Fun
Reply
#6

Yes, it worked, however didn't teach me much.

Mind explaining me this line?
pawn Код:
if(!sscanf(params, "is[128]", id, reason))
That way I can learn more.
Reply
#7

something i forgot over here.

here it is the correct one:

pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
    new str[128], id, reason[128];
    if(!sscanf(params, "is[128]", id, reason))
    {
    if(IsPlayerConnected(id))
    {
    new playername[MAX_PLAYER_NAME+1];
    new bannedname[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, playername, sizeof(playername));
    GetPlayerName(id, bannedname, sizeof(bannedname));
    format(str, sizeof(str), "AdmCmd: %s was banned by %s (Reason: %s)", bannedname, playername, reason);
    SendClientMessageToAll(COLOR_RED, str);
    BanPlayer(id);
    } else return SendClientMessage(playerid, 0xEE0000FF, "ERROR: Player isn't connected!");
    } else return SendClientMessage(playerid, 0xEE0000FF, "USAGE: /ban [id] [reason]");
    } else return SendClientMessage(playerid, 0xEE0000FF, "You are not allowed to use this command!");
    return 1;
}
Reply
#8

-.- you copied my name...
Reply
#9

pawn Код:
CMD:ban(playerid, params[])
{
    new
        id,
        reason[40],
        fstr[128],
        pName[MAX_PLAYER_NAME],
        bName[MAX_PLAYER_NAME];
    if (PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF5959}You are not allowed to use this command!");
    if (sscanf(params, "ds", id, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF5959}USAGE: /ban [id] [reason]");
    if (!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF5959}This player isn't connected.");
    GetPlayerName(playerid, pName, sizeof(pName));
    GetPlayerName(id, bName, sizeof(bName));
    format(fstr, sizeof(fstr), "» {FF9900}The admin {00CED1}%s (%d){FFFFFF} has banned {00CED1}%s (%d){FFFFFF}. Reason: {F81414}%s", pName, playerid, bName, id, reason);
    SendClientMessageToAll(0xFFFFFFFF, fstr);
    Ban(id);
    return 1;
}
Reply
#10

I have provided a command with much more explanation in the comments. PM me if you need any more help.
pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 1)
    {
        new
            str[128], // a new string for the global message
            targetid, // the id of the player to be banned
            reason[40], // the string for the reason
            targetname[24], // selfexplanatory
            name[24] // the admin's name
        ;
        // this is where sscanf breaks apart your command
        // sscanf splits up 'params' which is all the parameters
        // into the variables that you want in your command
        // Now look at the qouted text, that is where you give
        // your command what parameters you want
        // The 'u' stands for a username/id
        // the 's[40]' stands for the reason
        // then just like format you insert the variables above in the
        // rest of the parameters
        if(sscanf(params, "us[40]", targetid, reason))
        {
            // sscanf automatically returns false, but the line
            // above is saying if sscanf returns true
            // so basically it means if a player DIDN'T
            // type the command correctly
            SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason]");
            return 1; // we return to stop the command
        }
        // if the id they typed is not connected
        if(targetid == INVALID_PLAYER_ID)
        {
            // then it returns this message
            SendClientMessage(playerid, -1, "Player is not connect");
            return 1;
        }
        // so now if they DID type the command correctly
        GetPlayerName(playerid, name, sizeof(name)); // we get the names below
        GetPlayerName(targetid, targetname, 24);
        format(str, sizeof(str), "AdmCmd: %s was banned by %s", name, targetname); // format the string
        SendClientMessageToAll(COLOR_RED, str); // send it to all
        BanPlayer(id);
    }
    else
    {
        // if they aren't an admin then it will return the "UNKOWN COMMAND message"
        return 0;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)