Stock creates the file but can't read it
#6

I have scripted a y_ini version of this system because the method you are using is very outdated and slow.

The system I have scripted will print out the amount of cars loaded and will also use seperate files for every vehicle.

Be sure to create a folder named "Dealership" in your scriptfiles folder. The data will be saved in it.

If you don't want to lose the cars you created with your old system, load them with your old system and save them with this system. After you saved them, import the new loading system in your script, and start the server.

Here's the code:

PHP код:
#include <YSI/y_ini> // On the top of your script
stock LoadDealershipCars()
{
    new 
string[144], count 0;
    
    for(new 
0MAX_DVEHICLESi++) // Loop the vehicles
    
{
        
format(stringsizeof(string), "Dealership/Car_%d.ini"i); // Format the string with the car's ID
        
        
if(fexist(string))
        {
            
INI_ParseFile(string"LoadVehicle_%s", .bExtra true, .extra i); // Loads the vehicle's data from the file
               
            
vehicle CreateVehicle(VehicleStatistics[i][vehicle_model], VehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], VehicleStatistics[i][vehicle_position][4], 00, -1);
            
format(stringsizeof(string), "{91D593}This Vehicle is for sale\nModel:%s\nPrice:$%d\n{FFBE63}Enter the vehicle to buy it"GetVehicleName(vehicle), VehicleStatistics[i][vehicle_price]);
            
VehicleStatistics[i][vehicle_label] = Create3DTextLabel(stringCOLOR_BDOVehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], 10.00);
            
count++;
        }
    }
    
printf("Loaded %d dealership cars."count); // Will print the number of cars loaded
    
return 1;
}
forward LoadVehicle_data(vehicleid,name[],value[]);
public 
LoadVehicle_data(vehicleid,name[],value[])
{
    
INI_Int(File"Model"VehicleStatistics[vehicleid][vehicle_model]);
    
INI_Int(File"Price"VehicleStatistics[vehicleid][vehicle_price]);
    
INI_Float(File"PosX"VehicleStatistics[vehicleid][vehicle_position][1]);
    
INI_Float(File"PosY"VehicleStatistics[vehicleid][vehicle_position][2]);
    
INI_Float(File"PosZ"VehicleStatistics[vehicleid][vehicle_position][3]);
    
INI_Float(File"PosA"VehicleStatistics[vehicleid][vehicle_position][4]);
    
INI_Int(File"OnSale"VehicleStatistics[vehicleid][vehicle_onsale]);
    return 
1;
}
stock SaveDealershipCars()
{
    new 
filestring[64];
    
    for(new 
0idx = -1MAX_DVEHICLESi++) // Loop through the cars
    
{
        if(
VehicleStatistics[i][vehicle_model] < 400) continue; // Checking if the slot isn't taken (if it isn't, 'continue' to the next iteration), you can use another variable if you wish
        
idx++;
        
        
format(filestringsizeof(filestring), "Dealership/Car_%d.ini"idx); 
        new 
INI:File INI_Open(filestring); // Open the file
        
INI_SetTag(File,"data");
        
        
INI_WriteInt(File"Model"VehicleStatistics[i][vehicle_model]);
        
INI_WriteInt(File"Price"VehicleStatistics[i][vehicle_price]);
        
INI_WriteFloat(File"PosX"VehicleStatistics[i][vehicle_position][1]);
        
INI_WriteFloat(File"PosY"VehicleStatistics[i][vehicle_position][2]);
        
INI_WriteFloat(File"PosZ"VehicleStatistics[i][vehicle_position][3]);
        
INI_WriteFloat(File"PosA"VehicleStatistics[i][vehicle_position][4]);
        
INI_WriteInt(File"OnSale"VehicleStatistics[i][vehicle_onsale]);
        
        
INI_Close(File); // Close the files
    
}
    print(
"Dealership cars saved successfully.");
    return 
1;

Be aware though, I haven't tested this. If you get any errors, please post them.

I just realized your location says DEFQON.1... Hardstyle for life mate!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)