stock LoadDealershipCars()
{
new dcar[7][32];
new string[256], vehicle;
new File:file = fopen("dealershipcars.cfg", io_read);
if(file)
{
new i = 1;
while(i < MAX_DVEHICLES)
{
fread(file, string);
split(string, dcar, '|');
VehicleStatistics[i][vehicle_model] = strval(dcar[0]);
VehicleStatistics[i][vehicle_price] = strval(dcar[1]);
VehicleStatistics[i][vehicle_position][1] = floatstr(dcar[2]);
VehicleStatistics[i][vehicle_position][2] = floatstr(dcar[3]);
VehicleStatistics[i][vehicle_position][3] = floatstr(dcar[4]);
VehicleStatistics[i][vehicle_position][4] = floatstr(dcar[5]);
VehicleStatistics[i][vehicle_onsale] = strval(dcar[6]);
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], 0, 0, -1);
format(string, sizeof(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(string, COLOR_BDO, VehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], 10.0, 0);
i++;
}
}
print("Dealership Cars loaded successfully.");
return 1;
}
stock SaveDealershipCars()
{
new i = 1, File:file;
new string[256];
while(i < MAX_DVEHICLES)
{
format(string, sizeof(string), "%d|%d|%f|%f|%f|%f|%d\r\n",
VehicleStatistics[i][vehicle_model],
VehicleStatistics[i][vehicle_price],
VehicleStatistics[i][vehicle_position][1],
VehicleStatistics[i][vehicle_position][2],
VehicleStatistics[i][vehicle_position][3],
VehicleStatistics[i][vehicle_position][4],
VehicleStatistics[i][vehicle_onsale]);
if(i == 1)
{
file = fopen("dealershipcars.cfg", io_write);
}
else
{
file = fopen("dealershipcars.cfg", io_append);
}
fwrite(file, string);
fclose(file);
i++;
}
print("Dealership Cars saved successfully.");
}
[14:31:47] Houses loaded successfully. // Dealership Cars loaded successfully. "should appear here but it doesn't" [14:31:47] ---------------------------------- [14:31:47] | My Roleplay Server | [14:31:47] ---------------------------------- [14:31:47] | Created by Adam Hardy - Penguin | [14:31:47] ---------------------------------- [14:31:47] Number of vehicle models: 6
while(fread(file, string) && i < MAX_DVEHICLES)
stock LoadDealershipCars()
{
new dcar[7][32];
new string[256], vehicle;
new File:file = fopen("dealershipcars.cfg", io_read);
if(file)
{
new i = 1;
while(fread(file, string) && i < MAX_DVEHICLES)
{
split(string, dcar, '|');
VehicleStatistics[i][vehicle_model] = strval(dcar[0]);
VehicleStatistics[i][vehicle_price] = strval(dcar[1]);
VehicleStatistics[i][vehicle_position][1] = floatstr(dcar[2]);
VehicleStatistics[i][vehicle_position][2] = floatstr(dcar[3]);
VehicleStatistics[i][vehicle_position][3] = floatstr(dcar[4]);
VehicleStatistics[i][vehicle_position][4] = floatstr(dcar[5]);
VehicleStatistics[i][vehicle_onsale] = strval(dcar[6]);
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], 0, 0, -1);
format(string, sizeof(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(string, COLOR_BDO, VehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], 10.0, 0);
i++;
}
fclose(file);
}
print("Dealership Cars loaded successfully.");
return 1;
}
stock SaveDealershipCars()
{
new i = 0, File:file;
new string[256];
while(fread(file, string) && i < MAX_DVEHICLES)
{
format(string, sizeof(string), "%d|%d|%f|%f|%f|%f|%d\r\n",
VehicleStatistics[i][vehicle_model],
VehicleStatistics[i][vehicle_price],
VehicleStatistics[i][vehicle_position][1],
VehicleStatistics[i][vehicle_position][2],
VehicleStatistics[i][vehicle_position][3],
VehicleStatistics[i][vehicle_position][4],
VehicleStatistics[i][vehicle_onsale]);
if(i == 0)
{
file = fopen("dealershipcars.cfg", io_write);
}
else
{
file = fopen("dealershipcars.cfg", io_append);
}
fwrite(file, string);
i++;
}
fclose(file);
print("Dealership Cars saved successfully.");
}
#include <YSI/y_ini> // On the top of your script
stock LoadDealershipCars()
{
new string[144], count = 0;
for(new i = 0; i < MAX_DVEHICLES; i++) // Loop the vehicles
{
format(string, sizeof(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], 0, 0, -1);
format(string, sizeof(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(string, COLOR_BDO, VehicleStatistics[i][vehicle_position][1], VehicleStatistics[i][vehicle_position][2], VehicleStatistics[i][vehicle_position][3], 10.0, 0);
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 i = 0, idx = -1; i < MAX_DVEHICLES; i++) // 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(filestring, sizeof(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;
}
|
Well tbh I did not want to use YSI on my gamemode because I will have to change many other things, can it work the same version I had it? If so can you show me how? Thanks and +rep if you do.
|
|
Oh dang I just noticed the Hardstyle reply, thank you lol I'm in dead love with Hardstyle for 10 years xD Welcome back Heady <3
You didn't define File in the public function. |
forward LoadVehicle_data(vehicleid,name[],value[]);
public LoadVehicle_data(vehicleid,name[],value[])
{
INI_Int("Model", VehicleStatistics[vehicleid][vehicle_model]);
INI_Int("Price", VehicleStatistics[vehicleid][vehicle_price]);
INI_Float("PosX", VehicleStatistics[vehicleid][vehicle_position][1]);
INI_Float("PosY", VehicleStatistics[vehicleid][vehicle_position][2]);
INI_Float("PosZ", VehicleStatistics[vehicleid][vehicle_position][3]);
INI_Float("PosA", VehicleStatistics[vehicleid][vehicle_position][4]);
INI_Int("OnSale", VehicleStatistics[vehicleid][vehicle_onsale]);
return 1;
}