SA-MP Forums Archive
Multiple parameters, help needed. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Multiple parameters, help needed. (/showthread.php?tid=96400)



Multiple parameters, help needed. - Outbreak - 07.09.2009

I'm wanting to make a command with 3 parameters using dcmd

Its for a team script im making. /team has many options. one of the options has 2 params, one integer and one string.

The example below is one of the optinos i want to be able to use when i use /team
pawn Код:
else if(strcmp(params, "setname", true, 7))
   {
     new teamid = strval(params[8]);

     // now from here how would i add another param which will be used as a string to set the team name?
Hopefully someone experienced will be able to understand what im trying to do.

Thanks


Re: Multiple parameters, help needed. - Daren_Jacobson - 07.09.2009

pawn Код:
dcmd_team(playerid, params[])
{
new option[24], extra[64]
if (sscanf(params, "sz", option, extra)) SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /team [option] [params]");
else if (!strcmp(option, "setname", true))
{
 teamname = extra;
}
else if (...



Re: Multiple parameters, help needed. - Outbreak - 07.09.2009

thats only two.

im wanting have /team [option] [teamid] [string]

/team setname [teamid] [name]


Re: Multiple parameters, help needed. - [LL]InstabiC - 07.09.2009

pawn Код:
dcmd_team(playerid, params[])
{
new option[24],option2[24], extra[64]
if (sscanf(params, "sz", option,option2, extra)) SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /team [option] [option2] [params]");
else if (!strcmp(option, "setname", true))
{
 teamname = extra;
}
else if (...
idk, it should work ><


Re: Multiple parameters, help needed. - Outbreak - 07.09.2009

I've already wrote the whole command and other options without using sscanf, like the method above.

So how could I add an extra param the same way as I added the teamid one?




Re: Multiple parameters, help needed. - ilikepie2221 - 07.09.2009

pawn Код:
dcmd_yourcommand(playerid,params)
{
  new variablea, variableb, variablec;
  if(sscanf(params, "sss"/*or whatever */, variablea, variableb, variablec)) SendClientMessage(playerid, COLOR_WHITE, "Usage:whatever");
  if(strcmp(variablea, // insert here a string, true) == 0)
  {
     // code to compare variableb and variablec
  }
  if(strcmp(variablea, // insert here a string, true) == 0)
  {
    // code to compare variableb and variablec
  }
  return 1;
}
Untested


Re: Multiple parameters, help needed. - Outbreak - 07.09.2009

Without using sscanf....

I'm not a great fan of it.




Re: Multiple parameters, help needed. - Nero_3D - 07.09.2009

sscanf isnt bad but how you want

pawn Код:
else if(strcmp(params, "setname", true, 7))
   {
     //first of all we need to check if two params exists
     new idx = strfind(params, " ", true, 8);
     if(idx == -1 || params[idx + 1] == EOS)
       return SendClientMessage(playerid, 0xFFFFFFAA, "Right Usage: /team setname [teamid] [name]");
     params[idx] = EOS, idx++;
     new teamid = strval(params[8]);
     // now we got all what we need, example usage
     new string[128];
     format(string, sizeof string, "You typed /team setname %d %s", teamid, params[idx]);
     return SendClientMessage(playerid, 0xFFFFFFAA, string);
   }
Hope this works


Re: Multiple parameters, help needed. - Calgon - 08.09.2009

Quote:
Originally Posted by Outbreak
Without using sscanf....

I'm not a great fan of it.

Sscanf is a far better way, better for script optimization AFAIK too. You really should use it, over the current method you're using, you'll find it so much easier.