05.06.2011, 03:48
I made a report system but I have been having problems with it. I got it to work but the command /reports suddenly stopped working for no reason at all, it returns Unknown command. It only works if I comment the sscanf line in the /reports command. I tried debugging and the strings seem fine, it must be a problem with sscanf and delimiters or something? Any ideas on the problem would be appreciated, I don't really have time to figure it out myself.
Vars/arrays..
Commands:
EDIT:
If I just comment the sscanf line, the dialog shows, so its in fact something to do with sscanf.
Vars/arrays..
pawn Код:
#define MAX_REPORTS 7 //8
#define MAX_REPORT_LEN 60
new Reports[MAX_REPORTS][MAX_REPORT_LEN+90],
ReportID;
Commands:
pawn Код:
CMD:report(playerid, params[])
{
new target, repstr[MAX_REPORT_LEN];
if(sscanf(params, "us["#MAX_REPORT_LEN"]", target, repstr)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /report <playerid/name> <reason>");
if(strlen(repstr) > MAX_REPORT_LEN) return SendClientMessage(playerid, COLOR_RED, "ERROR: Max reason length is "#MAX_REPORT_LEN" characters!");
new oldrep[MAX_REPORT_LEN];
GetPVarString(playerid, "ReportMsg", oldrep, MAX_REPORT_LEN);
if(strfind(oldrep, repstr, true) != -1) return SendClientMessage(playerid, COLOR_RED, "ERROR: Do not repeat reports, your first one should be read sooner or later.");
if(ReportID >= MAX_REPORTS) ReportID = 0;
else ReportID++;
new str[180];
format(str, sizeof(str), "Report: %s (ID %d) reported %s (ID %d) (Reason: %s)", pName(playerid), playerid, pName(target), target, repstr);
SendMessageToAdmins(COLOR_RED, str);
format(str, sizeof(str), "%s,%s,%s", pName(playerid), pName(target), repstr);
SetPVarString(playerid, "ReportMsg", str);
format(Reports[ReportID], 200, "%s", str);
return 1;
}
CMD:reports(playerid, params[])
{
new str[500];
new reporter[MAX_PLAYER_NAME], reportee[MAX_PLAYER_NAME], reason[MAX_REPORT_LEN];
format(str, sizeof(str), "{"#G>"}Reporter\t\t{"#B>"}Reportee\t\t{"#R>"}Reason\n\n");
for(new x=0; x<=MAX_REPORTS; x++)
{
if(sscanf(Reports[x], "p<,>s[24]s[24]s[60]", reporter, reportee, reason)) continue;
else format(str, sizeof(str), "%s{"#G>"}%s\t\t{"#B>"}%s\t\t{"#R>"}%s\n", str, reporter, reportee, reason);
}
if(strlen(str) < 60) format(str, sizeof(str), "{"#W>"}There are currently no reports.", reporter, reportee, reason);
ShowPlayerDialog(playerid, ADIAG-1, DIALOG_STYLE_MSGBOX, "{"#W>"}Recent Reports", str, "Exit", "");
return 1;
}
If I just comment the sscanf line, the dialog shows, so its in fact something to do with sscanf.
pawn Код:
CMD:reports(playerid, params[])
{
new str[500];
new reporter[MAX_PLAYER_NAME], reportee[MAX_PLAYER_NAME], reason[MAX_REPORT_LEN];
format(str, sizeof(str), "{"#G>"}Reporter\t\t{"#B>"}Reportee\t\t{"#R>"}Reason\n\n");
for(new x=0; x<=MAX_REPORTS; x++)
{
//if(sscanf(Reports[x], "p<,>s[24]s[24]s[60]", reporter, reportee, reason)) continue;
format(str, sizeof(str), "%s{"#G>"}%s\t\t{"#B>"}%s\t\t{"#R>"}%s\n", str, reporter, reportee, reason);
}
if(strlen(str) < 60) format(str, sizeof(str), "{"#W>"}There are currently no reports.", reporter, reportee, reason);
ShowPlayerDialog(playerid, ADIAG-1, DIALOG_STYLE_MSGBOX, "{"#W>"}Recent Reports", str, "Exit", "");
return 1;
}