Component IDs from file aren't loading into the enums, but save from the enums.
#1

Well, I've been trying to get help for ages but no one can seem to help me. It's a really complicated screwed up problem, and if someone fixes it, it'll amaze me in every way possible.

Here's the Load and Save function for my cars:
pawn Код:
//==============================================================================
public LoadCar()
{
    new arrCoords[30][64];
    new strFromFile2[256];
    new File: file = fopen("dealership.cfg", io_read);
    if (file)
    {
        new idx = 0;
        while (idx < sizeof(CarInfo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, ',');
            CarInfo[idx][vModel] = strval(arrCoords[0]);
            CarInfo[idx][vLocationx] = floatstr(arrCoords[1]);
            CarInfo[idx][vLocationy] = floatstr(arrCoords[2]);
            CarInfo[idx][vLocationz] = floatstr(arrCoords[3]);
            CarInfo[idx][vAngle] = floatstr(arrCoords[4]);
            CarInfo[idx][vColorOne] = strval(arrCoords[5]);
            CarInfo[idx][vColorTwo] = strval(arrCoords[6]);
            strmid(CarInfo[idx][vOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
            strmid(CarInfo[idx][vDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            CarInfo[idx][vValue] = strval(arrCoords[9]);
            CarInfo[idx][vLicense] = strval(arrCoords[10]);
            CarInfo[idx][vOwned] = strval(arrCoords[11]);
            CarInfo[idx][vLock] = strval(arrCoords[12]);
            CarInfo[idx][vMod1] = strval(arrCoords[13]);
            CarInfo[idx][vMod2] = strval(arrCoords[14]);
            CarInfo[idx][vMod3] = strval(arrCoords[15]);
            CarInfo[idx][vMod4] = strval(arrCoords[16]);
            CarInfo[idx][vMod5] = strval(arrCoords[17]);
            CarInfo[idx][vMod6] = strval(arrCoords[18]);
            CarInfo[idx][vMod7] = strval(arrCoords[19]);
            CarInfo[idx][vMod8] = strval(arrCoords[20]);
            CarInfo[idx][vMod9] = strval(arrCoords[21]);
            CarInfo[idx][vMod10] = strval(arrCoords[22]);
            CarInfo[idx][vMod11] = strval(arrCoords[23]);
            CarInfo[idx][vMod12] = strval(arrCoords[24]);
            CarInfo[idx][vMod13] = strval(arrCoords[25]);
            CarInfo[idx][vMod14] = strval(arrCoords[26]);
            CarInfo[idx][vMod15] = strval(arrCoords[27]);
            CarInfo[idx][vMod16] = strval(arrCoords[28]);
            CarInfo[idx][vMod17] = strval(arrCoords[29]);
            CarInfo[idx][ownedvehicle] = CreateVehicle(CarInfo[idx][vModel],CarInfo[idx][vLocationx],CarInfo[idx][vLocationy],CarInfo[idx][vLocationz],CarInfo[idx][vAngle],CarInfo[idx][vColorOne],CarInfo[idx][vColorTwo],300000);
            printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][vOwner],CarInfo[idx][vLicense]);
            idx++;
        }
    }
    return 1;
}
//==============================================================================
public SaveCars()
{
    new idx;
    new File: file2;
    while (idx < sizeof(CarInfo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\n",
        CarInfo[idx][vModel],
        CarInfo[idx][vLocationx],
        CarInfo[idx][vLocationy],
        CarInfo[idx][vLocationz],
        CarInfo[idx][vAngle],
        CarInfo[idx][vColorOne],
        CarInfo[idx][vColorTwo],
        CarInfo[idx][vOwner],
        CarInfo[idx][vDescription],
        CarInfo[idx][vValue],
        CarInfo[idx][vLicense],
        CarInfo[idx][vOwned],
        CarInfo[idx][vLock],
        CarInfo[idx][vMod1],
        CarInfo[idx][vMod2],
        CarInfo[idx][vMod3],
        CarInfo[idx][vMod4],
        CarInfo[idx][vMod5],
        CarInfo[idx][vMod6],
        CarInfo[idx][vMod7],
        CarInfo[idx][vMod8],
        CarInfo[idx][vMod9],
        CarInfo[idx][vMod10],
        CarInfo[idx][vMod11],
        CarInfo[idx][vMod12],
        CarInfo[idx][vMod13],
        CarInfo[idx][vMod14],
        CarInfo[idx][vMod15],
        CarInfo[idx][vMod16],
        CarInfo[idx][vMod17]);
        if(idx == 0)
        {
            file2 = fopen("dealership.cfg", io_write);
        }
        else
        {
            file2 = fopen("dealership.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}
//==============================================================================

Right now, see how it loads the info into enums? Yes, well here are therse enums:
pawn Код:
enum vInfo
{
    vModel,
    Float:vLocationx,
    Float:vLocationy,
    Float:vLocationz,
    Float:vAngle,
    vColorOne,
    vColorTwo,
    vOwner[MAX_PLAYER_NAME],
    vDescription[MAX_PLAYER_NAME],
    vValue,
    vLicense,
    vRegistration,
    vOwned,
    vLock,
    ownedvehicle,
    vMod1,
    vMod2,
    vMod3,
    vMod4,
    vMod5,
    vMod6,
    vMod7,
    vMod8,
    vMod9,
    vMod10,
    vMod11,
    vMod12,
    vMod13,
    vMod14,
    vMod15,
    vMod16,
    vMod17
   
};
new CarInfo[200][vInfo];
Okay, now this is what happens. Everything in the LoadCar function loads into the enums apart from the component ids (line 9 - 29).. let's look at an example of a line that has saved with component ids in it.
Код:
560,-2705.624267,224.065734,3.844985,189.970138,0,0,Louis,,20000,,1,0,1139,1009,1169,1141,1028,0,0,0,1032,1026,0,1087,1086,0,0,1079,0,
So we can tell the component IDs are saved right? And the information is gathered from the enum, but the problem is, whilst in-game and the server is running, the enums are "0", but then they save as the appropriate component ID, weird huh? Very weird.

Why are they loading into the enum as "0" but save as the correct component ID?

Another weird thing is, every time I mod the car, and then when the server shuts down (which is when SaveCar function does it's thing), the component IDs update.

Then, when the server starts up, like I said, it loads as 0, but then it saves as e.g. 1312 even though it gathered that information from the Enum that I'm trying to Load the component Ids into.

Ahh, ind f**ked. someone help me please!
Reply
#2

First try doing a debug to see if the file opens at all.
Reply
#3

Yes, like I said, everything else in the Load function loads, because the cars create.

And I do have a debug, see:
Код:
printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][vOwner],CarInfo[idx][vLicense]);
Reply
#4

Oh well fine.
So the cars create, but the mods don't load...
I guess you should use AddVehicleComponent
Reply
#5

This is on OnVechileSpawn:
pawn Код:
for(new i = 0; i < sizeof(CarInfo); i++)
        {
            if(CarInfo[i][ownedvehicle] == vehicleid)
            {
                ChangeVehicleColor(CarInfo[i][ownedvehicle],CarInfo[i][vColorOne],CarInfo[i][vColorTwo]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod1]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod2]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod3]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod4]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod5]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod6]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod7]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod8]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod9]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod10]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod11]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod12]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod13]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod14]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod15]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod16]);
                AddVehicleComponent(CarInfo[i][ownedvehicle],CarInfo[i][vMod17]);
            }
        }
Problem is in the loadcar function, they load as 0. not their component id e.g. 1232
Reply
#6

At the top of ur GM:
pawn Код:
#define MAX_CARS 200
And try replacing
pawn Код:
for(new i = 0; i < MAX_CARS; i++)
I'm not sure, but maybe it could work out
Reply
#7

Respawn vehicles again if you're using OnVehicleSpawn.
Reply
#8

Quote:
Originally Posted by Delux13
Посмотреть сообщение
At the top of ur GM:
pawn Код:
#define MAX_CARS 200
And try replacing
pawn Код:
for(new i = 0; i < MAX_CARS; i++)
I'm not sure, but maybe it could work out
Nope. Everything else in the LoadCar function works, until we get to cMod1, then everything starts loading as "0", but it saves as the actual component ID.

EDIT:
@Riddick: like I said, component ids from the file are loading as 0, but when I mod a car and then the file saves, it saves as the component ID.

EDIT 2:
@Riddick, wow, some reason that worked, I love you :P thankyou!!!!!!!!!!!
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)