Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- PickupID,
- Text3DoorText,
- MapIconID,
- HouseName[100],
- Insurance,
- Float:HouseX,
- Float:HouseY,
- Float:HouseZ,
- HouseLevel,
- HouseMaxLevel,
- HousePrice,
- bool:Owned,
- Owner[24],
- PassCar[100],
- bool:HouseOpened,
- VehicleIDs[10],
- UltimoLogin[30]
- }
- new AHouseData[MAX_HOUSES][THouseData];
- HouseFile_Load(HouseID, bool:OnlyLoadVehicles = false)
- {
- new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
- // Setup local variables
- 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); // Construct the complete filename for this house-file
- if (fexist(file))
- {
- HFile = fopen(file, io_read); // Open the housefile for reading
- fread(HFile, LineFromFile); // Read the first line of the file
- // Set the house so it cannot be entered by anyone, except the owner (close the house)
- AHouseData[HouseID][HouseOpened] = false;
- // Keep reading until the end of the file is found (no more data)
- while (strlen(LineFromFile) > 0)
- {
- StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
- sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
- // If OnlyLoadVehicles is "false", only load the house-data
- // If OnlyLoadVehicles is "true", only load the vehicle-data
- if (OnlyLoadVehicles == false)
- {
- // Store the proper value in the proper place
- 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, "PassCar", false) == 0) // If the parametername is correct ("PassCar")
- format(AHouseData[HouseID][PassCar], 24, ParameterValue); // Store the PassCar
- 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, "UltimoLogin", false) == 0) // Ultimo Locin Casa
- format(AHouseData[HouseID][UltimoLogin], 30, ParameterValue); // Ultimo Login Casa
- if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
- AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
- }
- else // OnlyLoadVehicles is "true", so only read the vehicle-data
- {
- 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 // If the parameter was there, store it
- AVehicleData[vid][Fuel] = cFuel;
- }
- }
- // Read the next line of the file
- fread(HFile, LineFromFile);
- }
- // Check if the maximum house-level isn't 0 (when updating to the new version)
- if (AHouseData[HouseID][HouseMaxLevel] == 0)
- AHouseData[HouseID][HouseMaxLevel] = 10; // Set the maximum level to 10
- // Close the file
- fclose(HFile);
- // Return if the file was read correctly
- return 1;
- }
- else
- return 0; // Return 0 if the file couldn't be read (doesn't exist)
- }
- HouseFile_Save(HouseID)
- {
- new file[100], File:HFile, LineForFile[100], vid;
- // Construct the complete filename for this house
- format(file, sizeof(file), HouseFile, HouseID);
- HFile = fopen(file, io_write); // Open the playerfile for writing
- format(LineForFile, 100, "HouseName %s\r\n", AHouseData[HouseID][HouseName]); // Construct the line: "HouseName <HouseName>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "HouseX %f\r\n", AHouseData[HouseID][HouseX]); // Construct the line: "HouseX <HouseX>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "HouseY %f\r\n", AHouseData[HouseID][HouseY]); // Construct the line: "HouseY <HouseY>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "HouseZ %f\r\n", AHouseData[HouseID][HouseZ]); // Construct the line: "HouseZ <HouseZ>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "HouseLevel %i\r\n", AHouseData[HouseID][HouseLevel]); // Construct the line: "HouseLevel <HouseLevel>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "HouseMaxLevel %i\r\n", AHouseData[HouseID][HouseMaxLevel]); // Construct the line: "HouseMaxLevel <HouseMaxLevel>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "HousePrice %i\r\n", AHouseData[HouseID][HousePrice]); // Construct the line: "HousePrice <HousePrice>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "PassCar %s\r\n", AHouseData[HouseID][PassCar]); // Construct the line: "PassCar <PassCar>"
- fwrite(HFile, LineForFile); // And save it to the file
- if (AHouseData[HouseID][Owned] == true) // Check if the house is owned
- {
- format(LineForFile, 100, "Owned Yes\r\n"); // Construct the line: "Owned Yes"
- fwrite(HFile, LineForFile); // And save it to the file
- }
- else
- {
- format(LineForFile, 100, "Owned No\r\n"); // Construct the line: "Owned No"
- fwrite(HFile, LineForFile); // And save it to the file
- }
- format(LineForFile, 100, "Owner %s\r\n", AHouseData[HouseID][Owner]); // Construct the line: "Owner <Owner>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "UltimoLogin %s\r\n", AHouseData[HouseID][UltimoLogin]); // Construct the line: "Owner <Owner>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "Insurance %i\r\n", AHouseData[HouseID][Insurance]); // Construct the line: "Insurance <Insurance>"
- fwrite(HFile, LineForFile); // And save it to the file
- // Save the vehicle-data for every vehicle added to the house
- for (new CarSlot; CarSlot < 10; CarSlot++)
- {
- // If a valid vehicle-id has been found
- if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
- {
- // Get the vehicle id
- vid = AHouseData[HouseID][VehicleIDs][CarSlot];
- format(LineForFile, 100, "[Vehicle]\r\n"); // Construct the line: "[Vehicle]"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleModel %i\r\n", AVehicleData[vid][Model]); // Construct the line: "VehicleModel <VehicleModel>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "Fuel %i\r\n", AVehicleData[vid][Fuel]); // Construct the line: "Fuel <Fuel>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehiclePaintJob %i\r\n", AVehicleData[vid][PaintJob]); // Construct the line: "VehiclePaintJob <VehiclePaintJob>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleSpoiler %i\r\n", AVehicleData[vid][Components][0]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleHood %i\r\n", AVehicleData[vid][Components][1]); // Construct the line: "VehicleHood <VehicleHood>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleRoof %i\r\n", AVehicleData[vid][Components][2]); // Construct the line: "VehicleRoof <VehicleRoof>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleSideSkirt %i\r\n", AVehicleData[vid][Components][3]); // Construct the line: "VehicleSideSkirt <VehicleSideSkirt>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleLamps %i\r\n", AVehicleData[vid][Components][4]); // Construct the line: "VehicleLamps <VehicleLamps>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleNitro %i\r\n", AVehicleData[vid][Components][5]); // Construct the line: "VehicleNitro <VehicleNitro>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleExhaust %i\r\n", AVehicleData[vid][Components][6]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleWheels %i\r\n", AVehicleData[vid][Components][7]); // Construct the line: "VehicleWheels <VehicleWheels>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleStereo %i\r\n", AVehicleData[vid][Components][8]); // Construct the line: "VehicleStereo <VehicleStereo>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleHydraulics %i\r\n", AVehicleData[vid][Components][9]); // Construct the line: "VehicleHydraulics <VehicleHydraulics>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleFrontBumper %i\r\n", AVehicleData[vid][Components][10]); // Construct the line: "VehicleFrontBumper <VehicleFrontBumper>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleRearBumper %i\r\n", AVehicleData[vid][Components][11]); // Construct the line: "VehicleRearBumper <VehicleRearBumper>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleVentRight %i\r\n", AVehicleData[vid][Components][12]); // Construct the line: "VehicleVentRight <VehicleVentRight>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleVentLeft %i\r\n", AVehicleData[vid][Components][13]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "Color1 %i\r\n", AVehicleData[vid][Color1]); // Construct the line: "Color1 <Color1>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "Color2 %i\r\n", AVehicleData[vid][Color2]); // Construct the line: "Color2 <Color2>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleX %f\r\n", AVehicleData[vid][SpawnX]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleY %f\r\n", AVehicleData[vid][SpawnY]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleZ %f\r\n", AVehicleData[vid][SpawnZ]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "VehicleAngle %f\r\n", AVehicleData[vid][SpawnRot]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
- fwrite(HFile, LineForFile); // And save it to the file
- if (AVehicleData[vid][Clamped] == true)
- format(LineForFile, 100, "Clamped Yes\r\n"); // Construct the line: "Clamped <Yes>"
- else
- format(LineForFile, 100, "Clamped No\r\n"); // Construct the line: "Clamped <No>"
- fwrite(HFile, LineForFile); // And save it to the file
- format(LineForFile, 100, "[/Vehicle]\r\n"); // Construct the line: "[/Vehicle]"
- fwrite(HFile, LineForFile); // And save it to the file
- }
- }
- fclose(HFile); // Close the file
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement