SA-MP Forums Archive
HOW TO DO a special printf? - 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: HOW TO DO a special printf? (/showthread.php?tid=77910)



HOW TO DO a special printf? - jwload - 15.05.2009

Hi scripters,

I need to create a function that executes the same function of the printf,
but that besides writing in console and server_log.txt also writes in a file in the scriptfiles...

I want register all in this file in the scriptfiles
format strings and substitute printf for print for each printf that I have in my gamemode will be very hard
with this function I would simply substitute the functions printf for this new function using a CTRL+H

Thanks for replys! :P




Re: HOW TO DO a special printf? - Backwardsman97 - 15.05.2009

Why did you make two topics...

Edit:It just got deleted.


Re: HOW TO DO a special printf? - jwload - 15.05.2009

sorry,
it was a mistake in my broswer



Re: HOW TO DO a special printf? - Backwardsman97 - 15.05.2009

So you want to store all your printf's into your scriptfiles folder?


Re: HOW TO DO a special printf? - jwload - 16.05.2009

Yes, basically I need a new printf that has an additional function: writing in a logfile in the scriptfiles...


Re: HOW TO DO a special printf? - yom - 16.05.2009

Soemthing like that (edit if needed..)
pawn Код:
new
  File:logfile,
  logstring[128]
;

#define logprint(%0); \
{\
  format(logstring,sizeof logstring,%0);\
  print(logstring);\
  logfile=fopen("logfile.log",io_append);\
  fwrite(logfile,logstring);\
  fwrite(logfile,"\r\n");\
  fclose(logfile);\
}
pawn Код:
logprint("%s = %d", "0rb", 1337);



Re: HOW TO DO a special printf? - Qeux - 16.05.2009

isn't there a server log for that


Re: HOW TO DO a special printf? - jwload - 16.05.2009

Thanks Orb!

I also found other way of doing that, based on SendFormatMessage by ******:

pawn Код:
#define lprintf(%1,%2) do{new sendfstring[128];format(sendfstring,128,(%1),%2);lprint(sendfstring);}while(FALSE)

stock lprint(const str[])
{
    print(str);
    new hour,minute,second;
    new str2[255],File:log=fopen("Log.txt",io_append);
    gettime(hour,minute,second);
    format(str2,sizeof(str2),"[%d:%d:%d] [PRINT] %s\r\n",hour,minute,second,str);
    fwrite(log,str2);
    fclose(log);
}
The effect is the same, but I don't know which is the best...

Anyway, thanks for reply.