sscanf help -
Dusan01 - 23.10.2015
hi guys, i have problem with sscanf, i have this command:
PHP код:
CMD:setstats(playerid, params[]) {
new id, sta[126], string[256];
if(sscanf(params, "us[126]", id, sta)) {
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", id, sta, lvl)) return SCMF(playerid,-1,"{07C1F5}/setstat {FFFFFF}%d %s [Amount]",id,sta);
PI[id][Level] = lvl;
SetPlayerScore(id, lvl);
}
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
Re: sscanf help -
ATGOggy - 23.10.2015
if(sscanf(params, "is[126]", id, sta))
Re: sscanf help -
Dusan01 - 23.10.2015
Still same problem, i accidentally delated "u" from code above, i have it in script
Re: sscanf help -
ATGOggy - 23.10.2015
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]);
Re: sscanf help -
Dusan01 - 23.10.2015
TNX!
Re: sscanf help -
PrO.GameR - 23.10.2015
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