[Tutorial] Optional params with sscanf and ZCMD
#1

I noticed there are lots of tutorials on basic sscanf but haven't seen anything that explained this.I am going to assume you already have sscanf and zcmd included in your script. When making your sscanf line if you want the param to be optional simply use "S()[32]", you use () to declare the string is empty, and 32 for the size of the string.The captial S is what flags it as optional. Pretty bad at explaining stuff but here is an example on how to use it.

PHP код:
CMD:goto(playerid,params[])
{
     new 
result[32],optparam[32];
     if(
sscanf(params,"s[32]S()[32]",result,optparam)) return SendClientMessage(playerid,-1,"/goto [place lv or ls]");
     if(
strcmp(result,"lv",true) == 0)// if they player typed /goto lv
     

          if(
isnull(optparam))//this will be called
          
{
              
SendClientMessage(playerid,-1,"/goto lv [location]");
              
SendClientMessage(playerid,-1,"You can choose teleport location 1 or 2");
              return 
1;//stops the code from continuing.
          

          switch(
strval(optparam))//switch statements are much faster then if/else if statements.
          
{
                case 
1://if they type /goto lv 1
                
{
                       
SetPlayerPos(playerid000);
                       
SendClientMessage(playerid, -1"You have teleported to LV location 1!");
                }
                case 
2://if they type /goto lv 2
                
{
                       
SetPlayerPos(playerid00,0);
                       
SendClientMessage(playerid, -1"You have teleported to LV location 2!");
                }
                default: { 
SendClientMessage(playerid,-1,"Invalid location number"); }// if the number is anythign becides 1 or 2
          
}
      }
      return 
1;

Reply


Messages In This Thread
Optional params with sscanf and ZCMD - by new121 - 02.09.2012, 04:40
Re: Optional params with sscanf and ZCMD - by Kindred - 02.09.2012, 05:35
Re: Optional params with sscanf and ZCMD - by new121 - 02.09.2012, 05:46
Re: Optional params with sscanf and ZCMD - by Kindred - 02.09.2012, 05:51
Re: Optional params with sscanf and ZCMD - by new121 - 02.09.2012, 05:59
Re: Optional params with sscanf and ZCMD - by newbienoob - 02.09.2012, 06:03
Re: Optional params with sscanf and ZCMD - by new121 - 02.09.2012, 06:16

Forum Jump:


Users browsing this thread: 1 Guest(s)