zcmd + sscanf + strcmp + next param.
#1

So i made a command with zcmd.

In zcmd i`m using sscanf which checks string.
pawn Код:
if(sscanf(params, "s[20]", name))
after that command is checking if there is name/word - for example "putin"
pawn Код:
if(strcmp(name,"putin",true) == 0)
After that - in putin command i need another param, well made that with sscanf again.
pawn Код:
if(sscanf(params, "d", slot))
everything works perfect till i write in game a command.

/command putin 3 - but it wont work, after that it shows invalid fuction / unknown name which we done at first check with sscanf.

but writing
/command putin - with out param it succesuffly checks if there is parameter and shows message which needed.

so question is that, how to make param working.

full code how it ~ looks.
pawn Код:
COMMAND:command(playerid, params[])
{
      if(sscanf(params, "s[20]", name)) return // blablablalalala
      if(strcmp(name,"putin",true) == 0)
      {
              if(sscanf(params, "d", slot)) return // if there is no param written (IG) then it successfully messages it.
              // code after this wont work.
       }
       else // this is showing when player writes param for putin.
}
So what i need to do? with strtok or what?
Reply
#2

You could add a optional param, which only get's used if the previous param was "putin"

If you want me to show how, please explain what this does, and show the definition of 'slot' and 'name' ^^
Reply
#3

pawn Код:
new name[20], slot;
as you see name is a string, slot is a integirer (i/d)

Comand putin should store a value to another variable, that |"another"| variable stores value to a file.
It`s like GF command trunk putgun etc only with this difference so player can choose slot.
ofcourse there are many checks for example - if slot is in use etc stuff...
Reply
#4

Try this:

pawn Код:
COMMAND:command(playerid, params[])
{
      if(sscanf(params, "s[20]I(-1)", name, slot)) return // blablablalalala
      if(strcmp(name,"putin",true) == 0)
      {
              if(slot == -1)
                    return YourStuffHere //slot is '-1' , which means it isn't changed from the default value, which again means that player didn't put anything in the second param
              /* Do your stuff */
       }
       else // if 'putin' isn't the first param put
}
Reply
#5

Ahh but forgot to tell you, there are another strcmp checks which dont need a param.
As i said like /trunk command

/command info
/command takeout param
/command putin param
etc.

Edit: Okey thanks works fine.
Reply
#6

Blah i said there are commands which dont need param.
for these i need to enter any slot. ;s
Reply
#7

Quote:
Originally Posted by GaGlets®
Посмотреть сообщение
Ahh but forgot to tell you, there are another strcmp checks which dont need a param.
As i said like /trunk command

/command info
/command takeout param
/command putin param
etc.

Edit: Okey thanks works fine.
Quote:
Originally Posted by GaGlets®
Посмотреть сообщение
Blah i said there are commands which dont need param.
for these i need to enter any slot. ;s

I believe
Quote:
Originally Posted by GaGlets®
Посмотреть сообщение
Edit: Okey thanks works fine.
meant that it actually worked, and you don't need further help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)