Multi-Parameter Commands!
#2

The easiest approach to sub or multi parameter commands is sscanf which is a string splitter. It takes a string apart based on a given range of specifiers(such as d, i, s, etc.)

I know you're not asking for code, but let's apart this example based on your command:
pawn Код:
CMD:givemoney(playerid, params[])
{
      new giveplayerid, cash; // we need to define the inputs using sscanf
      if(sscanf(params, "ud", giveplayerid, cash)) return SendClientMessage(playerid, -1, "USAGE: /givemoney [playerid] [cash]");
     
      GivePlayerCash(giveplayerid, cash);
      return 1;
}
Basically the "ud" are the specifiers.
"u" - the playerID / partofname
"d" - an integer value

sscanf returns 1 if the string didn't contain the inputs, or was formatted incorrectly according to the specifiers. 0 is returned when it is able to split the strings.
Reply


Messages In This Thread
Multi-Parameter Commands! - by ironmen - 07.06.2015, 20:44
Re: Multi-Parameter Commands! - by Abagail - 07.06.2015, 20:51
Re: Multi-Parameter Commands! - by ironmen - 07.06.2015, 20:55
Re: Multi-Parameter Commands! - by ironmen - 07.06.2015, 21:00
Re: Multi-Parameter Commands! - by Abagail - 07.06.2015, 21:02
Re: Multi-Parameter Commands! - by ironmen - 07.06.2015, 21:04
Re: Multi-Parameter Commands! - by Abagail - 07.06.2015, 21:10
Re: Multi-Parameter Commands! - by ironmen - 08.06.2015, 05:30

Forum Jump:


Users browsing this thread: 1 Guest(s)