(/command [id] [time]) how can i add another variable?
#1

How can change this so insted of /command ID TIME
it works as /command ID TIME REASON

pawn Код:
if(strcmp(cmd, "/aj", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pGmL] >= 2)
            {
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /aj [ID] [MIN]");
                    return 1;
                }
                new para1;
                new level;
                para1 = ReturnUser(tmp);
                tmp = strtok(cmdtext, idx);
                level = strval(tmp);
Reply
#2

Use a command processor (ZCMD/YCMD) and sscanf.
Reply
#3

can i not do it with this?
Reply
#4

You always can ofc, but that is deemed impractical by today's users. Using a command processor is much more simpler, as all you do is include a file into your gamemode, and use the macro. A /givemoney command can be made in less than 20 lines without assigning a million variables, and it's just generally easy to use.

Example:
pawn Код:
CMD:setmoney(playerid,params[])
{
    new
        target,
        money;

    if(sscanf(params,"ui",target,money))
    {
        return SendClientMessage(playerid,COLOR_LIGHTGRAY,"USAGE: /setmoney [playerid] [amount]");
    }
    else
    {
        ResetPlayerMoney(target);
        GivePlayerMoney(target,money);
    }
    return 1;
}
Reply
#5

It's easy to add more parameters with strcmp (the old-school way :P)

pawn Код:
if(strcmp(cmd, "/aj", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pGmL] >= 2)
            {
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Uz.yj: /aj [ID] [MIN]");
                new para1 = ReturnUser(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Uz.yj: /aj [ID] [MIN]");
                new level = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Uz.yj: /aj [ID] [MIN] [PARAM 3]");
                new para3 = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Uz.yj: /aj [ID] [MIN] [PARAM 4]");
                new para4 = strval(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Uz.yj: /aj [ID] [MIN] [PARAM 5]");
                new para5 = strval(tmp);
                //done...
But as everyone is saying, switch to ZCMD and SSCANF.
Reply
#6

wow this is class:
pawn Код:
CMD:setmoney(playerid,params[])
{
    new
        target,
        money;

    if(sscanf(params,"ui",target,money))
    {
        return SendClientMessage(playerid,COLOR_LIGHTGRAY,"USAGE: /setmoney [playerid] [amount]");
    }
    else
    {
        ResetPlayerMoney(target);
        GivePlayerMoney(target,money);
    }
    return 1;
}
but can i use it like this:

pawn Код:
if command bla bla?
{
    new
        target,
        money;

    if(sscanf(params,"ui",target,money))
    {
        return SendClientMessage(playerid,COLOR_LIGHTGRAY,"USAGE: /setmoney [playerid] [amount]");
    }
    else
    {
        ResetPlayerMoney(target);
        GivePlayerMoney(target,money);
    }
    return 1;
}
Reply
#7

no u can't

ZCMD is zcmd, strcmp is strcmp
Reply
#8

you CAN use sscanf inside of OnPlayerCommandText along with strcmp
instead of using strok although I would not do that its up to you.
Reply
#9

ok ill do it this way
pawn Код:
CMD:setmoney(playerid,params[])
{
    new
        target,
        money;

    if(sscanf(params,"ui",target,money))
    {
        return SendClientMessage(playerid,COLOR_LIGHTGRAY,"USAGE: /setmoney [playerid] [amount]");
    }
    else
    {
        ResetPlayerMoney(target);
        GivePlayerMoney(target,money);
    }
    return 1;
}
so what else do I need at the top towards CMD:blabla for it to work?
Reply
#10

Will this work?

pawn Код:
CMD:aj(playerid,params[])
{
    new
        target,
        time,
        reason;

    if(sscanf(params,"uiS(string)[128]",target,money,reason))
    {
        return SendClientMessage(playerid,COLOR_LIGHTGRAY,"USAGE: /aj [playerid] [time] [reason]");
    }
    else
    {
     //etc
    }
    return 1;
}
btw i already have the include and plugin, I just never used it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)