Problems with creating a chatlog.
#1

Everytime i go in-game and try to send any message, the message is not sent and my server crashes.

Here's the lines:

pawn Код:
public OnPlayerText(playerid, text[])
{
new File:fi_log;
fi_log = fopen("scriptfiles/Admin/Logs/Chatlog.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);
[/pawn]


pawn Код:
public Chatlog(text[])
{
    new File:fi_log;
    fi_log = fopen("scriptfiles/Admin/Logs/Chatlog.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;
}
Reply
#2

Try changing "scriptfiles/Admin/Logs/Chatlog.txt" to "/Admin/Logs/Chatlog.txt" and see if that was the problem (it is already default to open from the scriptfiles folder).
Reply
#3

make sure all directory are created and valid.
Remove "scriptfiles" from the path.
Reply
#4

It worked, but i tried writting down a kicklog like this:

pawn Код:
CMD:kick(playerid, params[])
{
    new pID, atext[256], cstring[256], aname[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
    if(sscanf(params, "us[256]", pID, atext)) return SendClientMessage(playerid, 0xFF0000AA, "[USAGE] /kick <playerid> <reason>");
    if(pInfo[playerid][Level] < 3) return 0;
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, 0xFF0000AA, "[ERROR] User is not connected.");
    else
    {

        GetPlayerName(playerid, aname, sizeof(aname));
        GetPlayerName(pID, pname, sizeof(pname));
        format(cstring, sizeof(cstring), "[ADMIN] %s has kicked %s from the server for %s", aname, pname, atext);
        SendClientMessageToAll(0xFF0000AA, cstring);
        format(cstring, sizeof(cstring), "You've been kicked from the server by %s for %s", aname, atext);
        SendClientMessage(pID, 0xFF0000AA, cstring);
        new File:fi_log;
        fi_log = fopen("Admin/Logs/Kicklog.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 has kicked %s from the server. reason: %s.\r\n", day, month, year, hour, minute, second, aname, pname, atext);
        fwrite(fi_log, string);
        fclose(fi_log);
        Kick(pID);
       
    }
    return 1;
}
Whenever someone gets kicked, two lines are used at once, one contains the kick message, and the other one is in blank.

Quote:

11/5/2013 - 18:29:33]GwE_NIKO has kicked GwE_NIKO from the server. reason: I don't need a reason to kick myself, do i?.
[11/5/2013 - 18:29:33]
[11/5/2013 - 18:31:9]GwE_NIKO has kicked GwE_NIKO from the server. reason: I don't need a reason to kick myself, do i?.
[11/5/2013 - 18:31:9]

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)