Multi-Parameter Commands!
#1

Hello!
Im a begginer!
i just need help in multi-parameter commands like /givemoney (playerid) (cash)
But please don't give me a code i need an explanation please!!!!
Reply
#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
#3

thanks a lot!!!!!!
Reply
#4

But how i can make like /goto (playerid)
Please explain!
Reply
#5

Using the same way just without the second specific, parameter.

pawn Код:
CMD:goto(playerid, params[])
{
      new giveplayerid;
      if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, -1, "USAGE: /goto [playerid]");
     
      new Float: x, Float: y, Float: z;
      GetPlayerPos(giveplayerid, x, y, z);
      SetPlayerPos(playerid, x, y, z);
     
      return 1;
}
Reply
#6

sorry i mean how to make /goto with another command that enable/disable going to that player
I think i must use switches and cases
Reply
#7

Why would you need to make a switch? If you mean a /goto off for the "giveplayerid":

pawn Код:
new bool: Goto[MAX_PLAYERS][MAX_PLAYERS];
towards the top ^^

then, below the sscanf line

pawn Код:
if(Goto[giveplayerid][playerid] == true) return SendClientMessage(playerid, -1, "That player has disabled you from using /goto to TP to them!");
then something such as:
pawn Код:
CMD:disablegoto(playerid, params[])
{
      new giveplayerid;
      if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, -1, "USAGE: /disablegoto [playerid]");

      if(Goto[playerid][giveplayerid] == true)
      {
           Goto[playerid][giveplayerid] = false;
           SendClientMessage(playerid, -1, "That player can now TP to you again.");
      }

      else {
            Goto[playerid][giveplayerid] = true;
            SendClientMessage(playerid, -1, "That player can no longer TP to you.");
      }

      return 1;
}
Reply
#8

Thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)