[help] /kick with reason
#1

cmd: /kick [id] [reason]

i want to be able to add a reason to this code:

pawn Код:
if(strcmp("/kick", cmdtext, true, 5) == 0)
    {
        if(Level[playerid] == 0) return 0;
        if(strlen(cmdtext[6]) == 0) return SendClientMessage(playerid, red, "You did not enter an ID");
        if(IsPlayerConnected(strval(cmdtext[6])) == 0) return SendClientMessage(playerid, red, "That player is not connected");

        new cmdname[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, cmdname, sizeof(cmdname));
        GetPlayerName(strval(cmdtext[6]), cmdname, sizeof(cmdname));

        format(string, sizeof(string), "**KICK [ADMIN KICK] %s Has Been Kicked From The Server By An Admin.", cmdname);
        SendClientMessageToAll(pink, string);

        Kick(strval(cmdtext[6]));
        return 1;
    }
Reply
#2

anyone? plz
Reply
#3

I'd suggest using DCMD + scanf.
Reply
#4

dcmd is to confusing to me :S
Reply
#5

i will unconfuse it for you
put the define line at the top of your script with the variables
goto OnPlayerCommandText
type in
pawn Код:
dcmd(kick, 4, cmdtext); //command name without '/', length of command, and cmdtext(in case you renamed cmdtext to something else, you would change that)
than goto the bottom of your script and make a function called, and with the paramaters of
pawn Код:
dcmd_kick(playerid, params[])
now about sscanf, this can be used in many places, not just in cmds, but i will teach you for commands.(put sscanf in your script)
the usage is like this
pawn Код:
sscanf(params, "us", pid, reason) //u is a userid or name, s is a string, z is optional string
so you could do it in an if like this
pawn Код:
if (sscanf(params, "us", pid, reason)) SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /kick [playerid] [reason]");
so i will convert your command so you can understand.


pawn Код:
dcmd_kick(playerid, params[])
{
new pid, reason;
if (sscanf(params, "us", pid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /kick [playerid] [reason]
if(Level[playerid] == 0) return 0;

new pname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME] string[128];
GetPlayerName(playerid, pname1, 24);
GetPlayerName(pid, pname2, 24);

format(string, sizeof(string), "
**KICK [ADMIN KICK] %s Has Been Kicked From The Server By Admin %s Reason:%s.", pname2, pname1, reason);
SendClientMessageToAll(pink, string);

Kick(pid);
return 1;
this could be easily be converted so reason is optional, and almost as easy to make it not say Reason: than nothing here

hope i could help

Reply
#6

and will this work even though no other cmds use dcmd, this will be the only one?
Reply
#7

yes it will, as long as you have dcmd and sscanf in your script
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)