Saved Player Owned Cars won't load!
#1

I am having a bit of trouble with my Car Ownership system.
Cars are successfully saved when a player purchases the vehicle, however, when I restart my script/server, the player owned vehicles wouldn't load in!

These are the related functions that work flawlessly:
My SaveVehicle function:
pawn Код:
stock SaveVehicle(vehicle, filename[36])
{
    new INI:iniFile = INI_Open(filename);
    INI_SetTag(iniFile, "data");
    INI_WriteInt(iniFile, "Model", vInfo[vehicle][Model]);
    INI_WriteFloat(iniFile, "x", vInfo[vehicle][vPos_x]);
    INI_WriteFloat(iniFile, "y", vInfo[vehicle][vPos_y]);
    INI_WriteFloat(iniFile, "z", vInfo[vehicle][vPos_z]);
    INI_WriteFloat(iniFile, "fa", vInfo[vehicle][vAngle]);
    INI_WriteInt(iniFile, "color1", vInfo[vehicle][vcolor1]);
    INI_WriteInt(iniFile, "color2", vInfo[vehicle][vcolor2]);
    INI_WriteInt(iniFile, "locked", vInfo[vehicle][locked]);
    INI_WriteInt(iniFile, "carid", vInfo[vehicle][id]);
    INI_Close(iniFile);
 }
My SaveAllVehicles function:
pawn Код:
stock SaveAllVehicles()
{
    new saveindex = 1;
    new fname[36];
    for(new i = 0; i < MAX_VEHICLES; i ++)
    {
        if(vInfo[i][id] > 0)
        {
            format(fname, sizeof(fname), "/POV/%d.ini", saveindex);
            SaveVehicle(i, fname);
            saveindex++;
        }
    }
}
And these are the functions which I'm having issues with:

LoadAllVehicles:

pawn Код:
stock LoadAllVehicles()
{
    new fname[36];
    new index = 1;
    format(fname, sizeof(fname), "/POV/%i.ini", index);
    while(fexist(fname))
    {
        format(fname, sizeof(fname), "/POV/%i.ini", index);
        INI_ParseFile(fname, "LoadVehicles");
        index++;
    }
}
LoadVehicles:

pawn Код:
forward LoadVehicles(filename[36], name[], value[]);
public LoadVehicles(filename[36], name[], value[])
{
    new AssignedCarID, model, Float:vx, Float:vy, Float:vz, Float:vfa, col1, col2;
    INI_Int("Model", model);
    INI_Float("x", Float:vx);
    INI_Float("y", Float:vy);
    INI_Float("z", Float:vz);
    INI_Float("fa", Float:vfa);
    INI_Int("color1", col1);
    INI_Int("color2", col2);
    INI_Int("id", AssignedCarID);
    CreateVehicleEx(model, Float:vx, Float:vy, Float:vz, Float:vfa, col1, col2, AssignedCarID);
    return 0;
}
I've used some printf messages to debug it, the values seem to be always 0.

Printf LoadVehicles:

pawn Код:
forward LoadVehicles(filename[36], name[], value[]);
public LoadVehicles(filename[36], name[], value[])
{
    printf("Loading %s %s %i", filename, name, value);
    new AssignedCarID, model, Float:vx, Float:vy, Float:vz, Float:vfa, col1, col2;
    INI_Int("Model", model);
    INI_Float("x", Float:vx);
    INI_Float("y", Float:vy);
    INI_Float("z", Float:vz);
    INI_Float("fa", Float:vfa);
    INI_Int("color1", col1);
    INI_Int("color2", col2);
    INI_Int("id", AssignedCarID);
    CreateVehicleEx(model, Float:vx, Float:vy, Float:vz, Float:vfa, col1, col2, AssignedCarID);
    return 0;
}
returns
Код:
Loading: Model 466
However, this

pawn Код:
forward LoadVehicles(filename[36], name[], value[]);
public LoadVehicles(filename[36], name[], value[])
{
    new AssignedCarID, model, Float:vx, Float:vy, Float:vz, Float:vfa, col1, col2;
    INI_Int("Model", model);
    INI_Float("x", Float:vx);
    INI_Float("y", Float:vy);
    INI_Float("z", Float:vz);
    INI_Float("fa", Float:vfa);
    INI_Int("color1", col1);
    INI_Int("color2", col2);
    INI_Int("id", AssignedCarID);
    printf("Loading Vehicle %i, Model %i at X: %f Y:%f Z:%f", AssignedCarID, model, Float:vx, Float:vy, Float:vz);
    CreateVehicleEx(model, Float:vx, Float:vy, Float:vz, Float:vfa, col1, col2, AssignedCarID);
    return 0;
}
returns
Код:
Loading Vehicle 0, Model 0 at X:0.000000 Y:0.000000 Z:0.000000
Can anyone help?
Reply
#2

Take out those return 0s.
Reply
#3

I just did that, nothing has changed.
Reply
#4

Check if you have forgotten to make the path folder
Reply
#5

Path folder is there, because that's where the SaveVehicle function saves the car without problem.
I even checked the .ini file, all the data is correctly saved.
Reply
#6

pawn Код:
new cModel, Float:Cx, Float:Cy, Float:Cz, Float:CAngle, CColor1, CColor2;
INI_Int("Model", cModel);
INI_Float("x", Float:Cx);
INI_Float("y", Float:Cy);
INI_Float("z", Float:Cz);
INI_Float("fa", Float:CAngle);
INI_Int("color1", CColor1);
INI_Int("color2", CColor2);
printf("Loading car data: Model %i, Positions: %f %f %f, Angle %f", cModel, Cx, Cy, Cz, CAngle);
gives me
Код:
Loading car data: Model 0, Positions: 0.000000 0.000000 0.000000, Angle 0.000000
The data doesn't even seem to load in correctly.

Related function:

pawn Код:
stock LoadAllVehicles()
{
    new fname[36];
    new index = 1;
    format(fname, sizeof(fname), "/POV/%i.ini", index);
    while(fexist(fname))
    {
        format(fname, sizeof(fname), "/POV/%i.ini", index);
        INI_ParseFile(fname, "LoadVehicles");
        printf("Loading file %s", fname);
        index++;
    }
}
The .ini file it's supposedly loading:

Код:
[data]
Model = 546
x = 1659.910522
y = -1891.801757
z = 13.330147
fa = 0.041964
color1 = 1
color2 = 1
locked = 0
EDIT: I've removed the filename[36] argument from the function, and I've added another printf messages.
pawn Код:
forward LoadVehicles(name[], value[]);
public LoadVehicles(name[], value[])
{
    new cModel, Float:Cx, Float:Cy, Float:Cz, Float:CAngle, CColor1, CColor2;
    printf("Loading Name:%s Value:%s", name, value);
    INI_Int("Model", cModel);
    INI_Float("x", Float:Cx);
    INI_Float("y", Float:Cy);
    INI_Float("z", Float:Cz);
    INI_Float("fa", Float:CAngle);
    INI_Int("color1", CColor1);
    INI_Int("color2", CColor2);
    printf("Loading car data: Model %i, Positions: %f %f %f, Angle %f", cModel, Cx, Cy, Cz, CAngle);
    new LoadedCar = CreateVehicleEx(cModel, Float:Cx, Float:Cy, Float:Cz, Float:CAngle, CColor1, CColor2);
    vInfo[LoadedCar][Model] = cModel;
    vInfo[LoadedCar][vPos_x] = Float:Cx;
    vInfo[LoadedCar][vPos_y] = Float:Cy;
    vInfo[LoadedCar][vPos_z] = Float:Cz;
    vInfo[LoadedCar][vAngle] = Float:CAngle;
    vInfo[LoadedCar][vcolor1] = CColor1;
    vInfo[LoadedCar][vcolor2] = CColor2;
    printf("Spawning Player Owned Vehicle Model %i at X = %f Y = %f Z = %f", cModel, Float:Cx, Float:Cy, Float:Cz);
   
    return 1;
}
This returns
Код:
[16:54:45] Loading Name:Model Value:466
[16:54:45] Loading Name:x Value:1655.299804
[16:54:45] Loading Name:y Value:-1880.500000
[16:54:45] Loading Name:z Value:13.370150
[16:54:45] Loading Name:fa Value:0.000000
[16:54:45] Loading Name:color1 Value:1
[16:54:45] Loading Name:color2 Value:1
[16:54:45] Loading Name:locked Value:0
[16:54:45] Loading car data: Model 0, Positions: 0.000000 0.000000 0.000000, Angle 0.000000
Strangely enough, the data which is being read, won't save into the variables cModel, Cx, Cy, Cz, CAngle, CColor1 and CColor2.

Is there a workaround for this or am I doing something wrong?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)