Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HouseFile_Load(HouseID, bool:LoadVehicles = true) {
- new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
- new cModel, cPaint, components[14], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, vid, bool:VehicleClamped, cFuel = -1;
- format(file, sizeof(file), HouseFile, HouseID);
- if(fexist(file)) {
- HFile = fopen(file, io_read);
- fread(HFile, LineFromFile);
- AHouseData[HouseID][HouseOpened] = false;
- while(strlen(LineFromFile) > 0) {
- StripNewLine(LineFromFile);
- sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue);
- switch(LoadVehicles) {
- case true: {
- if (strcmp(ParameterName, "HouseName", false) == 0) // If the parametername is correct ("HouseName")
- format(AHouseData[HouseID][HouseName], 24, ParameterValue); // Store the HouseName
- if (strcmp(ParameterName, "HouseX", false) == 0) // If the parametername is correct ("HouseX")
- AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
- if (strcmp(ParameterName, "HouseY", false) == 0) // If the parametername is correct ("HouseY")
- AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
- if (strcmp(ParameterName, "HouseZ", false) == 0) // If the parametername is correct ("HouseZ")
- AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
- if (strcmp(ParameterName, "HouseLevel", false) == 0) // If the parametername is correct ("HouseLevel")
- AHouseData[HouseID][HouseLevel] = strval(ParameterValue); // Store the HouseLevel
- if (strcmp(ParameterName, "HouseMaxLevel", false) == 0) // If the parametername is correct ("HouseMaxLevel")
- AHouseData[HouseID][HouseMaxLevel] = strval(ParameterValue); // Store the HouseMaxLevel
- if (strcmp(ParameterName, "HousePrice", false) == 0) // If the parametername is correct ("HousePrice")
- AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
- if (strcmp(ParameterName, "Localidade", false) == 0) // If the parametername is correct ("HouseName")
- format(AHouseData[HouseID][Localidade], 24, ParameterValue);
- if (strcmp(ParameterName, "VehiclesPassword", false) == 0) // If the parametername is correct ("VehiclesPassword")
- format(AHouseData[HouseID][VehiclesPassword], 16, ParameterValue); // Store the VehiclesPassword
- if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
- {
- if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
- AHouseData[HouseID][Owned] = true; // House is owned
- else
- AHouseData[HouseID][Owned] = false; // House is not owned
- }
- if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
- // Store the Owner (Owner will hold "1" if there is no owner (empty string), done by "sscanf" I guess)
- // But this doesn't matter, as the owner will never be displayed when the house is not owned by someone
- format(AHouseData[HouseID][Owner], 24, ParameterValue);
- if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
- AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
- if (strcmp(ParameterName, "[Vehicle]", false) == 0) // If the parametername is correct ("[Vehicle]")
- {
- // Clear all data to start a new vehicle
- cModel = 0;
- cPaint = 0;
- cFuel = -1;
- for (new i; i < 14; i++)
- components[i] = 0;
- }
- if (strcmp(ParameterName, "VehicleModel", false) == 0) // If the parametername is correct ("VehicleModel")
- cModel = strval(ParameterValue); // Store the VehicleModel
- if (strcmp(ParameterName, "Fuel", false) == 0) // If the parametername is correct ("Fuel")
- cFuel = strval(ParameterValue); // Store the Fuel
- if (strcmp(ParameterName, "VehiclePaintJob", false) == 0) // If the parametername is correct ("VehiclePaintJob")
- cPaint = strval(ParameterValue); // Store the VehiclePaintJob
- if (strcmp(ParameterName, "VehicleSpoiler", false) == 0) // If the parametername is correct ("VehicleSpoiler")
- components[0] = strval(ParameterValue); // Store the VehicleSpoiler
- if (strcmp(ParameterName, "VehicleHood", false) == 0) // If the parametername is correct ("VehicleHood")
- components[1] = strval(ParameterValue); // Store the VehicleHood
- if (strcmp(ParameterName, "VehicleRoof", false) == 0) // If the parametername is correct ("VehicleRoof")
- components[2] = strval(ParameterValue); // Store the VehicleRoof
- if (strcmp(ParameterName, "VehicleSideSkirt", false) == 0) // If the parametername is correct ("VehicleSideSkirt")
- components[3] = strval(ParameterValue); // Store the VehicleSideSkirt
- if (strcmp(ParameterName, "VehicleLamps", false) == 0) // If the parametername is correct ("VehicleLamps")
- components[4] = strval(ParameterValue); // Store the VehicleLamps
- if (strcmp(ParameterName, "VehicleNitro", false) == 0) // If the parametername is correct ("VehicleNitro")
- components[5] = strval(ParameterValue); // Store the VehicleNitro
- if (strcmp(ParameterName, "VehicleExhaust", false) == 0) // If the parametername is correct ("VehicleExhaust")
- components[6] = strval(ParameterValue); // Store the VehicleExhaust
- if (strcmp(ParameterName, "VehicleWheels", false) == 0) // If the parametername is correct ("VehicleWheels")
- components[7] = strval(ParameterValue); // Store the VehicleWheels
- if (strcmp(ParameterName, "VehicleStereo", false) == 0) // If the parametername is correct ("VehicleStereo")
- components[8] = strval(ParameterValue); // Store the VehicleStereo
- if (strcmp(ParameterName, "VehicleHydraulics", false) == 0) // If the parametername is correct ("VehicleHydraulics")
- components[9] = strval(ParameterValue); // Store the VehicleHydraulics
- if (strcmp(ParameterName, "VehicleFrontBumper", false) == 0) // If the parametername is correct ("VehicleFrontBumper")
- components[10] = strval(ParameterValue); // Store the VehicleFrontBumper
- if (strcmp(ParameterName, "VehicleRearBumper", false) == 0) // If the parametername is correct ("VehicleRearBumper")
- components[11] = strval(ParameterValue); // Store the VehicleRearBumper
- if (strcmp(ParameterName, "VehicleVentRight", false) == 0) // If the parametername is correct ("VehicleVentRight")
- components[12] = strval(ParameterValue); // Store the VehicleVentRight
- if (strcmp(ParameterName, "VehicleVentLeft", false) == 0) // If the parametername is correct ("VehicleVentLeft")
- components[13] = strval(ParameterValue); // Store the VehicleVentLeft
- if (strcmp(ParameterName, "Color1", false) == 0) // If the parametername is correct ("Color1")
- Col1 = strval(ParameterValue); // Store the Color1
- if (strcmp(ParameterName, "Color2", false) == 0) // If the parametername is correct ("Color2")
- Col2 = strval(ParameterValue); // Store the Color2
- if (strcmp(ParameterName, "VehicleX", false) == 0) // If the parametername is correct ("VehicleX")
- cx = floatstr(ParameterValue); // Store the VehicleX
- if (strcmp(ParameterName, "VehicleY", false) == 0) // If the parametername is correct ("VehicleY")
- cy = floatstr(ParameterValue); // Store the VehicleY
- if (strcmp(ParameterName, "VehicleZ", false) == 0) // If the parametername is correct ("VehicleZ")
- cz = floatstr(ParameterValue); // Store the VehicleZ
- if (strcmp(ParameterName, "VehicleAngle", false) == 0) // If the parametername is correct ("VehicleAngle")
- crot = floatstr(ParameterValue); // Store the VehicleAngle
- if (strcmp(ParameterName, "Clamped", false) == 0) // If the parametername is correct ("Clamped")
- {
- if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
- VehicleClamped = true; // Vehicle is clamped
- else
- VehicleClamped = false; // Vehicle is not clamped
- }
- if (strcmp(ParameterName, "[/Vehicle]", false) == 0) // If the parametername is correct ("[/Vehicle]")
- {
- // Set both colors to 1 if they are 0 AND if there is a paintjob applied
- if ((Col1 == 0) && (cPaint != 0))
- Col1 = 1;
- if ((Col2 == 0) && (cPaint != 0))
- Col2 = 1;
- // The "[/Vehicle]" is found, this means that all data about this vehicle is now stored in the variables
- // Now add the vehicle to the house and set it's data
- vid = House_AddVehicle(HouseID, cModel, cPaint, components, cx, cy, cz, crot, Col1, Col2);
- AVehicleData[vid][Clamped] = VehicleClamped;
- // Also set the fuel (set it to maximum when the fuel parameter wasn't inside the file)
- if (cFuel == -1)
- AVehicleData[vid][Fuel] = MaxFuel;
- else
- AVehicleData[vid][Fuel] = cFuel;
- format(AVehicleData[vid][VehiclePass], 16, "%s", AHouseData[HouseID][VehiclesPassword]);
- }
- }
- }
- fread(HFile, LineFromFile);
- }
- if(AHouseData[HouseID][HouseMaxLevel] == 1) { AHouseData[HouseID][HouseMaxLevel] = 10; }
- fclose(HFile);
- return true;
- }
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment