20.02.2013, 16:57
Check sscanf's release thread if you're still confused. I don't know how else to explain this...
* Read the comments, they'll help!
pawn Код:
CMD:note(playerid, params[])
{
new
option[7], // this doesn't need to be 128 characters, "create" and "remove" are only 6 characters long!!
str[256]
;
if(sscanf(params,"s[7]",option))
return SyntaxMSG(playerid, "/note [show/create/remove/give]");
if(!strcmp(option, "show", true))
{
SCM(playerid, COLOR_YELLOWG, "|____________Notes____________|");
format(str, sizeof(str), "Note 1: {94EDED}%s{FFFFFF}.", PlayerInfo[playerid][pNote1]);
SCM(playerid, -1, str);
format(str, sizeof(str), "Note 2: {94EDED}%s{FFFFFF}.", PlayerInfo[playerid][pNote2]);
SCM(playerid, -1, str);
format(str, sizeof(str), "Note 3: {94EDED}%s{FFFFFF}.", PlayerInfo[playerid][pNote3]);
SCM(playerid, -1, str);
SCM(playerid, COLOR_YELLOWG, "|_____________________________|");
format(str, sizeof(str), "* %s takes out a few paper notes and looks through them.", GetNameWithMask(playerid));
ProxDetector(30.0, playerid, str, COLOR_PURPLE);
}
// if(!strcmp(option, "create", true)) // WRONG, use else if
if(!strcmp(option, "create", true))
{
/*if(sscanf(params,"s[256]",text))
return SyntaxMSG(playerid, "/note create [text]");*/
// ^^ Bad. This is the proper way. Remember, set your sting sizes to WHAT YOU NEED, not just random numbers.
new
szText[129] // the note text can only be 128 chars long
;
if(sscanf(params, "{s[7]}s[129]", szText)) // We use {s[7]} because sscanf reads params again, if we don't account for the "option", then it won't work. The {s[7]} says; "Hey, there's a specifer here, but we don't need to save it!"
return SyntaxMSG(playerid, "/note create [text]");
// finish the code
}
else if(!strcmp(option, "remove", true))
{
new
iNoteID
;
if(sscanf(params, "{s[7]}d", iNoteID))
return SyntaxMSG(playerid, "/note remove [note id]");
// finish the code, use iNoteID as the note's ID
}
return 1;
}