Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HouseFile_Load(HouseID)
- {
- // Setup local variables
- new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
- // Construct the complete filename for this house-file
- format(file, sizeof(file), HouseFile, HouseID);
- // Check if the HouseFile exists
- if (fexist(file))
- {
- // Open the housefile for reading
- HFile = fopen(file, io_read);
- // Read the first line of the file
- fread(HFile, LineFromFile);
- // Keep reading until the end of the file is found (no more data)
- // An empty line between data-segments still has the NewLine characters (\r\n) so it's not completely empty
- // Reading past the last line will read a completely empty line, therefore indicating the end of the file
- 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
- // Check if there is anything in the LineFromFile (skipping empty lines)
- if (strlen(LineFromFile) > 0)
- {
- // Store the proper value in the proper place
- 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, "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, "HouseOpened", false) == 0) // If the parametername is correct ("HouseOpened")
- {
- if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
- AHouseData[HouseID][HouseOpened] = true; // House is open to the public (anyone can enter)
- else
- AHouseData[HouseID][HouseOpened] = false; // House is closed to the public, only house-owner can enter
- }
- if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
- {
- if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
- AHouseData[HouseID][Insurance] = true; // House has insurance for it's vehicles
- else
- AHouseData[HouseID][Insurance] = false; // House doesn't have insurance
- }
- if (strcmp(ParameterName, "StaticHouse", false) == 0) // If the parametername is correct ("StaticHouse")
- {
- if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
- AHouseData[HouseID][StaticHouse] = true; // House is static (not upgradable, fixed interior and carslots)
- else
- AHouseData[HouseID][StaticHouse] = false; // House isn't static (upgradable, interior and carslots based on HouseLevel)
- }
- if (strcmp(ParameterName, "CarSlots", false) == 0) // If the parametername is correct ("CarSlots")
- AHouseData[HouseID][CarSlots] = strval(ParameterValue); // Store the CarSlots
- }
- // Read the next line of the file
- fread(HFile, LineFromFile);
- }
- // Close the file
- fclose(HFile);
- // Add a pickup and 3DText for this house
- House_UpdateEntrance(HouseID);
- // Count the amount of houses that are loaded
- TotalHouses++;
- // Return if the file was read correctly
- return 1;
- }
- else
- return 0; // Return 0 if the file couldn't be read (doesn't exist)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement