[SOLVED] Tuned cars saving
#1

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:

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);
}
Load Vehicles gets called 1 second after OnGameModeInit, and then later calls SaveVehicleData every second.

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...");
        }
    }
}
Excuse the identation, it's the forum/PAWN tags...

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
Reply
#2

Bump...
Reply
#3

I haven't used these funcs myself either, but I think instead of

pawn Код:
dini_IntSet(string, "Component0", GetVehicleComponentType(component[0]));
it should be

pawn Код:
dini_IntSet(string, "Component0", GetVehicleComponentInSlot(vehs, 0));
Reply
#4

I've tried that already.
The weird thing is that the X, Y, Z and other angles save as 0.0000 too.
Reply
#5

Are the vehicles spawned when you execute that code ?
Reply
#6

Well, i've noticed that GetVehicleComponentInSlot "is a new function working since SA-MP 0.3. It won't work in previous versions. " according to the Wiki. https://sampwiki.blast.hk/wiki/GetVehicleComponentInSlot

That may be partly the reason why it's not working, unless you are using 0.3?
Reply
#7

Quote:
Originally Posted by dice7
Are the vehicles spawned when you execute that code ?
Of course, it's under a timer aswell, so it should work.

Quote:
Originally Posted by [B2K
Hustler ]
Well, i've noticed that GetVehicleComponentInSlot "is a new function working since SA-MP 0.3. It won't work in previous versions. " according to the Wiki. https://sampwiki.blast.hk/wiki/GetVehicleComponentInSlot

That may be partly the reason why it's not working, unless you are using 0.3?
Yes, I am using 0.3

EDIT: I've updated the first post with the code I'm using now.
Reply
#8

I'm not too sure but, make sure the LoadVehicleData() function executes after the vehciles are created, maybe that is the problem. And also try delaying the timer - You have the timer at 1 second, maybe change it to five seconds (probaby the values are still being read while being written? Worth a try

Change:
pawn Код:
SetTimer("SaveVehicleData", 1000, 1);
to:
pawn Код:
SetTimer("SaveVehicleData", 5000, 1);
Reply
#9

Still the same result; it writes 0 for everything:

Код:
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
EDIT: Hmmm, weird, I've put the timer under OnVehicleSpawn and now it doesn't even get called, I guess that the vehicles don't spawn, though I see them ingame...
Reply
#10

Ok i've got another idea. Note: i've never tried this before, but i'm interested to see if it works. Try a bit of debugging.

First stop calling any of your functions (SaveVehicleData() and LoadVehicleData()). Make sure you follow exactly.

Then follow these steps:

1. Delete all your vehicle files in admin/vehicles/mods/ (make a backup in case)

2. Make a command like /savemycars and in that command put this:
pawn Код:
SaveVehicleData();
SendClientMessage(playerid,0x48FF48FF,"Ok, all the vehicle data should now be saved");
print("Vehicles Saved Called Sucessful");
3. Disconnect from the server and check if the vehicle data have been saved. Dont worry about the component0 =0, component1=0 etc, just check if the coords save (X,Y,Z to the files). Note: Don't just check one file, check lots of files.
If they havn't then probably there is a problem with the SaveVehicleData. Have a look at that. If it saves continue to step 4.

4. Now go back to ur gamemode/filterscript and then use/call ur LoadVehicleData() function where you used to, make sure it is after the vehicles have been created.

Use this one (the same as urs only the timer has been commented out.)
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"));
        }
    }
    /// SetTimer("SaveVehicleData", 5000, 1);
    print("LoadedVehicleData Sucessful");
}
5. Now check if any of your vehicle positions are fine and check your files as well (again dont worry about component0, component1 etc =0) If so, then continue to step 6.

6. Go back to ur gamemode/filterscript and do this:

pawn Код:
//OnGameModeInit:
CreateVehicle...
LoadVehicleData();
Then UnComment out the timer in your LoadVehicleData() callback.

Let me know what happens. Good Luck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)