Multiple parameters, help needed.
#1

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
Reply
#2

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 (...
Reply
#3

thats only two.

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

/team setname [teamid] [name]
Reply
#4

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 ><
Reply
#5

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?

Reply
#6

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
Reply
#7

Without using sscanf....

I'm not a great fan of it.

Reply
#8

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
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)