SA-MP Forums Archive
Multi-Parameter Commands! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multi-Parameter Commands! (/showthread.php?tid=576940)



Multi-Parameter Commands! - ironmen - 07.06.2015

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!!!!


Re: Multi-Parameter Commands! - Abagail - 07.06.2015

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.


Re: Multi-Parameter Commands! - ironmen - 07.06.2015

thanks a lot!!!!!!


Re: Multi-Parameter Commands! - ironmen - 07.06.2015

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


Re: Multi-Parameter Commands! - Abagail - 07.06.2015

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;
}



Re: Multi-Parameter Commands! - ironmen - 07.06.2015

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


Re: Multi-Parameter Commands! - Abagail - 07.06.2015

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;
}



Re: Multi-Parameter Commands! - ironmen - 08.06.2015

Thanks