Originally Posted by Gangs_Rocks
The Gogger
Advanced log creating and saving
by Gangs a.k.a CreativityLacker
Functions:
pawn Код:
forward CreateLog(logname[]); forward WriteInLog(logname[], string[]);
Code
pawn Код:
/* The Gogger - Advanced log creating, writing and saving by Gangs a.k.a CreativityLacker Don't remove credits from here This is the BETA version Please report any bugs at the topc */
#include <file> #include <a_samp>
forward CreateLog(logname[]); forward WriteInLog(logname[], string[]);
public CreateLog(logname[]) { new date[3]; getdate(date[0], date[1], date[2]); new string[120]; format(string, sizeof(string), "Logs/%s.txt", logname); // Change this to the location you want your logs at new File:log = fopen(string, io_append); format(string, sizeof(string), "[%02d-%02d-%04d] Started logging in LOG '%s' ", date[2], date[1], date[0], logname); fwrite(log, string); fclose(log); format(string, sizeof(string), "\r\n[%02d-%02d-%04d] Started logging in LOG '%s'", date[2], date[1], date[0], logname); printf(string); return 1; }
public WriteInLog(logname[], string[]) { new location[120]; format(location, sizeof(location),"Logs/%s.txt", logname); // Change this to the location you want your logs at if(fexist(location)) { new File:log = fopen(location, io_append); fwrite(log, string); fclose(log); } else return printf("[LOG ERROR]A log wasn't found!"); return 1; }
Test script :
pawn Код:
#include <a_samp> #include <Gogger>
main() { print("\n----------------------------------"); print(" Testing Log creator"); print("----------------------------------\n"); } public OnGameModeInit() { // Don't use these lines if it's a filterscript SetGameModeText("Blank Script"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); CreateLog("TestLog"); return 1; } public OnPlayerConnect(playerid) { new name[24]; GetPlayerName(playerid, name, sizeof(name)); new string[40]; format(string, sizeof(string), "\r\n%s connected to the server", name); WriteInLog("TestLog", string); return 1; }
public OnPlayerDisconnect(playerid, reason) { new name[24]; GetPlayerName(playerid, name, sizeof(name)); new string[40]; format(string, sizeof(string), "\r\n%s disconnected from the server", name); WriteInLog("TestLog", string); printf(string); return 1; }
Output results after this code:
Console:
File (scriptfiles/Logs/TestLog.txt):
Please report any bugs, I'll try to fix 'em ASAP
|