SA-MP Forums Archive
Writing to log format - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Writing to log format (/showthread.php?tid=244343)



Writing to log format - Holnista - 26.03.2011

Hi.

I need to make log writing function.
I made this:

Код:
stock WriteToLog(log[], const input[], {Float,_}:...)
{
	new string[128];
	new File:Plik = fopen(log, io_append);
	format(string, sizeof(string), input, ...);
	fwrite(Plik, string);
	fclose(Plik);
}
But i have this error:
Quote:

error 029: invalid expression, assumed zero

On line:
Quote:

format(string, sizeof(string), input, ...);

Can someone help?


Re: Writing to log format - grand.Theft.Otto - 27.03.2011

Make a folder in your scriptfiles folder and name it something, like your server short form name for example, or Plik as I see it is the name in your code.

pawn Код:
// Top of your script

#define SAVE_LOGS

// Bottom of your script:

forward SaveToFile(filename[],text[]);
public SaveToFile(filename[],text[])
{
    #if defined SAVE_LOGS
    new File:Plik, filepath[256], string[256], year,month,day, hour,minute,second;
    getdate(year,month,day); gettime(hour,minute,second);

    format(filepath,sizeof(filepath),"ladmin/logs/%s.txt",filename);
    Plik = 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(Plik,string);
    fclose(Plik);
    #endif
    return 1;
}
Now, make a text file in scriptfiles/Plik with a .txt extension at the end, like KickLog.txt

Next, type SaveToFile("KickLog",string); under your kick command, as this is the example for now (You can change it up if you want)

Now when the next person gets kicked, it will save a log of it in scriptfiles/Plik/KickLog.txt


Re: Writing to log format - Holnista - 27.03.2011

Quote:

[256]

I suggests using 128. Its enaugh nad its 2x faster.

Quote:

forward SaveToFile(filename[],text[]);

This is not what i need. I need fucntion with formating string !
For example:
Код:
WriteToLog("Logs/test.txt", "%s (ID:%d) is now testing log.", PlayerName(playerid), playerid);
How to make this ?


Re: Writing to log format - Holnista - 27.03.2011

Can someone help ?


Re: Writing to log format - Holnista - 27.03.2011

Ok Ok ! I made this !

Код:
new FALSE = 0;
#define WriteToLog(%0,%1,%2) \
do \
{ \
	new tmp[128]; \
	format(tmp, 128, %1, %2); \
	new File:Plik = fopen(%0, io_append); \
	fwrite(Plik, tmp); \
	fclose(Plik); \
} \
while(FALSE)