PDA

View Full Version : Vehicles bug upon loading


DevHarden
27/03/2017, 01:45 PM
enum vInfo
{
vID,
vHasKey,
vKeyID,
vModel,
vFuel,
vUsingFuel,
vOil,
vCanRun,
vInsured,
Float:vX,
Float:vY,
Float:vZ,
Float:vA,
vColor1,
vColor2,
vFaction,
vOwner[MAX_PLAYER_NAME],
vPrevOwners,
vLocked,
vRegdate[24],
vCash,
vWeapon,
vPot,
vCrack
};

new VehicleInfo[MAX_VEHICLES][vInfo];


Public OnGameModeInit()
{
new string[40], vCount = 0, bCount = 0;

for(new i = 0; i < sizeof(VehicleInfo); i++)
{
new vFile[35];
format(vFile, 50, vPATH ,i);
if(fexist(vFile))
{
INI_ParseFile(vFile, "LoadVehicle", .bExtra = true, .extra = i);
if(VehicleInfo[i][vModel] != 0)
{
vCount++;
VehicleInfo[i][vID] = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vX],VehicleInfo[i][vY],VehicleInfo[i][vZ],VehicleInfo[i][vA], VehicleInfo[i][vColor1], VehicleInfo[i][vColor2], 0);
SetVehicleParamsEx(VehicleInfo[i][vID], 0, 0, 0, 0, 0, 0, 0);
}
}
}

format(string, sizeof(string), " %i vehicles have been loaded!\n", vCount);
print(string);
}


function LoadVehicle(fileid, name[], value[])
{
INI_Int("KeyID",VehicleInfo[fileid][vKeyID]);
INI_Int("HasKey",VehicleInfo[fileid][vHasKey]);
INI_Int("Model",VehicleInfo[fileid][vModel]);
INI_Int("Fuel",VehicleInfo[fileid][vFuel]);
INI_Int("UsingFuel",VehicleInfo[fileid][vUsingFuel]);
INI_Int("Oil",VehicleInfo[fileid][vOil]);
INI_Int("CanRun",VehicleInfo[fileid][vCanRun]);
INI_Int("Insured",VehicleInfo[fileid][vInsured]);
INI_Float("X",VehicleInfo[fileid][vX]);
INI_Float("Y",VehicleInfo[fileid][vY]);
INI_Float("Z",VehicleInfo[fileid][vZ]);
INI_Float("A",VehicleInfo[fileid][vA]);
INI_Int("Color1",VehicleInfo[fileid][vColor1]);
INI_Int("Color2",VehicleInfo[fileid][vColor2]);
INI_Int("Faction",VehicleInfo[fileid][vFaction]);
INI_String("Owner",VehicleInfo[fileid][vOwner], MAX_PLAYER_NAME);
INI_Int("PrevOwners",VehicleInfo[fileid][vPrevOwners]);
INI_String("RegDate",VehicleInfo[fileid][vRegdate], 30);
INI_Int("Cash",VehicleInfo[fileid][vCash]);
INI_Int("Weapon",VehicleInfo[fileid][vWeapon]);
INI_Int("Pot",VehicleInfo[fileid][vPot]);
INI_Int("Crack",VehicleInfo[fileid][vCrack]);
return 1;
}



Issue:
Vehicle system saves the vehicle location perfectly, even after manually checking it before and after a manual restart. The problem arises when it is restarted and they are loaded in. They all spawn at "0.0, 0.0, 0.0" under the map and then free fall and spawn back on the map in the field but everything else about the vehicle is saved and correctly loaded, I am just having issues with the co-ordinates.

I've ran trial and error on all of the code and cannot figure out the problem. The problem started happening randomly as the code was previously working 100% correctly so either I accidentally changed something and am missing it or something else could be interfering with the system in which I hope somebody has had and can point me to a solution.

Thank you!

Feel free to message me your skype if you'd like to look over the complete code that doesn't involve the vehicle loading.

[eLg]elite
28/03/2017, 07:32 AM
Can I see the code where you save the coords of the vehicles to the ini itself?

Logic_
28/03/2017, 08:23 AM
Try creating a vehicle under OnGameModeInit, call a timer and destroy it (after 100ms would be fine), and then you may try loading the vehicles using your function.

You should use printf instead of print if you need to show (a) value in it.
printf(" %i vehicles have been loaded!\n", vCount);

You may as well, try printing the vehicle position while loading it, use printf here.

DevHarden
29/03/2017, 03:25 PM
elite;3861204']Can I see the code where you save the coords of the vehicles to the ini itself?


function SaveVehicle(fileid)
{
new vFile[128], Float:vsX, Float:vsY, Float:vsZ, Float:vsA;
format(vFile, sizeof(vFile),vPATH,fileid);
GetVehiclePos(VehicleInfo[fileid][vID], vsX, vsY, vsZ);
GetVehicleZAngle(VehicleInfo[fileid][vID], vsA);
VehicleInfo[fileid][vX] = vsX;
VehicleInfo[fileid][vY] = vsY;
VehicleInfo[fileid][vZ] = vsZ;
VehicleInfo[fileid][vA] = vsA;
new INI:File = INI_Open(vFile);
INI_WriteInt(File,"KeyID",VehicleInfo[fileid][vKeyID]);
INI_WriteInt(File,"HasKey",VehicleInfo[fileid][vHasKey]);
INI_WriteInt(File,"Model",VehicleInfo[fileid][vModel]);
INI_WriteInt(File,"Fuel",VehicleInfo[fileid][vFuel]);
INI_WriteInt(File,"UsingFuel",VehicleInfo[fileid][vUsingFuel]);
INI_WriteInt(File,"Oil",VehicleInfo[fileid][vOil]);
INI_WriteInt(File,"CanRun",VehicleInfo[fileid][vCanRun]);
INI_WriteInt(File,"Insured",VehicleInfo[fileid][vInsured]);
INI_WriteFloat(File,"X",VehicleInfo[fileid][vX]);
INI_WriteFloat(File,"Y",VehicleInfo[fileid][vY]);
INI_WriteFloat(File,"Z",VehicleInfo[fileid][vZ]);
INI_WriteFloat(File,"A",VehicleInfo[fileid][vA]);
INI_WriteInt(File,"Color1",VehicleInfo[fileid][vColor1]);
INI_WriteInt(File,"Color2",VehicleInfo[fileid][vColor2]);
INI_WriteInt(File,"Faction",VehicleInfo[fileid][vFaction]);
INI_WriteString(File,"Owner",VehicleInfo[fileid][vOwner]);
INI_WriteInt(File,"PrevOwners",VehicleInfo[fileid][vPrevOwners]);
INI_WriteString(File,"RegDate",VehicleInfo[fileid][vRegdate]);
INI_WriteInt(File,"Cash",VehicleInfo[fileid][vCash]);
INI_WriteInt(File,"Weapon",VehicleInfo[fileid][vWeapon]);
INI_WriteInt(File,"Pot",VehicleInfo[fileid][vPot]);
INI_WriteInt(File,"Crack",VehicleInfo[fileid][vCrack]);
INI_Close(File);
return 1;
}

function SaveVehicles(fileid)
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(VehicleInfo[i][vModel] != 0)
{
SaveVehicle(i);
}
}
}


Saving isn't an issue. I can turn the server off and manually check the vehicle files and the coords will be correct. The issue comes with loading the vehicles into the game. All of values saved to the vehicle are correct including the coords they were saved to, the issue is when they are actually spawned ingame they spawn at "0.0, 0.0, 0.0" instead of the correct coords.



Try creating a vehicle under OnGameModeInit, call a timer and destroy it (after 100ms would be fine), and then you may try loading the vehicles using your function.

You should use printf instead of print if you need to show (a) value in it.
printf(" %i vehicles have been loaded!\n", vCount);

You may as well, try printing the vehicle position while loading it, use printf here.


I gave your suggestion a try with no luck. Thank you for the suggestion though. :)