(/command [id] [time]) how can i add another variable? -
HondaCBR - 16.04.2012
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);
Re: (/command [id] [time]) how can i add another variable? -
MP2 - 16.04.2012
Use a command processor (ZCMD/YCMD) and sscanf.
Re: (/command [id] [time]) how can i add another variable? -
HondaCBR - 16.04.2012
can i not do it with this?
Re: (/command [id] [time]) how can i add another variable? -
ReneG - 16.04.2012
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;
}
Re: (/command [id] [time]) how can i add another variable? -
coole210 - 16.04.2012
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.
Re: (/command [id] [time]) how can i add another variable? -
HondaCBR - 16.04.2012
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;
}
Re: (/command [id] [time]) how can i add another variable? -
AlTy - 16.04.2012
no u can't
ZCMD is zcmd, strcmp is strcmp
Re: (/command [id] [time]) how can i add another variable? -
Jonny5 - 16.04.2012
you CAN use sscanf inside of OnPlayerCommandText along with strcmp
instead of using strok although I would not do that its up to you.
Re: (/command [id] [time]) how can i add another variable? -
HondaCBR - 16.04.2012
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?
Re: (/command [id] [time]) how can i add another variable? -
HondaCBR - 16.04.2012
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