zcmd - command log write to other file
#1

Dear,

I trying to make command log file , but the only thing i made is writing the command to server.log - its working but spamming the file which is useless for me.

I trying to make a file (dosent matter file name ) which all commands will be saved there, now i did all code into the ZCMD include and its looks like

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new playername[24];
    GetPlayerName(playerid, playername, 24);
    printf("[cmd] %s(%d): %s", playername, playerid, cmdtext);	
}
i need format are using fwrite, fopen etc..
Anyone can help me with making a format to new file instead of server.log ?
Reply
#2

Just do sth like this:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new string[128];
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    format(string,128,"%s (%d): %s",string,playerid,cmdtext);
    file_set_content("CMD_LOG.log",string);
}

stock file_set_content(const path[], string[]) {
    new File:f = fopen(path,io_append),h[6];
    gettime(h[0],h[1],h[2]),getdate(h[3],h[4],h[5]);
    format(string,128,"[%02d.%02d.%02d - %02d:%02d:%02d] %s\r\n",h[5],h[4],h[3],h[0],h[1],h[2],string);
    return fwrite(f,string),fclose(f);
}
Then it safes under /scriptfiles/CMD_LOG.log the cmd log
Reply
#3

Dear,

Thanks for helping but i tried what you say over here and its not writing on the file.
Reply
#4

Quote:
Originally Posted by Camorra
Посмотреть сообщение
Thanks for helping but i tried what you say over here and its not writing on the file.
Change this line:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
to this:

Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
Greekz
Reply
#5

Well, as i said i doing this formating on the zcmd include.
i testing a format i made by yours, will inform if its work

Код:
    new commands[MAX_STRING]="Logs/CMD_LOG.txt";
	new File:myfile=fopen(commands,io_write);
	new timestring[MAX_STRING];
	new hour,minu,seco,giorno,mese,anno;
	gettime(hour,minu,seco); getdate(anno,mese,giorno);
	format(timestring,sizeof(timestring),"[%d:%d:%d/%d-%d-%d]%s\n",hour,minu,seco,giorno,mese,anno,string);
	fwrite(myfile,timestring);
	fclose(myfile);
Reply
#6

Quote:
Originally Posted by Camorra
Посмотреть сообщение
Well, as i said i doing this formating on the zcmd include.
Dude..why you no just use my function

This would be so much easier...and are you sure..that the Logs folder exists?!

...just use my function and do this:

Код:
new string[128];
GetPlayerName(playerid, string, MAX_PLAYER_NAME);
format(string,128,"%s (%d): %s",string,playerid,cmdtext);
file_set_content("/Logs/CMD_LOG.log",string);
Greekz
Reply
#7

Alright, i made something with ur function.

At least its working and i got what i want, thank you very much
+rep
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)