Advertisement
Guest User

Script AHouseData

a guest
Jan 3rd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.28 KB | None | 0 0
  1. {
  2. PickupID,
  3. Text3DoorText,
  4. MapIconID,
  5. HouseName[100],
  6. Insurance,
  7. Float:HouseX,
  8. Float:HouseY,
  9. Float:HouseZ,
  10. HouseLevel,
  11. HouseMaxLevel,
  12. HousePrice,
  13. bool:Owned,
  14. Owner[24],
  15. PassCar[100],
  16. bool:HouseOpened,
  17. VehicleIDs[10],
  18. UltimoLogin[30]
  19. }
  20. new AHouseData[MAX_HOUSES][THouseData];
  21.  
  22. HouseFile_Load(HouseID, bool:OnlyLoadVehicles = false)
  23. {
  24. new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  25. // Setup local variables
  26. new cModel, cPaint, components[14], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, vid, bool:VehicleClamped, cFuel = -1;
  27.  
  28. format(file, sizeof(file), HouseFile, HouseID); // Construct the complete filename for this house-file
  29.  
  30. if (fexist(file))
  31. {
  32. HFile = fopen(file, io_read); // Open the housefile for reading
  33.  
  34. fread(HFile, LineFromFile); // Read the first line of the file
  35.  
  36. // Set the house so it cannot be entered by anyone, except the owner (close the house)
  37. AHouseData[HouseID][HouseOpened] = false;
  38.  
  39. // Keep reading until the end of the file is found (no more data)
  40. while (strlen(LineFromFile) > 0)
  41. {
  42. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  43. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  44.  
  45. // If OnlyLoadVehicles is "false", only load the house-data
  46. // If OnlyLoadVehicles is "true", only load the vehicle-data
  47. if (OnlyLoadVehicles == false)
  48. {
  49. // Store the proper value in the proper place
  50. if (strcmp(ParameterName, "HouseName", false) == 0) // If the parametername is correct ("HouseName")
  51. format(AHouseData[HouseID][HouseName], 24, ParameterValue); // Store the HouseName
  52. if (strcmp(ParameterName, "HouseX", false) == 0) // If the parametername is correct ("HouseX")
  53. AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
  54. if (strcmp(ParameterName, "HouseY", false) == 0) // If the parametername is correct ("HouseY")
  55. AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
  56. if (strcmp(ParameterName, "HouseZ", false) == 0) // If the parametername is correct ("HouseZ")
  57. AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
  58. if (strcmp(ParameterName, "HouseLevel", false) == 0) // If the parametername is correct ("HouseLevel")
  59. AHouseData[HouseID][HouseLevel] = strval(ParameterValue); // Store the HouseLevel
  60. if (strcmp(ParameterName, "HouseMaxLevel", false) == 0) // If the parametername is correct ("HouseMaxLevel")
  61. AHouseData[HouseID][HouseMaxLevel] = strval(ParameterValue); // Store the HouseMaxLevel
  62. if (strcmp(ParameterName, "HousePrice", false) == 0) // If the parametername is correct ("HousePrice")
  63. AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
  64. if (strcmp(ParameterName, "PassCar", false) == 0) // If the parametername is correct ("PassCar")
  65. format(AHouseData[HouseID][PassCar], 24, ParameterValue); // Store the PassCar
  66. if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
  67. {
  68. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  69. AHouseData[HouseID][Owned] = true; // House is owned
  70. else
  71. AHouseData[HouseID][Owned] = false; // House is not owned
  72. }
  73. if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
  74. // Store the Owner (Owner will hold "1" if there is no owner (empty string), done by "sscanf" I guess)
  75. // But this doesn't matter, as the owner will never be displayed when the house is not owned by someone
  76. format(AHouseData[HouseID][Owner], 24, ParameterValue);
  77. if (strcmp(ParameterName, "UltimoLogin", false) == 0) // Ultimo Locin Casa
  78. format(AHouseData[HouseID][UltimoLogin], 30, ParameterValue); // Ultimo Login Casa
  79. if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
  80. AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
  81. }
  82. else // OnlyLoadVehicles is "true", so only read the vehicle-data
  83. {
  84. if (strcmp(ParameterName, "[Vehicle]", false) == 0) // If the parametername is correct ("[Vehicle]")
  85. {
  86. // Clear all data to start a new vehicle
  87. cModel = 0;
  88. cPaint = 0;
  89. cFuel = -1;
  90. for (new i; i < 14; i++)
  91. components[i] = 0;
  92. }
  93. if (strcmp(ParameterName, "VehicleModel", false) == 0) // If the parametername is correct ("VehicleModel")
  94. cModel = strval(ParameterValue); // Store the VehicleModel
  95. if (strcmp(ParameterName, "Fuel", false) == 0) // If the parametername is correct ("Fuel")
  96. cFuel = strval(ParameterValue); // Store the Fuel
  97. if (strcmp(ParameterName, "VehiclePaintJob", false) == 0) // If the parametername is correct ("VehiclePaintJob")
  98. cPaint = strval(ParameterValue); // Store the VehiclePaintJob
  99. if (strcmp(ParameterName, "VehicleSpoiler", false) == 0) // If the parametername is correct ("VehicleSpoiler")
  100. components[0] = strval(ParameterValue); // Store the VehicleSpoiler
  101. if (strcmp(ParameterName, "VehicleHood", false) == 0) // If the parametername is correct ("VehicleHood")
  102. components[1] = strval(ParameterValue); // Store the VehicleHood
  103. if (strcmp(ParameterName, "VehicleRoof", false) == 0) // If the parametername is correct ("VehicleRoof")
  104. components[2] = strval(ParameterValue); // Store the VehicleRoof
  105. if (strcmp(ParameterName, "VehicleSideSkirt", false) == 0) // If the parametername is correct ("VehicleSideSkirt")
  106. components[3] = strval(ParameterValue); // Store the VehicleSideSkirt
  107. if (strcmp(ParameterName, "VehicleLamps", false) == 0) // If the parametername is correct ("VehicleLamps")
  108. components[4] = strval(ParameterValue); // Store the VehicleLamps
  109. if (strcmp(ParameterName, "VehicleNitro", false) == 0) // If the parametername is correct ("VehicleNitro")
  110. components[5] = strval(ParameterValue); // Store the VehicleNitro
  111. if (strcmp(ParameterName, "VehicleExhaust", false) == 0) // If the parametername is correct ("VehicleExhaust")
  112. components[6] = strval(ParameterValue); // Store the VehicleExhaust
  113. if (strcmp(ParameterName, "VehicleWheels", false) == 0) // If the parametername is correct ("VehicleWheels")
  114. components[7] = strval(ParameterValue); // Store the VehicleWheels
  115. if (strcmp(ParameterName, "VehicleStereo", false) == 0) // If the parametername is correct ("VehicleStereo")
  116. components[8] = strval(ParameterValue); // Store the VehicleStereo
  117. if (strcmp(ParameterName, "VehicleHydraulics", false) == 0) // If the parametername is correct ("VehicleHydraulics")
  118. components[9] = strval(ParameterValue); // Store the VehicleHydraulics
  119. if (strcmp(ParameterName, "VehicleFrontBumper", false) == 0) // If the parametername is correct ("VehicleFrontBumper")
  120. components[10] = strval(ParameterValue); // Store the VehicleFrontBumper
  121. if (strcmp(ParameterName, "VehicleRearBumper", false) == 0) // If the parametername is correct ("VehicleRearBumper")
  122. components[11] = strval(ParameterValue); // Store the VehicleRearBumper
  123. if (strcmp(ParameterName, "VehicleVentRight", false) == 0) // If the parametername is correct ("VehicleVentRight")
  124. components[12] = strval(ParameterValue); // Store the VehicleVentRight
  125. if (strcmp(ParameterName, "VehicleVentLeft", false) == 0) // If the parametername is correct ("VehicleVentLeft")
  126. components[13] = strval(ParameterValue); // Store the VehicleVentLeft
  127.  
  128. if (strcmp(ParameterName, "Color1", false) == 0) // If the parametername is correct ("Color1")
  129. Col1 = strval(ParameterValue); // Store the Color1
  130. if (strcmp(ParameterName, "Color2", false) == 0) // If the parametername is correct ("Color2")
  131. Col2 = strval(ParameterValue); // Store the Color2
  132.  
  133. if (strcmp(ParameterName, "VehicleX", false) == 0) // If the parametername is correct ("VehicleX")
  134. cx = floatstr(ParameterValue); // Store the VehicleX
  135. if (strcmp(ParameterName, "VehicleY", false) == 0) // If the parametername is correct ("VehicleY")
  136. cy = floatstr(ParameterValue); // Store the VehicleY
  137. if (strcmp(ParameterName, "VehicleZ", false) == 0) // If the parametername is correct ("VehicleZ")
  138. cz = floatstr(ParameterValue); // Store the VehicleZ
  139. if (strcmp(ParameterName, "VehicleAngle", false) == 0) // If the parametername is correct ("VehicleAngle")
  140. crot = floatstr(ParameterValue); // Store the VehicleAngle
  141.  
  142. if (strcmp(ParameterName, "Clamped", false) == 0) // If the parametername is correct ("Clamped")
  143. {
  144. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  145. VehicleClamped = true; // Vehicle is clamped
  146. else
  147. VehicleClamped = false; // Vehicle is not clamped
  148. }
  149.  
  150. if (strcmp(ParameterName, "[/Vehicle]", false) == 0) // If the parametername is correct ("[/Vehicle]")
  151. {
  152. // Set both colors to 1 if they are 0 AND if there is a paintjob applied
  153. if ((Col1 == 0) && (cPaint != 0))
  154. Col1 = 1;
  155. if ((Col2 == 0) && (cPaint != 0))
  156. Col2 = 1;
  157.  
  158. // The "[/Vehicle]" is found, this means that all data about this vehicle is now stored in the variables
  159. // Now add the vehicle to the house and set it's data
  160. vid = House_AddVehicle(HouseID, cModel, cPaint, components, cx, cy, cz, crot, Col1, Col2);
  161. AVehicleData[vid][Clamped] = VehicleClamped;
  162. // Also set the fuel (set it to maximum when the fuel parameter wasn't inside the file)
  163. if (cFuel == -1)
  164. AVehicleData[vid][Fuel] = MaxFuel;
  165. else // If the parameter was there, store it
  166. AVehicleData[vid][Fuel] = cFuel;
  167. }
  168. }
  169.  
  170. // Read the next line of the file
  171. fread(HFile, LineFromFile);
  172. }
  173.  
  174. // Check if the maximum house-level isn't 0 (when updating to the new version)
  175. if (AHouseData[HouseID][HouseMaxLevel] == 0)
  176. AHouseData[HouseID][HouseMaxLevel] = 10; // Set the maximum level to 10
  177.  
  178. // Close the file
  179. fclose(HFile);
  180.  
  181. // Return if the file was read correctly
  182. return 1;
  183. }
  184. else
  185. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  186. }
  187.  
  188. HouseFile_Save(HouseID)
  189. {
  190. new file[100], File:HFile, LineForFile[100], vid;
  191.  
  192. // Construct the complete filename for this house
  193. format(file, sizeof(file), HouseFile, HouseID);
  194.  
  195. HFile = fopen(file, io_write); // Open the playerfile for writing
  196.  
  197. format(LineForFile, 100, "HouseName %s\r\n", AHouseData[HouseID][HouseName]); // Construct the line: "HouseName <HouseName>"
  198. fwrite(HFile, LineForFile); // And save it to the file
  199.  
  200. format(LineForFile, 100, "HouseX %f\r\n", AHouseData[HouseID][HouseX]); // Construct the line: "HouseX <HouseX>"
  201. fwrite(HFile, LineForFile); // And save it to the file
  202.  
  203. format(LineForFile, 100, "HouseY %f\r\n", AHouseData[HouseID][HouseY]); // Construct the line: "HouseY <HouseY>"
  204. fwrite(HFile, LineForFile); // And save it to the file
  205.  
  206. format(LineForFile, 100, "HouseZ %f\r\n", AHouseData[HouseID][HouseZ]); // Construct the line: "HouseZ <HouseZ>"
  207. fwrite(HFile, LineForFile); // And save it to the file
  208.  
  209. format(LineForFile, 100, "HouseLevel %i\r\n", AHouseData[HouseID][HouseLevel]); // Construct the line: "HouseLevel <HouseLevel>"
  210. fwrite(HFile, LineForFile); // And save it to the file
  211.  
  212. format(LineForFile, 100, "HouseMaxLevel %i\r\n", AHouseData[HouseID][HouseMaxLevel]); // Construct the line: "HouseMaxLevel <HouseMaxLevel>"
  213. fwrite(HFile, LineForFile); // And save it to the file
  214.  
  215. format(LineForFile, 100, "HousePrice %i\r\n", AHouseData[HouseID][HousePrice]); // Construct the line: "HousePrice <HousePrice>"
  216. fwrite(HFile, LineForFile); // And save it to the file
  217.  
  218. format(LineForFile, 100, "PassCar %s\r\n", AHouseData[HouseID][PassCar]); // Construct the line: "PassCar <PassCar>"
  219. fwrite(HFile, LineForFile); // And save it to the file
  220.  
  221. if (AHouseData[HouseID][Owned] == true) // Check if the house is owned
  222. {
  223. format(LineForFile, 100, "Owned Yes\r\n"); // Construct the line: "Owned Yes"
  224. fwrite(HFile, LineForFile); // And save it to the file
  225. }
  226. else
  227. {
  228. format(LineForFile, 100, "Owned No\r\n"); // Construct the line: "Owned No"
  229. fwrite(HFile, LineForFile); // And save it to the file
  230. }
  231.  
  232. format(LineForFile, 100, "Owner %s\r\n", AHouseData[HouseID][Owner]); // Construct the line: "Owner <Owner>"
  233. fwrite(HFile, LineForFile); // And save it to the file
  234.  
  235. format(LineForFile, 100, "UltimoLogin %s\r\n", AHouseData[HouseID][UltimoLogin]); // Construct the line: "Owner <Owner>"
  236. fwrite(HFile, LineForFile); // And save it to the file
  237.  
  238. format(LineForFile, 100, "Insurance %i\r\n", AHouseData[HouseID][Insurance]); // Construct the line: "Insurance <Insurance>"
  239. fwrite(HFile, LineForFile); // And save it to the file
  240.  
  241.  
  242.  
  243. // Save the vehicle-data for every vehicle added to the house
  244. for (new CarSlot; CarSlot < 10; CarSlot++)
  245. {
  246. // If a valid vehicle-id has been found
  247. if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
  248. {
  249. // Get the vehicle id
  250. vid = AHouseData[HouseID][VehicleIDs][CarSlot];
  251.  
  252. format(LineForFile, 100, "[Vehicle]\r\n"); // Construct the line: "[Vehicle]"
  253. fwrite(HFile, LineForFile); // And save it to the file
  254.  
  255. format(LineForFile, 100, "VehicleModel %i\r\n", AVehicleData[vid][Model]); // Construct the line: "VehicleModel <VehicleModel>"
  256. fwrite(HFile, LineForFile); // And save it to the file
  257. format(LineForFile, 100, "Fuel %i\r\n", AVehicleData[vid][Fuel]); // Construct the line: "Fuel <Fuel>"
  258. fwrite(HFile, LineForFile); // And save it to the file
  259. format(LineForFile, 100, "VehiclePaintJob %i\r\n", AVehicleData[vid][PaintJob]); // Construct the line: "VehiclePaintJob <VehiclePaintJob>"
  260. fwrite(HFile, LineForFile); // And save it to the file
  261.  
  262. format(LineForFile, 100, "VehicleSpoiler %i\r\n", AVehicleData[vid][Components][0]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
  263. fwrite(HFile, LineForFile); // And save it to the file
  264. format(LineForFile, 100, "VehicleHood %i\r\n", AVehicleData[vid][Components][1]); // Construct the line: "VehicleHood <VehicleHood>"
  265. fwrite(HFile, LineForFile); // And save it to the file
  266. format(LineForFile, 100, "VehicleRoof %i\r\n", AVehicleData[vid][Components][2]); // Construct the line: "VehicleRoof <VehicleRoof>"
  267. fwrite(HFile, LineForFile); // And save it to the file
  268. format(LineForFile, 100, "VehicleSideSkirt %i\r\n", AVehicleData[vid][Components][3]); // Construct the line: "VehicleSideSkirt <VehicleSideSkirt>"
  269. fwrite(HFile, LineForFile); // And save it to the file
  270. format(LineForFile, 100, "VehicleLamps %i\r\n", AVehicleData[vid][Components][4]); // Construct the line: "VehicleLamps <VehicleLamps>"
  271. fwrite(HFile, LineForFile); // And save it to the file
  272. format(LineForFile, 100, "VehicleNitro %i\r\n", AVehicleData[vid][Components][5]); // Construct the line: "VehicleNitro <VehicleNitro>"
  273. fwrite(HFile, LineForFile); // And save it to the file
  274. format(LineForFile, 100, "VehicleExhaust %i\r\n", AVehicleData[vid][Components][6]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
  275. fwrite(HFile, LineForFile); // And save it to the file
  276. format(LineForFile, 100, "VehicleWheels %i\r\n", AVehicleData[vid][Components][7]); // Construct the line: "VehicleWheels <VehicleWheels>"
  277. fwrite(HFile, LineForFile); // And save it to the file
  278. format(LineForFile, 100, "VehicleStereo %i\r\n", AVehicleData[vid][Components][8]); // Construct the line: "VehicleStereo <VehicleStereo>"
  279. fwrite(HFile, LineForFile); // And save it to the file
  280. format(LineForFile, 100, "VehicleHydraulics %i\r\n", AVehicleData[vid][Components][9]); // Construct the line: "VehicleHydraulics <VehicleHydraulics>"
  281. fwrite(HFile, LineForFile); // And save it to the file
  282. format(LineForFile, 100, "VehicleFrontBumper %i\r\n", AVehicleData[vid][Components][10]); // Construct the line: "VehicleFrontBumper <VehicleFrontBumper>"
  283. fwrite(HFile, LineForFile); // And save it to the file
  284. format(LineForFile, 100, "VehicleRearBumper %i\r\n", AVehicleData[vid][Components][11]); // Construct the line: "VehicleRearBumper <VehicleRearBumper>"
  285. fwrite(HFile, LineForFile); // And save it to the file
  286. format(LineForFile, 100, "VehicleVentRight %i\r\n", AVehicleData[vid][Components][12]); // Construct the line: "VehicleVentRight <VehicleVentRight>"
  287. fwrite(HFile, LineForFile); // And save it to the file
  288. format(LineForFile, 100, "VehicleVentLeft %i\r\n", AVehicleData[vid][Components][13]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  289. fwrite(HFile, LineForFile); // And save it to the file
  290.  
  291. format(LineForFile, 100, "Color1 %i\r\n", AVehicleData[vid][Color1]); // Construct the line: "Color1 <Color1>"
  292. fwrite(HFile, LineForFile); // And save it to the file
  293. format(LineForFile, 100, "Color2 %i\r\n", AVehicleData[vid][Color2]); // Construct the line: "Color2 <Color2>"
  294. fwrite(HFile, LineForFile); // And save it to the file
  295.  
  296. format(LineForFile, 100, "VehicleX %f\r\n", AVehicleData[vid][SpawnX]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  297. fwrite(HFile, LineForFile); // And save it to the file
  298. format(LineForFile, 100, "VehicleY %f\r\n", AVehicleData[vid][SpawnY]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  299. fwrite(HFile, LineForFile); // And save it to the file
  300. format(LineForFile, 100, "VehicleZ %f\r\n", AVehicleData[vid][SpawnZ]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  301. fwrite(HFile, LineForFile); // And save it to the file
  302. format(LineForFile, 100, "VehicleAngle %f\r\n", AVehicleData[vid][SpawnRot]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  303. fwrite(HFile, LineForFile); // And save it to the file
  304.  
  305. if (AVehicleData[vid][Clamped] == true)
  306. format(LineForFile, 100, "Clamped Yes\r\n"); // Construct the line: "Clamped <Yes>"
  307. else
  308. format(LineForFile, 100, "Clamped No\r\n"); // Construct the line: "Clamped <No>"
  309.  
  310. fwrite(HFile, LineForFile); // And save it to the file
  311.  
  312. format(LineForFile, 100, "[/Vehicle]\r\n"); // Construct the line: "[/Vehicle]"
  313. fwrite(HFile, LineForFile); // And save it to the file
  314. }
  315. }
  316.  
  317. fclose(HFile); // Close the file
  318.  
  319. return 1;
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement