[HELP] Loading Vehicles
#1

Okay so, I'm working on a vehicle ownership system, and I got an issue with loading the vehicles.
Each vehicle has a file (VehX)
X is a number (if you format it, its Veh%d) I hope you get it..

Anyway, its a dynamic system, which means I can add & edit them in game by simple commands.
Lets say I got files, Veh1, Veh2, Veh3, Veh4
If I load them, its all good and works properly.
But if I would delete Veh2 and Veh3, then Veh1 loads properly, but not Veh4
If I add a vehicle (Not a file, just a vehicle) then it reads Veh4.. And thats the problem.. kinda

Thats how it works:
pawn Код:
public LoadVehicles()
{
    new file[128];
    for(new v = 1; v < MAX_VEHICLES; v++)
    {
        format(file, 128, "LVRP/Vehicles/Veh%d.ini", v);
        if(dini_Exists(file))
        {
            VehicleInfo[v][vID] = dini_Int(file, "ID");
            VehicleInfo[v][vSpawnx] = dini_Float(file, "Spawn_X");
            VehicleInfo[v][vSpawny] = dini_Float(file, "Spawn_Y");
            VehicleInfo[v][vSpawnz] = dini_Float(file, "Spawn_Z");
            VehicleInfo[v][vColor1] = dini_Int(file, "Color1");
            VehicleInfo[v][vColor2] = dini_Int(file, "Color2");
            VehicleInfo[v][vRotation] = dini_Float(file, "Rotation");
            VehicleInfo[v][vModel] = dini_Int(file, "Model");
            VehicleInfo[v][vAlarm] = dini_Int(file, "Alarm");
            VehicleInfo[v][vLock] = dini_Int(file, "Lock");
            VehicleInfo[v][vOwned] = dini_Int(file, "Owned");
            VehicleInfo[v][vInsurance] = dini_Int(file, "Insurance");
            VehicleInfo[v][vPrice] = dini_Int(file, "Price");
            VehicleInfo[v][vForSale] = dini_Int(file, "ForSale");
            VehicleInfo[v][vParkable] = dini_Int(file, "Parkable");
            VehicleInfo[v][vFuel] = dini_Int(file, "Fuel");
            VehicleInfo[v][vJob] = dini_Int(file, "Job");
            VehicleInfo[v][vCiv] = dini_Int(file, "Civ");
            VehicleInfo[v][vDTest] = dini_Int(file, "Test");
            VehicleInfo[v][vFaction] = dini_Int(file, "Faction");
            VehicleInfo[v][vWorld] = dini_Int(file, "World");
            VehicleInfo[v][vInterior] = dini_Int(file, "Interior");
            format(VehicleInfo[v][vOwner], MAX_PLAYER_NAME, "%s", dini_Get(file, "Owner"));
            format(VehicleInfo[v][vName], 128, "%s", dini_Get(file, "Name"));
            VehicleInfo[v][vTrade] = dini_Int(file, "Trade");
            VehicleInfo[v][vLocked] = dini_Int(file, "Locked");
            VehicleInfo[v][vDamage][0] = dini_Int(file, "Panels"), VehicleInfo[v][vDamage][1] = dini_Int(file, "Doors"), VehicleInfo[v][vDamage][2] = dini_Int(file, "Lights"), VehicleInfo[v][vDamage][3] = dini_Int(file, "Tires");
            //VehicleInfo[v][vID] = CreateVehicle(VehicleInfo[v][vModel], VehicleInfo[v][vSpawnx], VehicleInfo[v][vSpawny], VehicleInfo[v][vSpawnz],VehicleInfo[v][vRotation] , VehicleInfo[v][vColor1], VehicleInfo[v][vColor2],9999999999999);
            VehicleInfo[v][vID] = AddNewVehicle(VehicleInfo[v][vModel], VehicleInfo[v][vSpawnx], VehicleInfo[v][vSpawny], VehicleInfo[v][vSpawnz], VehicleInfo[v][vRotation] , VehicleInfo[v][vColor1], VehicleInfo[v][vColor2], VehicleInfo[v][vFaction], VehicleInfo[v][vJob]);
            SetVehicleVirtualWorld(v, VehicleInfo[v][vWorld]);
            SetVehicleInterior(v, VehicleInfo[v][vInterior]);
            SetVehicleToRespawn(v);
            UpdateVehicleDamageStatus(v, VehicleInfo[v][vDamage][0], VehicleInfo[v][vDamage][1], VehicleInfo[v][vDamage][2], VehicleInfo[v][vDamage][3]);
            VehicleInfo[v][vHealth] = dini_Float(file, "Health");
            SetVehicleHealth(v, VehicleInfo[v][vHealth]);
            if(VehicleInfo[v][vLocked])
            {
                LockCar(v);
            }
            else
            {
                UnlockCar(v);
            }
        }
    }
    return 1;
}
Reply
#2

Hmm, did you tried something like:

pawn Код:
if(dini_Exists(file))
{
  //Code
}
else continue;
Reply
#3

I just did, Its still the same :/
Reply
#4

where the delete part?
Reply
#5

What do you mean?
Reply
#6

The code to delete the car is what he means, that will probaly be good. But its good to check it out anyways.

What probaly happens is that when you delete a vehicle, it tries to load it. As its deleted it can't load it thats why it would PROBALY terminate the vehicle loading, and give an error that the log won't show you. I have no idea how to fix it though, lack of experience with Dini.
Reply
#7

YSF plugin needed.

pawn Код:
stock ReturnNextVehicleFileName()
{
    new filename[40], filepath[40], i, filenumber[40], lastint = 0000;
    while(ffind("LVRP/Vehicles/*", filename, 64, i)) {
        strmid(filenumber, filename, 3, 7);
        lastint = strval(filenumber)+1;
        format(filepath, sizeof(filepath), "LVRP/Vehicles/Veh%04d.ini", lastint);
        if(!dini_Exists(filepath)) return lastint;
    }
    return lastint;
}
And to read:

pawn Код:
new filename[40], i, filepath[128];
while(ffind("LVRP/Vehicles/*", filename, 64, i))
{
    format(filepath, sizeof(filepath), "LVRP/Vehicles/Veh%04d.ini", lastint);
    // This will loop through all the .INI files in the 'Vehicles' folder, use filepath for each vehicle starting from 0000 upwards.
    return lastint;
}
-Conroy
Reply
#8

error 017: undefined symbol "ffind"
error 017: undefined symbol "lastint"
error 017: undefined symbol "lastint"
Reply
#9

Quote:
Originally Posted by Conroy
Посмотреть сообщение
YSF plugin needed.
https://sampforum.blast.hk/showthread.php?tid=113485

And to read (fixed):

pawn Код:
new filename[40], i, filepath[128];
while(ffind("LVRP/Vehicles/*", filename, 64, i))
{
    format(filepath, sizeof(filepath), "LVRP/Vehicles/%s", filename);
    // This will loop through all the .INI files in the 'Vehicles' folder, use filepath for each vehicle starting from 0000 upwards.
}
-Conroy
Reply
#10

Is it for linux? I'm not using linux :X
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)