Loading reports
#1

Hello, I have made this reporting system, where players can report other players and the reports save in a file, I was woudering how I could open the file into a dialog so all the reports are in a dialog. But I don't want the dialog to get filled up, so how would i delete the reports after finishing with them,
Example;

/reports

Dialog shows up:

Код:
[date][time]LeXuZ has reported Player for hacking

"Open" "Close"
when they click on the report

Код:
[date][time]LeXuZ has reported player for hacking

"Ban" "Delete"
If you know how and what i mean please can you help me out here, I really need this command to work.

Codes:

pawn Код:
CMD:report(playerid, params[])
{
    new reason[128];
    if(sscanf(params, "us[128]", ID, reason)) return SCM(playerid, red, "--- /report <ID> <Reason> ---");
    new string[150], sender[MAX_PLAYER_NAME], receiver[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sender, sizeof(sender));
    GetPlayerName(ID, receiver, sizeof(receiver));
    format(string, sizeof(string), "%s(%d) has reported %s(%d) for %s", sender, playerid, receiver, ID, reason);
    SendReportToAdmins(string);
    ReportLog(playerid, string);
    return 1;
}

pawn Код:
stock ReportLog(playerid, text[])
{
    new
     File:lFile = fopen("Core/Logs/Report.txt", io_append),
     logData[178],
        fyear, fmonth, fday,
        fhour, fminute, fsecond;

    getdate(fyear, fmonth, fday);
    gettime(fhour, fminute, fsecond);

    format(logData, sizeof(logData),"[%02d/%02d/%04d %02d:%02d:%02d] (report) %s \r\n", fday, fmonth, fyear, fhour, fminute, fsecond, text);
    fwrite(lFile, logData);

    fclose(lFile);
    SCM(playerid, red, "Reported!");
    return 1;
}
pawn Код:
ACMD:reports(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 1) return 0;
    ShowPlayerDialog(playerid, reports, DIALOG_STYLE_LIST, "Reports", "", "Select", "Close");//don't know what to do in here
    return 1;
}
Thank you if you're able to help! + rep for anyone who helps me out!
Reply
#2

Do same what you did with SendClientMessage, but instead of sending each report in each line(SendClientMessage)
Add to the end of the string \n to break the line.
(Assuming you send each report line separately)
Then when you finish with it, show it to the player using the dialog function and instead of the dialog content "" type the array that contains the report data
Reply
#3

Yeah, I don't really know how to do that, I am not the best scripter, still learning, I don't know how i would start off writing up the code :S
Reply
#4

well, use fread:
pawn Код:
ACMD:reports(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 1) return 0;
    new File:filex = fopen("Core/Logs/Report.txt", io_read) // Opens the reports file
    new buf[129]; // the string variable which we are gonna return the loaded string in.
    new str[129]; // we are gonna use this later..
    if(filex) // if the file exists
    {
          print("Reports file loaded successfully."); // for debugging.
          while(fread(filex, buf)) // a "while" loop for reading ALL the file and store it in the "buf"
          {
              format(str, sizeof str, "%s\n", buf); // formating the buf in the str, and put "\n" to start a new line if needed.
             
              ShowPlayerDialog(playerid, reports, DIALOG_STYLE_LIST, "Reports", str, "Select", "Close"); // putting the str
          }
    }
    return 1;
}
not sure if works, i don't work with files much : p
P.S : why using outdated file functions? There's Y_INI, faster and easier.
Reply
#5

A little correction to Sawalha's code it has some errors -
pawn Код:
ACMD:reports(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 1) return 0;
    new File:filex = fopen("Core/Logs/Report.txt", io_read) // Opens the reports file
    new buf[80]; // the string variable which we are gonna return the loaded string in.
    new str[500]; // we are gonna use this later..
    bool firstline = true;
    if(filex) // if the file exists
    {
          print("Reports file loaded successfully."); // for debugging.
          while(fread(filex, buf)) // a "while" loop for reading ALL the file and store it in the "buf"
          {   if(firstline)strcat(str,buf);//if it is first line then we will not add new line character( '\n' )
               else { strcat(str, "\n"); strcat(str, buf); }
               firstline = false;
         }
ShowPlayerDialog(playerid, reports, DIALOG_STYLE_LIST, "Reports", str, "Select", "Close"); // Swahala putted it inside while it should be outside
    }
    return 1;
}
Reply
#6

pawn Код:
ACMD:reports(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 1) return 0;
    new File:filex = fopen("Core/Logs/Report.txt", io_read); // Opens the reports file
    new buf[80]; // the string variable which we are gonna return the loaded string in.
    new str[500]; // we are gonna use this later..
    bool firstline = true; //error
    if(filex) // if the file exists
    {
          print("Reports file loaded successfully."); // for debugging.
          while(fread(filex, buf)) // a "while" loop for reading ALL the file and store it in the "buf" Error
          {
          if(firstline)strcat(str,buf);//if it is first line then we will not add new line character( '\n' )//error
               else
               {
               strcat(str, "\n"); strcat(str, buf); }
               firstline = false;
               }
               SPD(playerid, reports, DIALOG_STYLE_LIST, "Reports", str, "Select", "Close"); // Swahala putted it inside while it should be outside
    }
    return 1;
}
}
Код:
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(808) : error 017: undefined symbol "bool"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(808) : error 017: undefined symbol "firstline"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(808) : warning 215: expression has no effect
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(813) : error 017: undefined symbol "firstline"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(815) : warning 217: loose indentation
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(815) : error 017: undefined symbol "firstline"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(815) : warning 215: expression has no effect
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts0.6.pwn(817) : warning 217: loose indentation
Getting these warnings, don't know how to fix Bool
Reply
#7

just add "new" ,
pawn Код:
new bool:firstline;
Reply
#8

pawn Код:
ACMD:reports(playerid, params[])
{
    new bool;
    new bool:firstline;
    if (pInfo[playerid][Adminlevel] < 1) return 0;
    new File:filex = fopen("Core/Logs/Report.txt", io_read); // Opens the reports file
    new buf[80]; // the string variable which we are gonna return the loaded string in.
    new str[500]; // we are gonna use this later..
    bool firstline = true; //error
    if(filex) // if the file exists
    {
          print("Reports file loaded successfully."); // for debugging.
          while(fread(filex, buf)) // a "while" loop for reading ALL the file and store it in the "buf" Error
          {
          if(firstline)strcat(str,buf);//if it is first line then we will not add new line character( '\n' )//error
               else
               {
               strcat(str, "\n"); strcat(str, buf); }
               firstline = false;
               }
               SPD(playerid, reports, DIALOG_STYLE_LIST, "Reports", str, "Select", "Close"); // Swahala putted it inside while it should be outside
    }
    return 1;
}
Quote:

C:\Users\BLACK\Desktop\Test\filterscripts\Accounts 0.6.pwn(810) : warning 215: expression has no effect
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts 0.6.pwn(810) : error 001: expected token: ";", but found "-identifier-"

Thanks for helping me out by the way!
Reply
#9

where's the error line?
Reply
#10

bool firstline = true; //error
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)