03.10.2009, 12:57
Hey, once again.
This thing has been bugging me for the past 2 days, it has to save the vehicle mods and then set them back, though it saves them wrong, in the file, it always writes 0 as a component, 0.0000 as float positions and 0 for colors and paintjobs.
Maybe I'm doing something wrong? It's my first time using GetVehicleComponentInSlot and GetVehicleComponentType.
Here's the code:
Load Vehicles gets called 1 second after OnGameModeInit, and then later calls SaveVehicleData every second.
Excuse the identation, it's the forum/PAWN tags...
Any help would be appreciated.
EDIT: Here's the file output, if anyone needs it;
This thing has been bugging me for the past 2 days, it has to save the vehicle mods and then set them back, though it saves them wrong, in the file, it always writes 0 as a component, 0.0000 as float positions and 0 for colors and paintjobs.
Maybe I'm doing something wrong? It's my first time using GetVehicleComponentInSlot and GetVehicleComponentType.
Here's the code:
pawn Код:
public LoadVehicleData()
{
for(new vehs = 0; vehs < vehcount; vehs++)
{
new string[128];
format(string, sizeof(string), "admin/vehicles/mods/veh%d.ini", vehs);
if(dini_Exists(string))
{
if(dini_Int(string, "Component0") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component0"));
if(dini_Int(string, "Component1") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component1"));
if(dini_Int(string, "Component2") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component2"));
if(dini_Int(string, "Component3") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component3"));
if(dini_Int(string, "Component4") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component4"));
if(dini_Int(string, "Component5") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component5"));
if(dini_Int(string, "Component6") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component6"));
if(dini_Int(string, "Component7") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component7"));
if(dini_Int(string, "Component8") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component8"));
if(dini_Int(string, "Component9") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component9"));
if(dini_Int(string, "Component10") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component10"));
if(dini_Int(string, "Component11") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component11"));
if(dini_Int(string, "Component12") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component12"));
if(dini_Int(string, "Component13") >= 0) AddVehicleComponent(vehs, dini_Int(string, "Component13"));
SetVehiclePos(vehs, dini_Float(string, "X"), dini_Float(string, "Y"), dini_Float(string, "Z"));
SetVehicleZAngle(vehs, dini_Float(string, "Angle"));
SetVehicleHealth(vehs, dini_Float(string, "Health"));
SetVehicleColor(vehs, dini_Int(string, "Color1"), dini_Int(string, "Color2"));
SetVehiclePaintjob(vehs, dini_Int(string, "Paintjob"));
VehicleLocked[vehs] = dini_Int(string, "Locked");
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++) SetVehicleParamsForPlayerEx(vehs, playerid, 0, VehicleLocked[vehs]);
}
else if(!dini_Exists(string))
{
//SetVehiclePos(vehs, dini_Float(string, "X"), dini_Float(string, "Y"), dini_Float(string, "Z"));
//SetVehicleZAngle(vehs, dini_Float(string, "Angle"));
SetVehicleHealth(vehs, 1000);
SetVehicleColor(vehs, VehicleColor[vehs][0], VehicleColor[vehs][1]);
SetVehiclePaintjob(vehs, 0);
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++) SetVehicleParamsForPlayerEx(vehs, playerid, 0, 0);
}
}
SetTimer("SaveVehicleData", 1000, 1);
}
pawn Код:
public SaveVehicleData()
{
for(new vehs = 0; vehs < vehcount; vehs++)
{
new string[128],
component[14];
format(string, sizeof(string), "admin/vehicles/mods/veh%d.ini", vehs);
if(!dini_Exists(string))
{
print("[VEHICLES] File doesn't exist");
new Float:X,
Float:Y,
Float:Z,
Float:Angle,
Float:Health,
Color1,
Color2,
Paintjob;
print("[VEHICLES] Everything is defined.");
dini_Create(string);
print("[VEHICLES] File created.");
GetVehiclePos(vehs, X, Y, Z);
GetVehicleZAngle(vehs, Angle);
GetVehicleHealth(vehs, Health);
GetVehicleColor(vehs, Color1, Color2);
GetVehiclePaintjob(vehs, Paintjob);
print("[VEHICLES] All positions, colors etc got in variables.");
dini_FloatSet(string, "X", floatround(X));
dini_FloatSet(string, "Y", floatround(Y));
dini_FloatSet(string, "Z", floatround(Z));
dini_FloatSet(string, "Angle", floatround(Angle));
dini_FloatSet(string, "Health", floatround(Health));
dini_IntSet(string, "Color1", Color1);
dini_IntSet(string, "Color2", Color2);
dini_IntSet(string, "Paintjob", Paintjob);
dini_IntSet(string, "Locked", VehicleLocked[vehs]);
print("[VEHICLES] Positions, colors etc saved in the file...");
dini_IntSet(string, "Component0", GetVehicleComponentInSlot(vehs, 0));
dini_IntSet(string, "Component1", GetVehicleComponentInSlot(vehs, 1));
dini_IntSet(string, "Component2", GetVehicleComponentInSlot(vehs, 2));
dini_IntSet(string, "Component3", GetVehicleComponentInSlot(vehs, 3));
dini_IntSet(string, "Component4", GetVehicleComponentInSlot(vehs, 4));
dini_IntSet(string, "Component5", GetVehicleComponentInSlot(vehs, 5));
dini_IntSet(string, "Component6", GetVehicleComponentInSlot(vehs, 6));
dini_IntSet(string, "Component7", GetVehicleComponentInSlot(vehs, 7));
dini_IntSet(string, "Component8", GetVehicleComponentInSlot(vehs, 8));
dini_IntSet(string, "Component9", GetVehicleComponentInSlot(vehs, 9));
dini_IntSet(string, "Component10", GetVehicleComponentInSlot(vehs, 10));
dini_IntSet(string, "Component11", GetVehicleComponentInSlot(vehs, 11));
dini_IntSet(string, "Component12", GetVehicleComponentInSlot(vehs, 12));
dini_IntSet(string, "Component13", GetVehicleComponentInSlot(vehs, 13));
print("[VEHICLES] Components saved in the file...");
}
else if(dini_Exists(string))
{
print("[VEHICLES] File exists");
new Float:X,
Float:Y,
Float:Z,
Float:Angle,
Float:Health,
Color1,
Color2,
Paintjob;
print("[VEHICLES] Everything is defined.");
GetVehiclePos(vehs, X, Y, Z);
GetVehicleZAngle(vehs, Angle);
GetVehicleHealth(vehs, Health);
GetVehicleColor(vehs, Color1, Color2);
GetVehiclePaintjob(vehs, Paintjob);
print("[VEHICLES] All positions, colors etc got in variables.");
dini_FloatSet(string, "X", floatround(X));
dini_FloatSet(string, "Y", floatround(Y));
dini_FloatSet(string, "Z", floatround(Z));
dini_FloatSet(string, "Angle", floatround(Angle));
dini_FloatSet(string, "Health", floatround(Health));
dini_IntSet(string, "Color1", Color1);
dini_IntSet(string, "Color2", Color2);
dini_IntSet(string, "Paintjob", Paintjob);
dini_IntSet(string, "Locked", VehicleLocked[vehs]);
print("[VEHICLES] Positions, colors etc saved in the file...");
dini_IntSet(string, "Component0", GetVehicleComponentInSlot(vehs, 0));
dini_IntSet(string, "Component1", GetVehicleComponentInSlot(vehs, 1));
dini_IntSet(string, "Component2", GetVehicleComponentInSlot(vehs, 2));
dini_IntSet(string, "Component3", GetVehicleComponentInSlot(vehs, 3));
dini_IntSet(string, "Component4", GetVehicleComponentInSlot(vehs, 4));
dini_IntSet(string, "Component5", GetVehicleComponentInSlot(vehs, 5));
dini_IntSet(string, "Component6", GetVehicleComponentInSlot(vehs, 6));
dini_IntSet(string, "Component7", GetVehicleComponentInSlot(vehs, 7));
dini_IntSet(string, "Component8", GetVehicleComponentInSlot(vehs, 8));
dini_IntSet(string, "Component9", GetVehicleComponentInSlot(vehs, 9));
dini_IntSet(string, "Component10", GetVehicleComponentInSlot(vehs, 10));
dini_IntSet(string, "Component11", GetVehicleComponentInSlot(vehs, 11));
dini_IntSet(string, "Component12", GetVehicleComponentInSlot(vehs, 12));
dini_IntSet(string, "Component13", GetVehicleComponentInSlot(vehs, 13));
print("[VEHICLES] Components saved in the file...");
}
}
}
Any help would be appreciated.
EDIT: Here's the file output, if anyone needs it;
Код:
X=0.000000 Y=0.000000 Z=0.000000 Angle=0.000000 Health=0.000000 Color1=0 Color2=0 Paintjob=0 Locked=0 Component0=0 Component1=0 Component2=0 Component3=0 Component4=0 Component5=0 Component6=0 Component7=0 Component8=0 Component9=0 Component10=0 Component11=0 Component12=0 Component13=0