Creating a Command reason
#1

I am trying to create a cmdreason thing. I see it in other gamemodes, but when i try it in mine, it doesn't work.
Like:
/test [Reason]
and that reason would be cmdreason. Any help??
Reply
#2

What do you mean by command reason?
Reply
#3

you mean creating a string?
Reply
#4

pawn Код:
if(!strcmp("/test", cmd, true))
{
        tmp = strtok(cmdtext, idx);
        new str[128];    
        format(str, sizeof(str), "Reason: %s", tmp);
        SendClientMessage(playerid, -1, str);
        return 1;
}
?
Reply
#5

Quote:
Originally Posted by TiNcH010
Посмотреть сообщение
pawn Код:
if(!strcmp("/test", cmd, true))
{
        tmp = strtok(cmdtext, idx);
        new str[128];    
        format(str, sizeof(str), "Reason: %s", tmp);
        SendClientMessage(playerid, -1, str);
        return 1;
}
?
why string in 128 , why not 64?
Reply
#6

Quote:
Originally Posted by axxelac
Посмотреть сообщение
why string in 128 , why not 64?
Because if he want write too long..
Or you can try this:

pawn Код:
if(!strcmp("/test", cmdtext, true))
{
        new str[128];    
        format(str, sizeof(str), "Reason: %s", cmdtext[1]);
        SendClientMessage(playerid, -1, str);
        return 1;
}
Reply
#7

Take a look at a command processor like ZCMD, it's much easier for beginners.
https://sampforum.blast.hk/showthread.php?tid=91354
Reply
#8

I meant a reason, like this:
(Ignore the ID part) You wanted a reason for a ban.
So: /ban ID REASON
The reason part is the one i need help on. I need to add that
Reply
#9

Quote:
Originally Posted by stormchaser206
Посмотреть сообщение
I meant a reason, like this:
(Ignore the ID part) You wanted a reason for a ban.
So: /ban ID REASON
The reason part is the one i need help on. I need to add that
Use sscanf.
If not, you can check the gamemodes on the gamemodes category, and take the /ban comand.
Reply
#10

Using strtok to check parameters is an impractical way of making commands.

Here you can see a ban command be made in 20 lines.
pawn Код:
CMD:ban(playerid,params[])
{
    new string[128],
        reason[50],
        target;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not allowed to use this command.");
    if(sscanf(params,"us[50]",target,reason)) return SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason]");
    else
    {
        new
            name[24],
            targetname[24];
        GetPlayerName(playerid,name,sizeof(name));
        GetPlayerName(target,targetname,sizeof(targetname));
        format(string,sizeof(string),"Administrator %s has banned %s. Reason: %s",name,targetname,reason);
        SendClientMessageToAll(-1, string);
        Ban(target);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)