file.inc glitched?
#1

I made this simple script for my server. CODE:

pawn Код:
public OnPlayerText(playerid, text[])
{
    new File:chatlog = fopen("/logs/chatlog.txt",io_append),chat[128],chater[128],hour,minute,second;
    GetPlayerName(playerid,chater,sizeof(chater));
    gettime(hour,minute,second);
    format(chat,sizeof(chat),"[%d:%d:%d]: ( %s ): %s\n",hour,minute,second,chater,text);
    if(chatlog)
    {
        if(fexist("chatlog.txt"))
        {
            fwrite(chatlog,chat);
            fclose(chatlog);
        }
    }
    return 1;
}
It creates the file and stuff. It just wont write to the file. What do
Reply
#2

OnPlayerText:
pawn Код:
public OnPlayerText(playerid, text[])
{
    new chater[MAX_PLAYER_NAME];
    GetPlayerName(playerid, chater, sizeof(chater));
    new chat[128], second, minute, hour;
    gettime(hour,minute,second);
    format(chat, sizeof(chat), "\n[%d:%d:%d] ( %s ) : %s", hour, minute, second, chater, text);
    ChatLog(chat);
    return 1;
}
Somewhere in your script:
pawn Код:
forward ChatLog(string[]);
public ChatLog(string[])
{
    new entry[128];
    format(entry, sizeof(entry), "%s",string);
    new File:hFile;
    hFile = fopen("Chat.txt", io_append);
    fwrite(hFile, entry);
    fwrite(hFile, "\n");
    fclose(hFile);
}
Reply
#3

THANKS!!!!!
Reply
#4

it doesnt make a new line? how fix
Reply
#5

Yes, New Line exists, its [] symbol. Try to open it with pawno.
Reply
#6

pawn Код:
format(entry, sizeof(entry), "%s\r\n",string);
Reply
#7

When pawno compiles, it use a chharacte for line breaks that notepad doesn't use. Issue is, if you open with wordpad, it over writes the pawno line breaks with wordpad line breaks. That will cause issues with loading the file
Reply
#8

it wont work...
Reply
#9

pawn Код:
forward CmdLog(string[]);
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new y5, m5, d5;
    new h5,mi5,s5;
    getdate(y5,m5,d5);
    gettime(h5,mi5,s5);
    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> %s",d5,m5,y5,h5,mi5,s5,sendername,cmdtext);
    CmdLog(string);
}

pawn Код:
public CmdLog(string[])
{
    new entry[256];
    format(entry, sizeof(entry), "%s\n",string);
    new File:hFile;
    hFile = fopen("logs/cmd.log", io_append);
    fwrite(hFile, entry);
    fclose(hFile);
}
Reply
#10

the \n doesnt make he line go down... wat do?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)