SA-MP Forums Archive
Loading Reports and deleting them - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loading Reports and deleting them (/showthread.php?tid=619878)



Loading Reports and deleting them - Marven - 23.10.2016

Hello there so i have made a report system it saves the reports so admins can check later on when they are online but i dont know how to open the stored reports and then later on how can i delete them?

here is the report cmd
Код:
CMD:report(playerid,params[])
{
    new Target,reason[50],rstring[128];
	if(IsJailedOrMuted(playerid))return 1;
    if(sscanf(params,"us[50]",Target,reason))return SendClientMessage(playerid,GREY,"USAGE: /report [playerid] [reason]");
	if(!IsPlayerConnectedEx(Target)) return SendClientMessage(playerid,GREY,"Invalid player ID");
	if(strlen(reason) > 50) return SendClientMessage(playerid,GREY,"Reason can't be longer than 50 characters");
	format(rstring,sizeof(rstring),"SERVER: {FFFFFF}%s reported %s(Reason: %s)",PlayerName(playerid),PlayerName(Target),reason);
	SendMessageToAdmins(RED,rstring);
	SendClientMessage(playerid,YELLOW,"Your report has been sucessfully sent to the online admins");
  	LogReport(rstring); //Log the string
    return 1;
}
here is the stock used to store report.

Код:
stock LogReport(event[])
{
	new File:log = fopen("report_log.txt", io_append);
	fwrite(log, event);
	fwrite(log, "/n");
	fclose(log);
}
Help would be appreciated.


Re: Loading Reports and deleting them - Micko123 - 23.10.2016

Does it makes report_log.txt file?


Re: Loading Reports and deleting them - Vince - 23.10.2016

Sequential files are really not suited for this kind of thing. You have no way to identify the line to remove other than some string comparison (slow). Also sequential files can only be read from and written to sequentially (hence their name). If a line is to be deleted the whole file needs to be rewritten. This process naturally becomes slower as the file grows larger.

Either create a separate folder and store the reports there - one per file - in ini format, or create a simple SQLite database.

And oh, the "newline" char is \n, not /n.


Re: Loading Reports and deleting them - Marven - 23.10.2016

@Micko yes it does create report file

@Vince oh alright any way i can make one report per file? not talking about SQlite just in ini format.


Re: Loading Reports and deleting them - Marven - 24.10.2016

Bump


Re: Loading Reports and deleting them - IceBilizard - 24.10.2016

PHP код:
CMD:report(playerid,params[])
{
    new 
Target,reason[50],rstring[128];
    if(
IsJailedOrMuted(playerid))return 1;
    if(
sscanf(params,"us[50]",Target,reason))return SendClientMessage(playerid,GREY,"USAGE: /report [playerid] [reason]");
    if(!
IsPlayerConnectedEx(Target)) return SendClientMessage(playerid,GREY,"Invalid player ID");
    if(
strlen(reason) > 50) return SendClientMessage(playerid,GREY,"Reason can't be longer than 50 characters");
    
format(rstring,sizeof(rstring),"SERVER: {FFFFFF}%s reported %s(Reason: %s)\r\n",PlayerName(playerid),PlayerName(Target),reason);
    
SendMessageToAdmins(RED,rstring);
    
SendClientMessage(playerid,YELLOW,"Your report has been sucessfully sent to the online admins");
      new 
Filefile fopen("report_log.txt"io_append);
    
fwrite(filerstring);
    
fclose(file);
    return 
1;
}
CMD:reports(playeridparams[])
{
    if (
adlvl[playerid] < 1) return 0;
    new 
string[256];
    new 
strings[128], Filefile fopen("report_log.txt"io_read), idxx=1;
    
SendClientMessage(playeridCOLOR_ORANGE"[Server Reports]:");
    while(
fread(filestrings))
    {
        
format(stringssizeof(strings), "%d) %s"idxxstrings);
        
SendClientMessage(playeridCOLOR_ORANGEstrings);
        
AddAdminCmdLog(playeridstring);
        
idxx ++;
    }
    
fclose(file);
    return 
1;