SA-MP Forums Archive
lil' help here - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: lil' help here (/showthread.php?tid=189422)



lil' help here - dark_clown - 11.11.2010

hum when i do /savelights it saves
but then if i do it again it remains in the .txt file the last light i saved
it dosnt do a new line or write it why?
pawn Код:
dcmd_savelights(playerid,params[])
{
    #pragma unused params
    new tmp[128],filename[25];
    format(tmp,sizeof(tmp),"DAdmin/Config/lights.txt",filename);
    new File:f = fopen(tmp,io_write);
    format(tmp, sizeof(tmp), "CreateObject(354,%f %f %f,270,0.0, 0.0, 30.0);\r\n",
    Lighter[playerid][X],
    Lighter[playerid][Y],
    Lighter[playerid][Z]);
    fwrite(f, tmp);
    fclose(f);
    return 1;
}



Re: lil' help here - TheXIII - 11.11.2010

try this
pawn Код:
dcmd_savelights(playerid,params[])
{
    #pragma unused params
    new File:savefile = fopen("DAdmin/Config/lights.txt", io_write);
    new str[80];
    format(str, sizeof(str), "CreateObject(354,%f, %f, %f,270,0.0, 0.0, 30.0);\r\n",
    Lighter[playerid][X],
    Lighter[playerid][Y],
    Lighter[playerid][Z]);
    fwrite(savefile, str);
    fclose(savefile);
    return 1;
}



Re: lil' help here - dark_clown - 11.11.2010

Quote:
Originally Posted by TheXIII
Посмотреть сообщение
try this
pawn Код:
dcmd_savelights(playerid,params[])
{
    #pragma unused params
    new File:savefile = fopen"DAdmin/Config/lights.txt", io_write);
    new str[80];
    format(str, sizeof(str), "CreateObject(354,%f, %f, %f,270,0.0, 0.0, 30.0);\r\n",
    Lighter[playerid][X],
    Lighter[playerid][Y],
    Lighter[playerid][Z]);
    fwrite(savefile, str);
    fclose(savefile);
    return 1;
}
it helped now but
this time it replaces the old one
nearly there but i cant get it


Re: lil' help here - TheXIII - 11.11.2010

Never used any files with pawn. Short read on wiki:

io_write Writes in a file, clears all earlier written text
io_read Reads the file, the file must exist, otherwise a crash will occur
io_append Appending to a file, writing only
io_readwrite Reads the file or makes a new one


So, just change io_write to io_append, and it will work.

pawn Код:
dcmd_savelights(playerid,params[])
{
    #pragma unused params
    new File:savefile = fopen("DAdmin/Config/lights.txt", io_append);
    new str[80];
    format(str, sizeof(str), "CreateObject(354,%f, %f, %f,270,0.0, 0.0, 30.0);\r\n",
    Lighter[playerid][X],
    Lighter[playerid][Y],
    Lighter[playerid][Z]);
    fwrite(savefile, str);
    fclose(savefile);
    return 1;
}



Re: lil' help here - The_Moddler - 11.11.2010

Like TheXIII just said..

pawn Код:
dcmd_savelights(playerid,params[])
{
    #pragma unused params
    new tmp[128],filename[25];
    format(tmp,sizeof(tmp),"DAdmin/Config/lights.txt",filename);
    new File:f = fopen(tmp,io_append);
    format(tmp, sizeof(tmp), "CreateObject(354,%f %f %f,270,0.0, 0.0, 30.0);\r\n",
    Lighter[playerid][X],
    Lighter[playerid][Y],
    Lighter[playerid][Z]);
    fwrite(f, tmp);
    fclose(f);
    return 1;
}