SA-MP Forums Archive
zcmd - command log write to other file - 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: zcmd - command log write to other file (/showthread.php?tid=568087)



zcmd - command log write to other file - Camorra - 19.03.2015

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 ?


AW: zcmd - command log write to other file - Kaliber - 19.03.2015

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


Re: zcmd - command log write to other file - Camorra - 19.03.2015

Dear,

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


AW: Re: zcmd - command log write to other file - Kaliber - 19.03.2015

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


Re: zcmd - command log write to other file - Camorra - 19.03.2015

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);



AW: Re: zcmd - command log write to other file - Kaliber - 19.03.2015

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


Re: zcmd - command log write to other file - Camorra - 19.03.2015

Alright, i made something with ur function.

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