if(strcmp(cmd, "/admingarerveh", true) == 0) { if(IsPlayerConnected(playerid)) { new IDVEH = GetPlayerVehicleID(playerid); new Float:PosX, Float:PosY, Float:PosZ, Float:PosA; GetVehiclePos(IDVEH, PosX, PosY, PosZ); GetVehicleZAngle(IDVEH, PosA); CarSystem[IDVEH][cX] = PosX; CarSystem[IDVEH][cY] = PosY; CarSystem[IDVEH][cZ] = PosZ; CarSystem[IDVEH][cAngle] = PosA; UpdateVehicle(IDVEH); } return 1; }
public UpdateVehicle(IDVEH) { new File: file2 = fopen("vehicles.cfg"); new coordsstring[258]; format(coordsstring, sizeof(coordsstring), "%d|%d|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d", CarSystem[IDVEH][cModel], CarSystem[IDVEH][cEssence], CarSystem[IDVEH][cX], CarSystem[IDVEH][cY], CarSystem[IDVEH][cZ], CarSystem[IDVEH][cAngle], CarSystem[IDVEH][cColor1], CarSystem[IDVEH][cColor2], CarSystem[IDVEH][cKM], CarSystem[IDVEH][cObjective], CarSystem[IDVEH][cDoorsLocked], CarSystem[IDVEH][cVehicleType], CarSystem[IDVEH][cPlaque], CarSystem[IDVEH][cVehicleMaterials], CarSystem[IDVEH][cVehicleCrack], CarSystem[IDVEH][cVehiclePot], CarSystem[IDVEH][cJantes], CarSystem[IDVEH][cMetre], CarSystem[IDVEH][cVehicleHealth], CarSystem[IDVEH][cVehicleAlarm], CarSystem[IDVEH][cVehicleOwned], CarSystem[IDVEH][cDescription], CarSystem[IDVEH][cOwner], CarSystem[IDVEH][cNitro], CarSystem[IDVEH][cLoad], CarSystem[IDVEH][veh_int], CarSystem[IDVEH][veh_world], CarSystem[IDVEH][cPaintJob], CarSystem[IDVEH][cHydro], CarSystem[IDVEH][cPimped], CarSystem[IDVEH][cPerma], CarSystem[IDVEH][cRank], CarSystem[IDVEH][cPrice], CarSystem[IDVEH][cSpoiler], CarSystem[IDVEH][cFbumper], CarSystem[IDVEH][cRbumper]); fwrite(file2, coordsstring); fclose(file2); }
410|100|2095.676269|-1817.695922|13.038349|272.177825|-1|-1|0|0|0|0|none|0|0|0|-1|12|1000|0|0|0|none|-1|0|1|-1|0|-1|-1|-1|0|0|-1|-1|-1|
414|100|2132.622070|-1869.314697|13.165164|359.999023|-1|-1|0|0|0|0|none|0|0|0|-1|0|1000|0|0|0|none|-1|0|0|1|-1|-1|-1|-1|0|0|-1|-1|-1|
fopen(filename[], io_append);
format(coordsstring, sizeof(coordsstring), "%d|%d|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d\r\n", ...
You need to use io_append, so you can add to the file, and not re-write it.
Код:
fopen(filename[], io_append); Код:
format(coordsstring, sizeof(coordsstring), "%d|%d|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d\r\n", ... |
410|100|2015.104492|-1807.023071|13.114258|90.029151|-1|-1|0|0|0|0|none|0|0|0|-1|13|1000|0|0|0|none|-1|1|-1|0|0|-1|-1|-1|0|0|-1|-1|-1|1|
414|100|2132.622070|-1869.314697|13.165164|359.999023|-1|-1|0|0|0|0|none|0|0|0|-1|0|1000|0|0|0|none|-1|0|0|1|-1|-1|-1|-1|0|0|-1|-1|-1|
414|100|2132.208007|-1869.288208|13.641092|0.000000|-1|-1|0|0|0|0|none|0|0|0|-1|0|1000|0|0|0|none|-1|0|1|-1|0|-1|-1|-1|0|0|-1|-1|-1|
If a line needs to be updated then generally the whole file needs to be rewritten from scratch. Unless you know exactly where you want to write as in that case you can use fseek() to move the cursor the right location. However this implies that the length of each line is the same and that's not the case here.
Also don't assume that any file is an INI. The INI syntax is very specific. |
public UpdateVehicle() { for(new IDVEH = 1; IDVEH < MAX_VEHICLES; IDVEH++) { new File: file2 = fopen("vehicles.cfg", io_readwrite); new coordsstring[258]; format(coordsstring, sizeof(coordsstring), "%d|%d|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d", CarSystem[IDVEH][cModel], CarSystem[IDVEH][cEssence], CarSystem[IDVEH][cX], CarSystem[IDVEH][cY], CarSystem[IDVEH][cZ], CarSystem[IDVEH][cAngle], CarSystem[IDVEH][cColor1], CarSystem[IDVEH][cColor2], CarSystem[IDVEH][cKM], CarSystem[IDVEH][cObjective], CarSystem[IDVEH][cDoorsLocked], CarSystem[IDVEH][cVehicleType], CarSystem[IDVEH][cPlaque], CarSystem[IDVEH][cVehicleMaterials], CarSystem[IDVEH][cVehicleCrack], CarSystem[IDVEH][cVehiclePot], CarSystem[IDVEH][cJantes], CarSystem[IDVEH][cMetre], CarSystem[IDVEH][cVehicleHealth], CarSystem[IDVEH][cVehicleAlarm], CarSystem[IDVEH][cVehicleOwned], CarSystem[IDVEH][cDescription], CarSystem[IDVEH][cOwner], CarSystem[IDVEH][cNitro], CarSystem[IDVEH][cLoad], CarSystem[IDVEH][veh_int], CarSystem[IDVEH][veh_world], CarSystem[IDVEH][cPaintJob], CarSystem[IDVEH][cHydro], CarSystem[IDVEH][cPimped], CarSystem[IDVEH][cPerma], CarSystem[IDVEH][cRank], CarSystem[IDVEH][cPrice], CarSystem[IDVEH][cSpoiler], CarSystem[IDVEH][cFbumper], CarSystem[IDVEH][cRbumper]); fwrite(file2, coordsstring); fclose(file2); } return 1; }