Advertisement
Pedro_Miranda

[PAWN] - Sistema de Logs {pLogs} (Include)

Apr 6th, 2012
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.97 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. /*
  4. native newLog(filename[]);
  5. native writeLog(filename[], text[]);
  6. native deleteLog(filename[]);
  7. native printLog(filename[]);
  8. native readLog(playerid, color, filename[]);
  9. */
  10.  
  11. stock newLog ( filename [ ] ) {
  12.     if ( fexist ( filename ) )
  13.         return printf ( "[ERRO]: O arquivo %s já existe." , filename );
  14.        
  15.     return fclose ( fopen ( filename , io_write ) );
  16. }
  17.  
  18. stock writeLog ( filename [ ] , text [ ] ) {
  19.     new
  20.         str [ 128 ],
  21.         day,
  22.         month,
  23.         year,
  24.         hour,
  25.         minute,
  26.         second,
  27.         File: fileLog;
  28.        
  29.     if ( !fexist ( filename ) ) {
  30.         newLog ( filename );
  31.     }
  32.        
  33.     gettime ( hour , minute , second );
  34.     getdate ( year , month , day );
  35.    
  36.     fileLog = fopen ( filename , io_append );
  37.     format ( str , sizeof ( str ) , "[%02i/%02i/%04i - %02i:%02i:%02i]: %s\r\n" , day , month , year , hour , minute , second , text );
  38.     fwrite ( fileLog , str );
  39.     fclose ( fileLog );
  40.     return 1;
  41. }
  42.  
  43. stock deleteLog ( filename [ ] ) {
  44.     if ( !fexist ( filename ) )
  45.         return printf ( "[ERRO]: O arquivo %s não existe." , filename );
  46.        
  47.     return fremove ( filename );
  48. }
  49.  
  50. stock printLog ( filename [ ] ) {
  51.     new
  52.         readString [ 128 ],
  53.         File: logFile;
  54.  
  55.     if ( !fexist ( filename ) )
  56.         return printf ( "[ERRO]: O arquivo %s não existe." , filename );
  57.        
  58.     logFile = fopen ( filename , io_read );
  59.     while ( fread ( logFile , readString ) ) {
  60.         printf ("\n[%s]: %s\n" , filename , readString );
  61.     }
  62.     return 1;
  63. }
  64.  
  65. stock readLog ( playerid , color , filename [ ] ) {
  66.     new
  67.         str [ 128 ],
  68.         readString [ 128 ],
  69.         File: logFile;
  70.  
  71.     if ( !fexist ( filename ) )
  72.         return format ( str , 70 , "[ERRO]: O arquivo %s não existe." , filename ) , SendClientMessage ( playerid , color , str );
  73.  
  74.     logFile = fopen ( filename , io_read );
  75.     while ( fread ( logFile , readString ) ) {
  76.         format ( str , sizeof str , "[%s]: %s" , filename , readString );
  77.         SendClientMessage ( playerid , color , str );
  78.     }
  79.     return 1;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement