Trying to write /reports to file
#1

Listed as a command:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(parch, 5, cmdtext);
	dcmd(jetpack, 7, cmdtext);
	dcmd(report, 6, cmdtext);
	dcmd(randomcolor, 11, cmdtext);
	dcmd(stats, 5, cmdtext);
	dcmd(commands, 8, cmdtext);
	return 1;
}
Command:
Код:
dcmd_report(playerid, params[])
{

	new tmp[256], idx;
	tmp = strtok(params, idx);
	if(!strlen(tmp)){
	    SendClientMessage(playerid, 0x555252AA, "/report [id] [reason]");
	    return 1;
	}else{
	    new pid = strval(tmp);
		tmp = strrest(params, idx);
		if(!IsPlayerConnected(pid)){
		    SendClientMessage(playerid, 0x555252AA, "Invalid Player");
		    return 1;
		}else{
		    if(!strlen(tmp)){
		        SendClientMessage(playerid, 0x555252AA, "/report [id] [reason]");
		        return 1;
			}else{
			    new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[200];
			    GetPlayerName(playerid, name, sizeof(name));
			    GetPlayerName(pid, name2, sizeof(name2));
			    format(string, sizeof(string), "*%s(%d) reported %s(%d) for '%s'", name, playerid, name2, pid, tmp);
				for(new i=0; i<GetMaxPlayers(); i++){
				    if(IsPlayerConnected(i)){
				        if(IsPlayerAdmin(i)){
				            SendClientMessage(i, 0x555252AA, string);
						}
					}
				}
			}
		}
	}
	return 1;
}
And at the bottom of script:
Код:
stock WriteReportsLog(string[])
{

    if(!fexist("Reports.log")) dini_Create("Reports.log"); // You need to change dini_Create to your file creating system. new

        entry[255], File: hFile;

    format(entry, sizeof(entry), "%s\r\n", string); hFile = fopen("Reports.log", io_append); fwrite(hFile, entry); fclose(hFile);

}
If I delete the stock WriteReportsLog(string[]) then it will say the player has been reported but when i check there is no file for reports.

if I keep that code then when I /report id reason nothing happens.
Reply
#2

pawn Код:
public SaveToFile(filename[],text[]){
    #if defined SAVE_LOGS
    new File:File filepath[128], string[128], year,month,day, hour,minute,second;
    getdate(year,month,day); gettime(hour,minute,second);
    format(filepath,sizeof(filepath),"Thepath/%s.txt",filename);
    File = fopen(filepath,io_append);
    format(string,sizeof(string),"[%d.%d.%d %d:%d:%d] %s\r\n",day,month,year,hour,minute,second,text);
    fwrite(File,string);
    fclose(File);
    #endif
    return 1;}
then under the last SendClientMessage use this
PHP код:
SaveToFile("Reports",string); 
Reply
#3

Quote:
Originally Posted by KillerStrike23
Посмотреть сообщение
pawn Код:
public SaveToFile(filename[],text[]){
    #if defined SAVE_LOGS
    new File:File filepath[128], string[128], year,month,day, hour,minute,second;
    getdate(year,month,day); gettime(hour,minute,second);
    format(filepath,sizeof(filepath),"Thepath/%s.txt",filename);
    File = fopen(filepath,io_append);
    format(string,sizeof(string),"[%d.%d.%d %d:%d:%d] %s\r\n",day,month,year,hour,minute,second,text);
    fwrite(File,string);
    fclose(File);
    #endif
    return 1;}
then under the last SendClientMessage use this
PHP код:
SaveToFile("Reports",string); 
When you say to put that under the last sendclientmessage do you mean in dcmd_report?
Compiled:
warning 235: public function lacks forward declaration (symbol "SaveToFile")
Line 165 which is:
Код:
public SaveToFile(filename[],text[]){
EDIT:
Nevermind. Just needed to add
forward SaveToFile(filename[],text[]);
Reply
#4

Still nothin.
Reply
#5

remove this line #if defined SAVE_LOGS also remove #endif
Reply
#6

Quote:
Originally Posted by awsomedude
Посмотреть сообщение
remove this line #if defined SAVE_LOGS also remove #endif
On line 167:
error 001: expected token: ";", but found "-identifier-"
error 017: undefined symbol "filepath"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
fatal error 107: too many error messages on one line

Line 167:
Код:
 new File:File filepath[128], string[128], year,month,day, hour,minute,second;
Heres the whole thing with your changes:

Код:
public SaveToFile(filename[],text[]){
    new File:File filepath[128], string[128], year,month,day, hour,minute,second;
    getdate(year,month,day); gettime(hour,minute,second);
    format(filepath,sizeof(filepath),"Thepath/%s.txt",filename);
    File = fopen(filepath,io_append);
    format(string,sizeof(string),"[%d.%d.%d %d:%d:%d] %s\r\n",day,month,year,hour,minute,second,text);
    fwrite(File,string);
    fclose(File);
    return 1;}
Reply
#7

Quote:
Originally Posted by awsomedude
Посмотреть сообщение
remove this line #if defined SAVE_LOGS also remove #endif
I put those things back and put
Код:
#define filepath "Reports/%s.ini"
at the top and got no errors.
Still doesnt write. And it will only let me report if Im rcon admin(which it doesnt write) which I want anyone to be able to report.
Reply
#8

dude I will kill you ! Isplayeradmin! whats this! here is mine edit it
this one somewhere in your gm
pawn Код:
new Reports[MAX_REPORTS][128];
and this one is like anti spam

pawn Код:
#define MAX_REPORTS 7
pawn Код:
dcmd_report(playerid, params[]) {
    new reported, tmp[128], tmp2[128], Index;       tmp = strtok(params,Index), tmp2 = strtok(params,Index);
    if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /report [playerid] [reason]");
    reported = strval(tmp);
    if(IsPlayerConnected(reported) && reported != INVALID_PLAYER_ID) {
        if(PlayerInfo[reported][Level] == ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,red,"ERROR: You cannot report this administrator");
        if(playerid == reported) return SendClientMessage(playerid,red,"ERROR: You Cannot report yourself");
        if(strlen(params) > 7) {
            new reportedname[MAX_PLAYER_NAME], reporter[MAX_PLAYER_NAME], str[128], hour,minute,second; gettime(hour,minute,second);
            GetPlayerName(reported, reportedname, sizeof(reportedname));    GetPlayerName(playerid, reporter, sizeof(reporter));
            format(str, sizeof(str), "||NewReport||  %s(%d) reported %s(%d) Reason: %s |@%d:%d:%d|", reporter,playerid, reportedname, reported, params[strlen(tmp)+1], hour,minute,second);
            MessageToAdmins(COLOR_WHITE,str);
            SaveToFile("ReportLog",str);
            format(str, sizeof(str), "Report(%d:%d:%d): %s(%d) reported %s(%d) Reason: %s", hour,minute,second, reporter,playerid, reportedname, reported, params[strlen(tmp)+1]);
            for(new i = 1; i < MAX_REPORTS-1; i++) Reports[i] = Reports[i+1];
            Reports[MAX_REPORTS-1] = str;
            return SendClientMessage(playerid,yellow, "Your report has been sent to online administrators.");
        } else return SendClientMessage(playerid,red,"ERROR: Must be a valid reason");
    } else return SendClientMessage(playerid, red, "Player is not connected");}
you will something called Level change it to your admin system ! and there is something called message to admins here its is define it
pawn Код:
forward MessageToAdmins(color,const string[]);
public MessageToAdmins(color,const string[]){
    for(new i = 0; i < MAX_PLAYERS; i++){
        if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 1) SendClientMessage(i, color, string);}
    return 1;}
if I help +rep
Reply
#9

Quote:
Originally Posted by KillerStrike23
Посмотреть сообщение
if I help +rep
All on Line 78:
error 017: undefined symbol "PlayerInfo"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line

Line 78:
Код:
 if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 1) SendClientMessage(i, color, string);}
Whole array:
Код:
public MessageToAdmins(color,const string[]){
    for(new i = 0; i < MAX_PLAYERS; i++){
        if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 1) SendClientMessage(i, color, string);}
    return 1;}
Reply
#10

I changed back to:
Код:
dcmd_report(playerid, params[])
{
    #pragma unused params
	new tmp[256], idx;
	tmp = strtok(params, idx);
	if(!strlen(tmp)){
	    SendClientMessage(playerid, 0x555252AA, "/report [id] [reason]");
	    return 1;
	}else{
	    new pid = strval(tmp);
		tmp = strrest(params, idx);
		if(!IsPlayerConnected(pid)){
		    SendClientMessage(playerid, 0xFF0000AA, "Invalid Player");
		    return 1;
		}else{
		    if(!strlen(tmp)){
		        SendClientMessage(playerid, 0xFFFFFFAA, "/report [id] [reason]");
		        return 1;
			}else{
			    new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[200];
			    GetPlayerName(playerid, name, sizeof(name));
			    GetPlayerName(pid, name2, sizeof(name2));
			    format(string, sizeof(string), "*%s(%d) reported %s(%d) for '%s'", name, playerid, name2, pid, tmp);
				for(new i=0; i<GetMaxPlayers(); i++){
				    if(IsPlayerConnected(i)){
						{
				            SendClientMessage(i, 0x00FF00C8, string);
				            SaveToFile("Reports",string);
						}
					}
				}
			}
		}
	}
	return 1;
}

public SaveToFile(filename[],text[]){
    #if defined SAVE_LOGS
    new File:File filepath[128], string[128], year,month,day, hour,minute,second;
    getdate(year,month,day); gettime(hour,minute,second);
    format(filepath,sizeof(filepath),"Reports/%s.ini",filename);
    File = fopen(filepath,io_append);
    format(string,sizeof(string),"[%d.%d.%d %d:%d:%d] %s\r\n",day,month,year,hour,minute,second,text);
    fwrite(File,string);
    fclose(File);
    #endif
    return 1;}
Код:
stock WriteReportsLog(string[])
{

    if(!fexist("Reports.ini")) dini_Create("Reports.ini"); // You need to change dini_Create to your file creating system. new

        entry[255], File: hFile;

    format(entry, sizeof(entry), "%s\r\n", string); hFile = fopen("Reports.ini", io_append); fwrite(hFile, entry); fclose(hFile);

}
Can anyone figure out why it wont write to a file?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)