SA-MP Forums Archive
sscanf question. - 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: sscanf question. (/showthread.php?tid=110684)



sscanf question. - Giacomand - 28.11.2009

Let's say I made a /spec <ID> command, but if I also wanted the player to do "/spec off", how would I do that in sscanf?


Re: sscanf question. - yezizhu - 28.11.2009

Код:
new
  tmpstr[32];
if(sscanf(x,"s",tmpstr)) return //bla...
if(IsNumeric(tmpstr)){
  new 
    id = strval(tmpstr);
  //bla,..
}else{
  if(!strcmp(tmpstr,"off",true){
    //bla...
  }
}



Re: sscanf question. - Giacomand - 28.11.2009

That's that I'm kinda doing now, but is that the only way?


Re: sscanf question. - yezizhu - 28.11.2009

Код:
new
  id;
if(sscanf(x,"u",id)){
  new
  str[32];
  if(sscanf(x,"s",str)) return //bla
  if(!strcmp//bla
}
//bla



Re: sscanf question. - Dabombber - 28.11.2009

Neither of those will work properly; the first will not work for parts of a player's name, and the second will not return true for "/spec off" (id will just be set to INVALID_PLAYER_ID).

pawn Код:
if(!isnull(params) && strcmp(params, "off", true) == 0) {
    //exit spec
    return 1;
}

new id;
if(sscanf(params, "u", id) || id == INVALID_PLAYER_ID) {
    // invalid player
    return 1;
}

// spec the player
You might want to consider just using just "/spec" to exit spectate mode, since someone might have the name "off".