sscanf help
#1

hi guys, i have problem with sscanf, i have this command:
PHP код:
CMD:setstats(playeridparams[]) {
    new 
idsta[126], string[256];
    if(
sscanf(params"us[126]"idsta)) {
        
SCM(playerid, -1"{07C1F5}/setstat {FFFFFF}[ID/name] [Type]");
        
SCM(playerid, -1"{07C1F5}Vrste: {FFFFFF} Level");
        return 
1;
    }
    if(
strcmp(sta,"Level"true) == 0) {
        new 
lvl;
        if(
sscanf(params"us[126]i"idstalvl)) return SCMF(playerid,-1,"{07C1F5}/setstat {FFFFFF}%d %s [Amount]",id,sta);
        
PI[id][Level] = lvl;
        
SetPlayerScore(idlvl);
    }
    else return 
SCM(playerid,GRAD2,"Unknow type!"); 
and when i type: /setstats its okay, and when i type setstats MYID Level, then set me lvl to 0, thats okay too but when i type /setstats MYID Level 15 then i get a message Unknow type!

i want to code be like that cuz in some cases i have more parameters like: /setstats MYID Skill Driving 5
Reply
#2

if(sscanf(params, "is[126]", id, sta))
Reply
#3

Still same problem, i accidentally delated "u" from code above, i have it in script
Reply
#4

level=strval(sta[5]);

Try this. Use this instead of the second sscanf. Also use isnull() and IsNumeric()

For MYID Skill Driving 5,
sscanf(params, "us[126]", id, sta)
Then, strcmp(sta, "MYID", true)
Then, format(sta2, "%s", sta[4]);
Then, strcmp(sta2, "skill", true)
Then, format(sta3, "%s", sta2[5]);
Then, strcmp(sta3, "driving", true)
Then, isnull(sta3[7]), IsNumeric(sta3[7]), and level=strval(sta[7]);
Reply
#5

TNX!
Reply
#6

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
level=strval(sta[5]);

Try this. Use this instead of the second sscanf. Also use isnull() and IsNumeric()

For MYID Skill Driving 5,
sscanf(params, "us[126]", id, sta)
Then, strcmp(sta, "MYID", true)
Then, format(sta2, "%s", sta[4]);
Then, strcmp(sta2, "skill", true)
Then, format(sta3, "%s", sta2[5]);
Then, strcmp(sta3, "driving", true)
Then, isnull(sta3[7]), IsNumeric(sta3[7]), and level=strval(sta[7]);
You don't understand sta[4] means do you ? sta[4] means 5th character of the string "sta", in case of
/setstats (id) Skill Driving 5
that means letter 'l' in the skill, you are assigning it to sta2, then asking for 6th character of sta2, which is absolutely nothing, assigning it to sta3


IF you don't know how to do it, there is no need to give some random vague answer, since I was confused af while reading your "help", let alone the poor guy looking for his answer.
I really wish this REP system would be removed, people do so much to get one !



OT:
You should re-sscanf the string sta, get the "stats" cmd wants to change in one string, rest to another, check what stat that is, see how many arguments it needs, then sscanf the "another" string to match your needs, sta you are creating is a 126 cell big, that means pretty much anything they type after /setstats id, if someone types /setstats 0 level something big here 5, this level something big here 5 gets saved in your sta string, which obviously doesn't match "level" you want to check

PS: there are better ways to do this, but it's midnight, this was the best I came up with, so don't shoot me plz :3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)