Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. HouseFile_Load(HouseID)
  2. {
  3. // Setup local variables
  4. new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  5.  
  6. // Construct the complete filename for this house-file
  7. format(file, sizeof(file), HouseFile, HouseID);
  8.  
  9. // Check if the HouseFile exists
  10. if (fexist(file))
  11. {
  12. // Open the housefile for reading
  13. HFile = fopen(file, io_read);
  14. // Read the first line of the file
  15. fread(HFile, LineFromFile);
  16.  
  17. // Keep reading until the end of the file is found (no more data)
  18. // An empty line between data-segments still has the NewLine characters (\r\n) so it's not completely empty
  19. // Reading past the last line will read a completely empty line, therefore indicating the end of the file
  20. while (strlen(LineFromFile) > 0)
  21. {
  22. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  23. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  24.  
  25. // Check if there is anything in the LineFromFile (skipping empty lines)
  26. if (strlen(LineFromFile) > 0)
  27. {
  28. // Store the proper value in the proper place
  29. if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
  30. {
  31. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  32. AHouseData[HouseID][Owned] = true; // House is owned
  33. else
  34. AHouseData[HouseID][Owned] = false; // House is not owned
  35. }
  36. if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
  37. // Store the Owner (Owner will hold "1" if there is no owner (empty string), done by "sscanf" I guess)
  38. // But this doesn't matter, as the owner will never be displayed when the house is not owned by someone
  39. format(AHouseData[HouseID][Owner], 24, ParameterValue);
  40.  
  41. if (strcmp(ParameterName, "HouseName", false) == 0) // If the parametername is correct ("HouseName")
  42. format(AHouseData[HouseID][HouseName], 24, ParameterValue); // Store the HouseName
  43. if (strcmp(ParameterName, "HouseX", false) == 0) // If the parametername is correct ("HouseX")
  44. AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
  45. if (strcmp(ParameterName, "HouseY", false) == 0) // If the parametername is correct ("HouseY")
  46. AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
  47. if (strcmp(ParameterName, "HouseZ", false) == 0) // If the parametername is correct ("HouseZ")
  48. AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
  49. if (strcmp(ParameterName, "HouseLevel", false) == 0) // If the parametername is correct ("HouseLevel")
  50. AHouseData[HouseID][HouseLevel] = strval(ParameterValue); // Store the HouseLevel
  51. if (strcmp(ParameterName, "HouseMaxLevel", false) == 0) // If the parametername is correct ("HouseMaxLevel")
  52. AHouseData[HouseID][HouseMaxLevel] = strval(ParameterValue); // Store the HouseMaxLevel
  53. if (strcmp(ParameterName, "HousePrice", false) == 0) // If the parametername is correct ("HousePrice")
  54. AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
  55. if (strcmp(ParameterName, "HouseOpened", false) == 0) // If the parametername is correct ("HouseOpened")
  56. {
  57. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  58. AHouseData[HouseID][HouseOpened] = true; // House is open to the public (anyone can enter)
  59. else
  60. AHouseData[HouseID][HouseOpened] = false; // House is closed to the public, only house-owner can enter
  61. }
  62. if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
  63. {
  64. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  65. AHouseData[HouseID][Insurance] = true; // House has insurance for it's vehicles
  66. else
  67. AHouseData[HouseID][Insurance] = false; // House doesn't have insurance
  68. }
  69.  
  70. if (strcmp(ParameterName, "StaticHouse", false) == 0) // If the parametername is correct ("StaticHouse")
  71. {
  72. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  73. AHouseData[HouseID][StaticHouse] = true; // House is static (not upgradable, fixed interior and carslots)
  74. else
  75. AHouseData[HouseID][StaticHouse] = false; // House isn't static (upgradable, interior and carslots based on HouseLevel)
  76. }
  77. if (strcmp(ParameterName, "CarSlots", false) == 0) // If the parametername is correct ("CarSlots")
  78. AHouseData[HouseID][CarSlots] = strval(ParameterValue); // Store the CarSlots
  79. }
  80.  
  81. // Read the next line of the file
  82. fread(HFile, LineFromFile);
  83. }
  84.  
  85. // Close the file
  86. fclose(HFile);
  87.  
  88. // Add a pickup and 3DText for this house
  89. House_UpdateEntrance(HouseID);
  90. // Count the amount of houses that are loaded
  91. TotalHouses++;
  92.  
  93. // Return if the file was read correctly
  94. return 1;
  95. }
  96. else
  97. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement