SA-MP Forums Archive
fwrite crashing my server? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: fwrite crashing my server? (/showthread.php?tid=322160)



fwrite crashing my server? - Walsh - 01.03.2012

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.


Re: fwrite crashing my server? - 2KY - 01.03.2012

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"



Re: fwrite crashing my server? - Walsh - 01.03.2012

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.


Re: fwrite crashing my server? - 2KY - 01.03.2012

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.


Re: fwrite crashing my server? - Walsh - 01.03.2012

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.


Re: fwrite crashing my server? - 2KY - 01.03.2012

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.