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

That is a stupid way of doing it, unnecessary shit. Why the hell is the integer made a string and then converted to an integer? Why the fuck wouldn't you just make an integer?

Plus, even if you did it this way, the size of the string is massive compared to what is needed (what is needed is 4 at maximum, you aren't going to have 999+ teleports).

This isn't a tutorial btw, so please hop back over the borders and go back to your own country.
Reply
#3

Quote:
Originally Posted by Kindred
Посмотреть сообщение
That is a stupid way of doing it, unnecessary shit. Why the hell is the integer made a string and then converted to an integer? Why the fuck wouldn't you just make an integer?

Plus, even if you did it this way, the size of the string is massive compared to what is needed (what is needed is 4 at maximum, you aren't going to have 999+ teleports).

This isn't a tutorial btw, so please hop back over the borders and go back to your own country.
I am not going to spend hours writing a tutorial if that's what you enjoy doing in your free time then you are a fucking looser. This was a quick and simple example and it explained it well enough to understand it, did you even read the comments in the code? I wrote the command in the web browser as a simple example, and if you need more then that to understand it then I don't really care figure it out some other way.
Reply
#4

Quote:
Originally Posted by new121
Посмотреть сообщение
I am not going to spend four hours writing a tutorial on every wich way you can do something. This was a quick and simple tutorial if you don't understand it then get the fuck out. Now fuck off back to troll land kid.
Who the fuck are you? Random insults. I am simply stating there is a much easier and better method, of which I explained above, and you go ape shit on me. And, as you said, "simple tutorial", this is more like a piece of goat shit.
Reply
#5

Quote:
Originally Posted by Kindred
Посмотреть сообщение
Who the fuck are you? Random insults. I am simply stating there is a much easier and better method, of which I explained above, and you go ape shit on me. And, as you said, "simple tutorial", this is more like a piece of goat shit.
Random insults? You called me a border hopper now get the fuck out of my thread, cunt.
Reply
#6

ok. how to make like... /stats = it will show your stats. /stats [id] = it will show other player's stats
Reply
#7

You don't really need to use sscanf for that.


PHP код:
CMD:stats(playeridparams[])
{    
    if(
isnull(params))//this is whats called if they just type /stats
    
{
         
//show the player his own stats
    
}
    else
//else this is called
    
{
        new 
playa strval(params);
        if(
playa != INVALID_PLAYER_ID)//checks that the commands paramater is a valid player id.
        
{
             if(
IsPlayerConnected(playa))// checks that someone is connected with that id
             
{
                  
//show playerid playas stats
             
}
        }
    }
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)