Help creating logs
#1

I need to make chat logs and command logs. Saving in two separate text files named chat and command.
Reply
#2

use this code to define:
pawn Код:
forward TextLog(text[]);
forward CommandLog(text[]);

public TextLog(text[])
{
    new File:fi_log;
    fi_log = fopen("TextLog.txt", io_append);
    new string[256], day, year, month, hour, minute, second;
    getdate(year, month, day); gettime(hour, minute, second);
    format(string, sizeof(string), "|[%d/%d/%d - %d:%d:%d]|%s|\r\n", day, month, year, hour, minute, second, text);
    fwrite(fi_log, string);
    fclose(fi_log);
    return 1;
}
public CommandLog(text[])
{
    new File:fi_log;
    fi_log = fopen("CommandLog.txt", io_append);
    new string[256], day, year, month, hour, minute, second;
    getdate(year, month, day); gettime(hour, minute, second);
    format(string, sizeof(string), "|[%d/%d/%d - %d:%d:%d]|%s|\r\n", day, month, year, hour, minute, second, text);
    fwrite(fi_log, string);
    fclose(fi_log);
    return 1;
}
Example to use to save text:
pawn Код:
public OnPlayerText(playerid, text[])
{
    new name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s: %s", name, text);
    TextLog(string);
    return 1;
}
EDIT:
and for commands:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s used %s", name, cmdtext);
    CommandLog(string);
    //commands.....
   return 0; //or return 1;
}
Reply
#3

thanks! now I got pretty much all the logs I need
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)