SA-MP Forums Archive
How to make a command with an extra parameter? - 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: How to make a command with an extra parameter? (/showthread.php?tid=128742)



How to make a command with an extra parameter? - lRaged - 19.02.2010

See, this is where pawn gets hard (for me). I want to know how I would make a command where you can use the command 2 (or more) times but with 2 different parameters.

e.g.
"/handsup 1" will:

pawn Код:
ApplyAnimation(playerid,"ROB_BANK","SHP_HandsUp_Scr",4.1,1,1,1,1,0);
"/handsup 2" will:

pawn Код:
ApplyAnimation(playerid,"PED","handsup",4.1,1,1,1,1,0);
If anyone could quickly just write the code for me and I'll be set for everything.

Please and thank you, credits will go to you.


Re: How to make a command with an extra parameter? - J.W. - 19.02.2010

I guess it would be something like this

Код:
if(strcmp(cmd, "/handsup", true) == 0)
		SendPlayerText(playerid,"Use either [1] or [2].",0);
and then

Код:
if(strcmp(cmd, "/handsup 1", true) == 0)
		ApplyAnimation(playerid,"ROB_BANK","SHP_HandsUp_Scr",4.1,1,1,1,1,0);
Код:
if(strcmp(cmd, "/handsup 2", true) == 0)
		ApplyAnimation(playerid,"PED","handsup",4.1,1,1,1,1,0);
Not too sure





Re: How to make a command with an extra parameter? - Hiddos - 19.02.2010

Use it like this:

pawn Код:
if(strcmp(cmd,"/handsup",true) == 0)
{
  new tmp[128];
  tmp = strtok(cmdtext,idx);
  if(!strcmp("1",tmp,true))
  {
    ApplyAnimation(playerid,"ROB_BANK","SHP_HandsUp_Scr",4.1,1,1,1,1,0);
  }
  if(!strcmp("2",tmp,true))
  {
    ApplyAnimation(playerid,"PED","handsup",4.1,1,1,1,1,0);
  }
  else SendClientMessage(playerid,0xFFFFFFFF,"USAGE: /handsup [1-2]");
  return 1;
}
Unsure if it works, but my /style command is based on it.


Re: How to make a command with an extra parameter? - lRaged - 19.02.2010

Quote:
Originally Posted by nulop
Use it like this:

Unsure if it works, but my /style command is based on it.
Compiles alright and the "USAGE:" works, but when I type /handsup 1 or /handsup 2, it doesn't work.


Re: How to make a command with an extra parameter? - Correlli - 19.02.2010

The best way is zcmd + sscanf, there are many examples on the forum - search for them and you'll find them.


Re: How to make a command with an extra parameter? - lRaged - 19.02.2010

Quote:
Originally Posted by Don Correlli
The best way is zcmd + sscanf, there are many examples on the forum - search for them and you'll find them.
Well to be honest I'd rather become familiar with strtok etc. instead of using plugins. But could you figure out the problem for me please?


Re: How to make a command with an extra parameter? - Correlli - 19.02.2010

Plugins are much faster, believe me. But there's a PAWN sscanf if you don't want to use the plugin one.


Re: How to make a command with an extra parameter? - Nero_3D - 19.02.2010

Don was faster :S nvm read it again

Quote:
Originally Posted by lRaged
Quote:
Originally Posted by Don Correlli
The best way is zcmd + sscanf, there are many examples on the forum - search for them and you'll find them.
Well to be honest I'd rather become familiar with strtok etc. instead of using plugins. But could you figure out the problem for me please?
You could use sscanf 1.0, too (can be found in the wiki -> sscanf)
It was only put into a plugin because there it got extra functions and it is way faster

But if you dont want to use anything new for you use that crap - it's limited from 0 till 99
pawn Код:
if(strcmp("/handsup", cmdtext, true, 8) == 0 && (cmdtext[8] == EOS || cmdtext[8] == ' '))
    {
        if(cmdtext[8] == &#39; ' && '0' <= cmdtext[9] && cmdtext[9] <= '9')
            switch(((cmdtext[10] != EOS) ? (((cmdtext[9] - &#39;0') * 10) + (cmdtext[10] - '0')) : (cmdtext[9] - '0')))
            {
                case 1: return ApplyAnimation(playerid, "ROB_BANK", "SHP_HandsUp_Scr", 4.1, 0, 0, 0, 1, 1);
                case 2: return ApplyAnimation(playerid, "PED", "handsup", 4.1, 0, 0, 0, 1, 1);
            }
        return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /handsup [1-2]");
    }



Re: How to make a command with an extra parameter? - adsy - 19.02.2010

Placeholder for code

i will post dcmd and strtok code here when i get home


Re: How to make a command with an extra parameter? - Joe Staff - 19.02.2010

pawn Код:
if(!strcmp(cmdtext[1],"handsup",true,7))
{
  switch(strval(cmdtext[9])
  {
    case 1: ApplyAnimation(playerid, "ROB_BANK", "SHP_HandsUp_Scr", 4.1, 0, 0, 0, 1, 1);
    case 2: ApplyAnimation(playerid, "PED", "handsup", 4.1, 0, 0, 0, 1, 1);
    default: SendClientMessage(playerid,0xFF0000FF,"USAGE: /handsup 1 or 2");
  }
  return 1;
}