sscanf question.
#1

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?
Reply
#2

Код:
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...
  }
}
Reply
#3

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

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

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".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)