02.09.2012, 04:40
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(playerid, 0, 0, 0);
SendClientMessage(playerid, -1, "You have teleported to LV location 1!");
}
case 2://if they type /goto lv 2
{
SetPlayerPos(playerid, 0, 0,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;
}