dcmd_cp(playerid, params[])
{
new reason[128]; new string[256];
if (sscanf(params, "z", reason)) return SendClientMessage(playerid,0xFFFFFF60, "Kasuta: /cp <nimi>");
if (GetPlayerState(playerid) == 2)
{
new stringid[2012]; // Oo jaa..
new stringid2[2012]; // Maailmalхpp
new Float:XP,Float:YP,Float:ZP;
new RedNeckiAuto = GetPlayerVehicleID(playerid);
GetVehiclePos(RedNeckiAuto,XP,YP,ZP);
new File:fhnd;
format(stringid2,2012,"%s",fread(fhnd, stringid2, -1));
format(stringid,2012,"%s\r\n#define %s %0.3f,%0.3f,%0.3f\r\n",stringid2,reason,XP,YP,ZP);
format(string, 300, "Checkpoint: {FFF45F}%s {FFFFFF}On Salvestatud! X: {FFF45F}%0.3f {FFFFFF}| Y: {FFF45F}%0.3f {FFFFFF}| Z: {FFF45F}%0.3f", reason,XP,YP,ZP);
SendClientMessage(playerid, 0xFFFFFF60, string);
SetPlayerRaceCheckpoint(playerid, 2, XP,YP,ZP, XP,YP,ZP, 15.0);
format(string, 256, "Checkpointid.ini");
fhnd=fopen(string ,io_write);
fwrite(fhnd, stringid);
fwrite(fhnd, "\n");
fclose(fhnd);
}
return 1;
}
//New file var
new File:fpFile;
//Open for writing
fpFile=fopen("myFile.txt" ,io_write);
//Write "hi" at position 0
fwrite(fpFile, "hi");
//Close the file.
fclose(fpFile);
//New file var
new File:fpFile;
//Open for appending
fpFile=fopen("myFile.txt" ,io_append);
//Append "hi"
fwrite(fpFile, "hi");
//New line
fwrite(fpFile, "\r\n");
//Close the file.
fclose(fpFile);
dcmd_cp(playerid, params[])
{
new reason[128]; new string[256];
if (sscanf(params, "z", reason)) return SendClientMessage(playerid,0xFFFFFF60, "Kasuta: /cp <nimi>");
if (GetPlayerState(playerid) == 2)
{
new stringid[2012]; // Oo jaa..
new stringid2[2012]; // Maailmalхpp
new Float:XP,Float:YP,Float:ZP;
new RedNeckiAuto = GetPlayerVehicleID(playerid);
GetVehiclePos(RedNeckiAuto,XP,YP,ZP);
new File:fhnd;
format(stringid2,2012,"%s",fread(fhnd, stringid2, -1));
format(stringid,2012,"%s\r\n#define %s %0.3f,%0.3f,%0.3f\r\n",stringid2,reason,XP,YP,ZP);
format(string, 300, "Checkpoint: {FFF45F}%s {FFFFFF}On Salvestatud! X: {FFF45F}%0.3f {FFFFFF}| Y: {FFF45F}%0.3f {FFFFFF}| Z: {FFF45F}%0.3f", reason,XP,YP,ZP);
SendClientMessage(playerid, 0xFFFFFF60, string);
SetPlayerRaceCheckpoint(playerid, 2, XP,YP,ZP, XP,YP,ZP, 15.0);
format(string, 256, "Checkpointid.ini");
fhnd=fopen(string ,io_append);
fwrite(fhnd, stringid);
fwrite(fhnd, "\n");
fclose(fhnd);
}
return 1;
}
It isn't fwrite which is causing the problem. It's the mode you open the file with; with fopen.
io_write - (what you're using) opens the file from offset 0, i.e. the start of the file. This means that whenever you write with fwrite after opening it this way, it'll write from the start and delete any other text. io_append - is what you're looking for. This opens the file at the end, so when you write with fwrite, it'll append text to the end of the file - not deleting anything else. To sum up, this adds text to the beginning, because of io_write: pawn Код:
pawn Код:
pawn Код:
|