fwrite crashing my server?
#1

Hello, to familiarize myself with the original file functions I decided to make a simple chatlog for practice. Only problem is that whenever I type anything in the main chat my server crashes. This is my file writing code. No errors on compiling either.

This is defined at the top of my script.
pawn Код:
#define LOG                 "../Server/log.txt"
OnPlayerText.
pawn Код:
public OnPlayerText(playerid, text[])
{
    new pname[MAX_PLAYER_NAME], str[128];
    GetPlayerName(playerid, pname, sizeof(pname));
    strreplace(pname,'_',' ');

    format(str, sizeof(str), "(American accent) %s says: %s", pname, text);
    ProxDetector(30.0, playerid, str, COLOR_WHITE);
    new lstring[254],File:log = fopen(LOG,io_write);
    format(lstring,254,"[chat] %s: %s",pname,text);
    fwrite(log,lstring);
    fclose(log);
    return 0;
}
and before you ask, yes, I do have the
Код:
log.txt
file in my server directory in the "Server" file. Also, my server-log shows nothing but the last text I typed.
Reply
#2

Try just doing
pawn Код:
#define LOG                 "Server/log.txt"
You don't need the first slash, like so;

pawn Код:
#include    < MissionServer\colours >   //Usable colours
#include    < MissionServer\dialogs >   //Dialog ID handling
or

pawn Код:
#define     PLAYER_PATH             "MissionServer/Accounts/%s.ini"
Reply
#3

I did the two dots because I think without them the directory is automatically in
Код:
scriptfiles
directory.

I tried what you said, same shit.

EDIT:

It worked. I forgot to add "Server" in scriptfiles directory. Gracias.
Reply
#4

You can only save/write files in the scriptfiles folder. It's currently looking for: C:/WHATEVER/SAMP SERVER/scriptfiles/Server/log.txt. You cannot read/write outside of it.
Reply
#5

Darn, now it's only writing the last chat, and deletes whats there. I read the wiki on file functions and tried
Код:
io_readwrite
but it still clears all the text.
Reply
#6

pawn Код:
public OnPlayerText(playerid, text[])
{
    new pname[MAX_PLAYER_NAME], str[128];
    GetPlayerName(playerid, pname, sizeof(pname));
    strreplace(pname,'_',' ');

    format(str, sizeof(str), "(American accent) %s says: %s", pname, text);
    ProxDetector(30.0, playerid, str, COLOR_WHITE);
    new lstring[254],File:log = fopen(LOG,io_write);
    format(lstring,254,"[chat] %s: %s\n",pname,text);
    fwrite(log,lstring);
    fclose(log);
    return 0;
}
Be sure to create a new line using \n.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)