08/07/2023 22:33
Tenho um sistema onde o salvamento é diferente doq eu uso, no caso uso DOF2 e queria uma ajudar para deixa-lo em DOF2 também.
Tava começando a fazer porém vim pedir uma ajuda a mais aqui.
Uso esse sistema que eu mesmo postei aqui no portal
https://portalsamp.com/showthread.php?tid=2867
Código:
LoadVehicles()
{
new string[64];
new File:handle, count;
new filename[64], line[256], s, key[64];
for(new i=1; i < MAX_DVEHICLES; i++)
{
format(filename, sizeof(filename), VEHICLE_FILE_PATH "v%d.ini", i);
if(!fexist(filename)) continue;
handle = fopen(filename, io_read);
while(fread(handle, line))
{
StripNL(line);
s = strfind(line, "=");
if(!line[0] || s < 1) continue;
strmid(key, line, 0, s++);
if(strcmp(key, "Created") == 0) VehicleCreated[i] = strval(line[s]);
else if(strcmp(key, "Model") == 0) VehicleModel[i] = strval(line[s]);
else if(strcmp(key, "Pos") == 0) sscanf(line[s], "p,ffff", VehiclePos[i][0], VehiclePos[i][1],
VehiclePos[i][2], VehiclePos[i][3]);
else if(strcmp(key, "Colors") == 0) sscanf(line[s], "p,dd", VehicleColor[i][0], VehicleColor[i][1]);
else if(strcmp(key, "Interior") == 0) VehicleInterior[i] = strval(line[s]);
else if(strcmp(key, "VirtualWorld") == 0) VehicleWorld[i] = strval(line[s]);
else if(strcmp(key, "Owner") == 0) strmid(VehicleOwner[i], line, s, sizeof(line));
else if(strcmp(key, "NumberPlate") == 0) strmid(VehicleNumberPlate[i], line, s, sizeof(line));
else if(strcmp(key, "Value") == 0) VehicleValue[i] = strval(line[s]);
else if(strcmp(key, "Lock") == 0) VehicleLock[i] = strval(line[s]);
else if(strcmp(key, "Alarm") == 0) VehicleAlarm[i] = strval(line[s]);
else if(strcmp(key, "Paintjob") == 0) VehiclePaintjob[i] = strval(line[s]);
else
{
for(new t=0; t < sizeof(VehicleTrunk[]); t++)
{
format(string, sizeof(string), "Trunk%d", t+1);
if(strcmp(key, string) == 0) sscanf(line[s], "p,dd", VehicleTrunk[i][t][0], VehicleTrunk[i][t][1]);
}
for(new m=0; m < sizeof(VehicleMods[]); m++)
{
format(string, sizeof(string), "Mod%d", m);
if(strcmp(key, string) == 0) VehicleMods[i][m] = strval(line[s]);
}
}
}
fclose(handle);
if(VehicleCreated[i]) count++;
}
printf(" Carregado %d Veiculos", count);
}
SaveVehicle(vehicleid)
{
new filename[64], line[256];
format(filename, sizeof(filename), VEHICLE_FILE_PATH "v%d.ini", vehicleid);
new File:handle = fopen(filename, io_write);
format(line, sizeof(line), "Created=%d\r\n", VehicleCreated[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Model=%d\r\n", VehicleModel[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Pos=%.3f,%.3f,%.3f,%.3f\r\n", VehiclePos[vehicleid][0], VehiclePos[vehicleid][1],
VehiclePos[vehicleid][2], VehiclePos[vehicleid][3]);
fwrite(handle, line);
format(line, sizeof(line), "Colors=%d,%d\r\n", VehicleColor[vehicleid][0], VehicleColor[vehicleid][1]); fwrite(handle, line);
format(line, sizeof(line), "Interior=%d\r\n", VehicleInterior[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "VirtualWorld=%d\r\n", VehicleWorld[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Owner=%s\r\n", VehicleOwner[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "NumberPlate=%s\r\n", VehicleNumberPlate[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Value=%d\r\n", VehicleValue[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Lock=%d\r\n", VehicleLock[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Alarm=%d\r\n", VehicleAlarm[vehicleid]); fwrite(handle, line);
format(line, sizeof(line), "Paintjob=%d\r\n", VehiclePaintjob[vehicleid]); fwrite(handle, line);
for(new t=0; t < sizeof(VehicleTrunk[]); t++)
{
format(line, sizeof(line), "Trunk%d=%d,%d\r\n", t+1, VehicleTrunk[vehicleid][t][0], VehicleTrunk[vehicleid][t][1]);
fwrite(handle, line);
}
for(new m=0; m < sizeof(VehicleMods[]); m++)
{
format(line, sizeof(line), "Mod%d=%d\r\n", m, VehicleMods[vehicleid][m]);
fwrite(handle, line);
}
fclose(handle);
}
Tava começando a fazer porém vim pedir uma ajuda a mais aqui.
Código:
CarregarVeh()
{
new File[255];
new filename[64], line[256], s, key[64];
for(new i = 0; i < MAX_DVEHICLES; i++)
{
format(File, sizeof(File), VEHICLE_FILE_PATH "v%d.ini", i);
if(DOF2_FileExists(File))
{
DOF2_SetInt(File, "Created", VehicleCreated[i]);
DOF2_SetInt(File, "Model", VehicleModel[i]);
DOF2_SetFloat(File, "Pos", VehiclePos[i][0], VehiclePos[i][1],VehiclePos[i][2], VehiclePos[i][3]);
DOF2_SetInt(File, "Colors", VehicleColor[i][0], VehicleColor[i][1]);
DOF2_SetInt(File, "Interior", VehicleInterior[i]);
DOF2_SetInt(File, "VirtualWorld", VehicleWorld[i]);
DOF2_SetString(File, "Owner", VehicleOwner[i]);
DOF2_SetString(File, "NumberPlate", VehicleNumberPlate[i]);
DOF2_SetInt(File, "Value", VehicleValue[i]);
DOF2_SetInt(File, "Lock", VehicleLock[i]);
DOF2_SetInt(File, "Alarm", VehicleAlarm[i]);
DOF2_SetInt(File, "Paintjob", VehiclePaintjob[i]);
if(VehicleCreated[i]) count++;
}
}
printf(" Carregado %d Veiculos", count);
}
Uso esse sistema que eu mesmo postei aqui no portal
https://portalsamp.com/showthread.php?tid=2867