Gguiz007

321

Apr 25th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. HouseFile_Load(HouseID, bool:LoadVehicles = true) {
  2.  
  3. new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  4. new cModel, cPaint, components[14], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, vid, bool:VehicleClamped, cFuel = -1;
  5. format(file, sizeof(file), HouseFile, HouseID);
  6. if(fexist(file)) {
  7. HFile = fopen(file, io_read);
  8. fread(HFile, LineFromFile);
  9.  
  10. AHouseData[HouseID][HouseOpened] = false;
  11.  
  12. while(strlen(LineFromFile) > 0) {
  13. StripNewLine(LineFromFile);
  14. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue);
  15.  
  16. switch(LoadVehicles) {
  17. case true: {
  18. if (strcmp(ParameterName, "HouseName", false) == 0) // If the parametername is correct ("HouseName")
  19. format(AHouseData[HouseID][HouseName], 24, ParameterValue); // Store the HouseName
  20. if (strcmp(ParameterName, "HouseX", false) == 0) // If the parametername is correct ("HouseX")
  21. AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
  22. if (strcmp(ParameterName, "HouseY", false) == 0) // If the parametername is correct ("HouseY")
  23. AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
  24. if (strcmp(ParameterName, "HouseZ", false) == 0) // If the parametername is correct ("HouseZ")
  25. AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
  26. if (strcmp(ParameterName, "HouseLevel", false) == 0) // If the parametername is correct ("HouseLevel")
  27. AHouseData[HouseID][HouseLevel] = strval(ParameterValue); // Store the HouseLevel
  28. if (strcmp(ParameterName, "HouseMaxLevel", false) == 0) // If the parametername is correct ("HouseMaxLevel")
  29. AHouseData[HouseID][HouseMaxLevel] = strval(ParameterValue); // Store the HouseMaxLevel
  30. if (strcmp(ParameterName, "HousePrice", false) == 0) // If the parametername is correct ("HousePrice")
  31. AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
  32. if (strcmp(ParameterName, "Localidade", false) == 0) // If the parametername is correct ("HouseName")
  33. format(AHouseData[HouseID][Localidade], 24, ParameterValue);
  34. if (strcmp(ParameterName, "VehiclesPassword", false) == 0) // If the parametername is correct ("VehiclesPassword")
  35. format(AHouseData[HouseID][VehiclesPassword], 16, ParameterValue); // Store the VehiclesPassword
  36. if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
  37. {
  38. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  39. AHouseData[HouseID][Owned] = true; // House is owned
  40. else
  41. AHouseData[HouseID][Owned] = false; // House is not owned
  42. }
  43. if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
  44. // Store the Owner (Owner will hold "1" if there is no owner (empty string), done by "sscanf" I guess)
  45. // But this doesn't matter, as the owner will never be displayed when the house is not owned by someone
  46. format(AHouseData[HouseID][Owner], 24, ParameterValue);
  47. if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
  48. AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
  49.  
  50. if (strcmp(ParameterName, "[Vehicle]", false) == 0) // If the parametername is correct ("[Vehicle]")
  51. {
  52. // Clear all data to start a new vehicle
  53. cModel = 0;
  54. cPaint = 0;
  55. cFuel = -1;
  56. for (new i; i < 14; i++)
  57. components[i] = 0;
  58. }
  59. if (strcmp(ParameterName, "VehicleModel", false) == 0) // If the parametername is correct ("VehicleModel")
  60. cModel = strval(ParameterValue); // Store the VehicleModel
  61. if (strcmp(ParameterName, "Fuel", false) == 0) // If the parametername is correct ("Fuel")
  62. cFuel = strval(ParameterValue); // Store the Fuel
  63. if (strcmp(ParameterName, "VehiclePaintJob", false) == 0) // If the parametername is correct ("VehiclePaintJob")
  64. cPaint = strval(ParameterValue); // Store the VehiclePaintJob
  65. if (strcmp(ParameterName, "VehicleSpoiler", false) == 0) // If the parametername is correct ("VehicleSpoiler")
  66. components[0] = strval(ParameterValue); // Store the VehicleSpoiler
  67. if (strcmp(ParameterName, "VehicleHood", false) == 0) // If the parametername is correct ("VehicleHood")
  68. components[1] = strval(ParameterValue); // Store the VehicleHood
  69. if (strcmp(ParameterName, "VehicleRoof", false) == 0) // If the parametername is correct ("VehicleRoof")
  70. components[2] = strval(ParameterValue); // Store the VehicleRoof
  71. if (strcmp(ParameterName, "VehicleSideSkirt", false) == 0) // If the parametername is correct ("VehicleSideSkirt")
  72. components[3] = strval(ParameterValue); // Store the VehicleSideSkirt
  73. if (strcmp(ParameterName, "VehicleLamps", false) == 0) // If the parametername is correct ("VehicleLamps")
  74. components[4] = strval(ParameterValue); // Store the VehicleLamps
  75. if (strcmp(ParameterName, "VehicleNitro", false) == 0) // If the parametername is correct ("VehicleNitro")
  76. components[5] = strval(ParameterValue); // Store the VehicleNitro
  77. if (strcmp(ParameterName, "VehicleExhaust", false) == 0) // If the parametername is correct ("VehicleExhaust")
  78. components[6] = strval(ParameterValue); // Store the VehicleExhaust
  79. if (strcmp(ParameterName, "VehicleWheels", false) == 0) // If the parametername is correct ("VehicleWheels")
  80. components[7] = strval(ParameterValue); // Store the VehicleWheels
  81. if (strcmp(ParameterName, "VehicleStereo", false) == 0) // If the parametername is correct ("VehicleStereo")
  82. components[8] = strval(ParameterValue); // Store the VehicleStereo
  83. if (strcmp(ParameterName, "VehicleHydraulics", false) == 0) // If the parametername is correct ("VehicleHydraulics")
  84. components[9] = strval(ParameterValue); // Store the VehicleHydraulics
  85. if (strcmp(ParameterName, "VehicleFrontBumper", false) == 0) // If the parametername is correct ("VehicleFrontBumper")
  86. components[10] = strval(ParameterValue); // Store the VehicleFrontBumper
  87. if (strcmp(ParameterName, "VehicleRearBumper", false) == 0) // If the parametername is correct ("VehicleRearBumper")
  88. components[11] = strval(ParameterValue); // Store the VehicleRearBumper
  89. if (strcmp(ParameterName, "VehicleVentRight", false) == 0) // If the parametername is correct ("VehicleVentRight")
  90. components[12] = strval(ParameterValue); // Store the VehicleVentRight
  91. if (strcmp(ParameterName, "VehicleVentLeft", false) == 0) // If the parametername is correct ("VehicleVentLeft")
  92. components[13] = strval(ParameterValue); // Store the VehicleVentLeft
  93.  
  94. if (strcmp(ParameterName, "Color1", false) == 0) // If the parametername is correct ("Color1")
  95. Col1 = strval(ParameterValue); // Store the Color1
  96. if (strcmp(ParameterName, "Color2", false) == 0) // If the parametername is correct ("Color2")
  97. Col2 = strval(ParameterValue); // Store the Color2
  98.  
  99. if (strcmp(ParameterName, "VehicleX", false) == 0) // If the parametername is correct ("VehicleX")
  100. cx = floatstr(ParameterValue); // Store the VehicleX
  101. if (strcmp(ParameterName, "VehicleY", false) == 0) // If the parametername is correct ("VehicleY")
  102. cy = floatstr(ParameterValue); // Store the VehicleY
  103. if (strcmp(ParameterName, "VehicleZ", false) == 0) // If the parametername is correct ("VehicleZ")
  104. cz = floatstr(ParameterValue); // Store the VehicleZ
  105. if (strcmp(ParameterName, "VehicleAngle", false) == 0) // If the parametername is correct ("VehicleAngle")
  106. crot = floatstr(ParameterValue); // Store the VehicleAngle
  107.  
  108. if (strcmp(ParameterName, "Clamped", false) == 0) // If the parametername is correct ("Clamped")
  109. {
  110. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  111. VehicleClamped = true; // Vehicle is clamped
  112. else
  113. VehicleClamped = false; // Vehicle is not clamped
  114. }
  115.  
  116. if (strcmp(ParameterName, "[/Vehicle]", false) == 0) // If the parametername is correct ("[/Vehicle]")
  117. {
  118. // Set both colors to 1 if they are 0 AND if there is a paintjob applied
  119. if ((Col1 == 0) && (cPaint != 0))
  120. Col1 = 1;
  121. if ((Col2 == 0) && (cPaint != 0))
  122. Col2 = 1;
  123.  
  124. // The "[/Vehicle]" is found, this means that all data about this vehicle is now stored in the variables
  125. // Now add the vehicle to the house and set it's data
  126. vid = House_AddVehicle(HouseID, cModel, cPaint, components, cx, cy, cz, crot, Col1, Col2);
  127. AVehicleData[vid][Clamped] = VehicleClamped;
  128. // Also set the fuel (set it to maximum when the fuel parameter wasn't inside the file)
  129. if (cFuel == -1)
  130. AVehicleData[vid][Fuel] = MaxFuel;
  131. else
  132. AVehicleData[vid][Fuel] = cFuel;
  133. format(AVehicleData[vid][VehiclePass], 16, "%s", AHouseData[HouseID][VehiclesPassword]);
  134. }
  135. }
  136. }
  137. fread(HFile, LineFromFile);
  138. }
  139. if(AHouseData[HouseID][HouseMaxLevel] == 1) { AHouseData[HouseID][HouseMaxLevel] = 10; }
  140. fclose(HFile);
  141.  
  142. return true;
  143. }
  144. else return false;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment