1
0

PPC_FileOperations.inc 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. // This function will create the player-datafile for the given player (only used when a new player joins the server)
  2. PlayerFile_Create(playerid)
  3. {
  4. new file[100], File:PFile, Name[24], LineForFile[100];
  5. format(Name, sizeof(Name), APlayerData[playerid][PlayerName]); // Get the playername
  6. format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account
  7. PFile = fopen(file, io_write); // Open the playerfile for writing
  8. format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][PlayerPassword]); // Construct the line: "Password <playerpassword>"
  9. fwrite(PFile, LineForFile); // And save it to the file
  10. format(LineForFile, 100, "Level %i\r\n", 0); // Construct the line: "Level <playerlevel>"
  11. fwrite(PFile, LineForFile); // And save it to the file
  12. format(LineForFile, 100, "Jailed %i\r\n", 0); // Construct the line: "Jailed <playerjailed>"
  13. fwrite(PFile, LineForFile); // And save it to the file
  14. format(LineForFile, 100, "Wanted %i\r\n", 0); // Construct the line: "Wanted <wantedlevel>"
  15. fwrite(PFile, LineForFile); // And save it to the file
  16. format(LineForFile, 100, "Bans %i\r\n", 0); // Construct the line: "Bans <NumberOfBans>"
  17. fwrite(PFile, LineForFile); // And save it to the file
  18. format(LineForFile, 100, "BanTime %i\r\n", 0); // Construct the line: "BanTime <TimeToUnban>"
  19. fwrite(PFile, LineForFile); // And save it to the file
  20. format(LineForFile, 100, "TruckerLicense %i\r\n", 0); // Construct the line: "TruckerLicense <playertruckerlicense>"
  21. fwrite(PFile, LineForFile); // And save it to the file
  22. format(LineForFile, 100, "BusLicense %i\r\n", 0); // Construct the line: "BusLicense <playerbuslicense>"
  23. fwrite(PFile, LineForFile); // And save it to the file
  24. format(LineForFile, 100, "StatsMetersDriven %f\r\n", 0.0); // Construct the line: "StatsMetersDriven <StatsMetersDriven>"
  25. fwrite(PFile, LineForFile); // And save it to the file
  26. format(LineForFile, 100, "StatsTruckerJobs %i\r\n", 0); // Construct the line: "StatsTruckerJobs <StatsTruckerJobs>"
  27. fwrite(PFile, LineForFile); // And save it to the file
  28. format(LineForFile, 100, "StatsConvoyJobs %i\r\n", 0); // Construct the line: "StatsConvoyJobs <StatsConvoyJobs>"
  29. fwrite(PFile, LineForFile); // And save it to the file
  30. format(LineForFile, 100, "StatsBusDriverJobs %i\r\n", 0); // Construct the line: "StatsBusDriverJobs <StatsBusDriverJobs>"
  31. fwrite(PFile, LineForFile); // And save it to the file
  32. format(LineForFile, 100, "StatsPilotJobs %i\r\n", 0); // Construct the line: "StatsPilotJobs <StatsPilotJobs>"
  33. fwrite(PFile, LineForFile); // And save it to the file
  34. format(LineForFile, 100, "StatsMafiaJobs %i\r\n", 0); // Construct the line: "StatsMafiaJobs <StatsMafiaJobs>"
  35. fwrite(PFile, LineForFile); // And save it to the file
  36. format(LineForFile, 100, "StatsMafiaStolen %i\r\n", 0); // Construct the line: "StatsMafiaStolen <StatsMafiaStolen>"
  37. fwrite(PFile, LineForFile); // And save it to the file
  38. format(LineForFile, 100, "StatsPoliceFined %i\r\n", 0); // Construct the line: "StatsPoliceFined <StatsPoliceFined>"
  39. fwrite(PFile, LineForFile); // And save it to the file
  40. format(LineForFile, 100, "StatsPoliceJailed %i\r\n", 0); // Construct the line: "StatsPoliceJailed <StatsPoliceJailed>"
  41. fwrite(PFile, LineForFile); // And save it to the file
  42. format(LineForFile, 100, "Money %i\r\n", 0); // Construct the line: "Money <playermoney>"
  43. fwrite(PFile, LineForFile); // And save it to the file
  44. format(LineForFile, 100, "Score %i\r\n", 0); // Construct the line: "Score <playerscore>"
  45. fwrite(PFile, LineForFile); // And save it to the file
  46. fclose(PFile); // Close the file
  47. return 1;
  48. }
  49. // This function will load the player's datafile (used when a player connects to the server)
  50. PlayerFile_Load(playerid)
  51. {
  52. // Setup local variables
  53. new file[100], File:PFile, Name[24], LineFromFile[100], ParameterName[50], ParameterValue[50], HouseIndex, BusIndex;
  54. format(Name, sizeof(Name), APlayerData[playerid][PlayerName]); // Get the playername
  55. format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account
  56. // Check if the player's datafile exists
  57. if (fexist(file))
  58. {
  59. PFile = fopen(file, io_read); // Open the playerfile for reading
  60. fread(PFile, LineFromFile); // Read the first line of the file
  61. // Keep reading until the end of the file is found (no more data)
  62. while (strlen(LineFromFile) > 0)
  63. {
  64. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  65. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  66. // Store the proper value in the proper place
  67. if (strcmp(ParameterName, "Password", false) == 0) // If the parametername is correct ("Password")
  68. format(APlayerData[playerid][PlayerPassword], 50, ParameterValue); // Store the password
  69. if (strcmp(ParameterName, "Level", false) == 0) // If the parametername is correct ("Level")
  70. APlayerData[playerid][PlayerLevel] = strval(ParameterValue); // Store the playerlevel
  71. if (strcmp(ParameterName, "Jailed", false) == 0) // If the parametername is correct ("Jailed")
  72. APlayerData[playerid][PlayerJailed] = strval(ParameterValue); // Store the jailed-status
  73. if (strcmp(ParameterName, "Wanted", false) == 0) // If the parametername is correct ("Wanted")
  74. SetPlayerWantedLevel(playerid, strval(ParameterValue)); // Set the wanted-status
  75. if (strcmp(ParameterName, "Bans", false) == 0) // If the parametername is correct ("Bans")
  76. APlayerData[playerid][Bans] = strval(ParameterValue); // Store the bans
  77. if (strcmp(ParameterName, "BanTime", false) == 0) // If the parametername is correct ("BanTime")
  78. APlayerData[playerid][BanTime] = strval(ParameterValue); // Store the bantime
  79. if (strcmp(ParameterName, "TruckerLicense", false) == 0) // If the parametername is correct ("TruckerLicense")
  80. APlayerData[playerid][TruckerLicense] = strval(ParameterValue); // Store the TruckerLicense
  81. if (strcmp(ParameterName, "BusLicense", false) == 0) // If the parametername is correct ("BusLicense")
  82. APlayerData[playerid][BusLicense] = strval(ParameterValue); // Store the BusLicense
  83. if (strcmp(ParameterName, "Muted", false) == 0) // If the parametername is correct ("Muted")
  84. {
  85. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  86. APlayerData[playerid][Muted] = true; // Player is muted
  87. else
  88. APlayerData[playerid][Muted] = false; // Player is not muted
  89. }
  90. if (strcmp(ParameterName, "RulesRead", false) == 0) // If the parametername is correct ("RulesRead")
  91. {
  92. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  93. APlayerData[playerid][RulesRead] = true; // Player has accepted the rules
  94. else
  95. APlayerData[playerid][RulesRead] = false; // Player hasn't accepted the rules yet
  96. }
  97. if (strcmp(ParameterName, "StatsMetersDriven", false) == 0) // If the parametername is correct ("StatsMetersDriven")
  98. APlayerData[playerid][StatsMetersDriven] = floatstr(ParameterValue); // Store the StatsMetersDriven
  99. if (strcmp(ParameterName, "StatsTruckerJobs", false) == 0) // If the parametername is correct ("StatsTruckerJobs")
  100. APlayerData[playerid][StatsTruckerJobs] = strval(ParameterValue); // Store the StatsTruckerJobs
  101. if (strcmp(ParameterName, "StatsConvoyJobs", false) == 0) // If the parametername is correct ("StatsConvoyJobs")
  102. APlayerData[playerid][StatsConvoyJobs] = strval(ParameterValue); // Store the StatsConvoyJobs
  103. if (strcmp(ParameterName, "StatsBusDriverJobs", false) == 0) // If the parametername is correct ("StatsBusDriverJobs")
  104. APlayerData[playerid][StatsBusDriverJobs] = strval(ParameterValue); // Store the StatsBusDriverJobs
  105. if (strcmp(ParameterName, "StatsPilotJobs", false) == 0) // If the parametername is correct ("StatsPilotJobs")
  106. APlayerData[playerid][StatsPilotJobs] = strval(ParameterValue); // Store the StatsPilotJobs
  107. if (strcmp(ParameterName, "StatsMafiaJobs", false) == 0) // If the parametername is correct ("StatsMafiaJobs")
  108. APlayerData[playerid][StatsMafiaJobs] = strval(ParameterValue); // Store the StatsMafiaJobs
  109. if (strcmp(ParameterName, "StatsMafiaStolen", false) == 0) // If the parametername is correct ("StatsMafiaStolen")
  110. APlayerData[playerid][StatsMafiaStolen] = strval(ParameterValue); // Store the StatsMafiaStolen
  111. if (strcmp(ParameterName, "StatsPoliceFined", false) == 0) // If the parametername is correct ("StatsPoliceFined")
  112. APlayerData[playerid][StatsPoliceFined] = strval(ParameterValue); // Store the StatsPoliceFined
  113. if (strcmp(ParameterName, "StatsPoliceJailed", false) == 0) // If the parametername is correct ("StatsPoliceJailed")
  114. APlayerData[playerid][StatsPoliceJailed] = strval(ParameterValue); // Store the StatsPoliceJailed
  115. if (strcmp(ParameterName, "StatsAssistance", false) == 0) // If the parametername is correct ("StatsAssistance")
  116. APlayerData[playerid][StatsAssistance] = strval(ParameterValue); // Store the StatsAssistance
  117. if (strcmp(ParameterName, "StatsCourierJobs", false) == 0) // If the parametername is correct ("StatsCourierJobs")
  118. APlayerData[playerid][StatsCourierJobs] = strval(ParameterValue); // Store the StatsCourierJobs
  119. if (strcmp(ParameterName, "StatsRoadworkerJobs", false) == 0) // If the parametername is correct ("StatsRoadworkerJobs")
  120. APlayerData[playerid][StatsRoadworkerJobs] = strval(ParameterValue); // Store the StatsRoadworkerJobs
  121. if (strcmp(ParameterName, "House", false) == 0) // If the parametername is correct ("House")
  122. {
  123. APlayerData[playerid][Houses][HouseIndex] = strval(ParameterValue); // Store the HouseID at the selected slot
  124. HouseIndex++; // Select the next house-slot in case another house-id is found
  125. }
  126. if (strcmp(ParameterName, "Business", false) == 0) // If the parametername is correct ("Business")
  127. {
  128. if (strcmp(ABusinessData[strval(ParameterValue)][Owner], Name, false) == 0) // Check if the player is the true owner of the business
  129. {
  130. APlayerData[playerid][Business][BusIndex] = strval(ParameterValue); // Store the BusinessID at the selected slot
  131. BusIndex++; // Select the next business-slot in case another business-id is found
  132. }
  133. }
  134. if (strcmp(ParameterName, "Money", false) == 0) // If the parametername is correct ("Money")
  135. RewardPlayer(playerid, strval(ParameterValue), 0); // Store the money
  136. if (strcmp(ParameterName, "Score", false) == 0) // If the parametername is correct ("Score")
  137. RewardPlayer(playerid, 0, strval(ParameterValue)); // Store the score
  138. fread(PFile, LineFromFile); // Read the next line of the file
  139. }
  140. fclose(PFile); // Close the file
  141. return 1; // Return if the file was read correctly
  142. }
  143. else
  144. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  145. }
  146. // This function will save all player-data (used when the player disconnects from the server)
  147. PlayerFile_Save(playerid)
  148. {
  149. new file[100], File:PFile, Name[24], LineForFile[100];
  150. format(Name, sizeof(Name), APlayerData[playerid][PlayerName]); // Get the playername
  151. format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account
  152. PFile = fopen(file, io_write); // Open the playerfile for writing
  153. format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][PlayerPassword]); // Construct the line: "Password <playerpassword>"
  154. fwrite(PFile, LineForFile); // And save it to the file
  155. format(LineForFile, 100, "Level %i\r\n", APlayerData[playerid][PlayerLevel]); // Construct the line: "Level <playerlevel>"
  156. fwrite(PFile, LineForFile); // And save it to the file
  157. format(LineForFile, 100, "Jailed %i\r\n", APlayerData[playerid][PlayerJailed]); // Construct the line: "Jailed <playerjailed>"
  158. fwrite(PFile, LineForFile); // And save it to the file
  159. format(LineForFile, 100, "Wanted %i\r\n", GetPlayerWantedLevel(playerid)); // Construct the line: "Wanted <wantedlevel>"
  160. fwrite(PFile, LineForFile); // And save it to the file
  161. format(LineForFile, 100, "Bans %i\r\n", APlayerData[playerid][Bans]); // Construct the line: "Bans <NumberOfBans>"
  162. fwrite(PFile, LineForFile); // And save it to the file
  163. format(LineForFile, 100, "BanTime %i\r\n", APlayerData[playerid][BanTime]); // Construct the line: "BanTime <TimeToUnban>"
  164. fwrite(PFile, LineForFile); // And save it to the file
  165. format(LineForFile, 100, "TruckerLicense %i\r\n", APlayerData[playerid][TruckerLicense]); // Construct the line: "TruckerLicense <playertruckerlicense>"
  166. fwrite(PFile, LineForFile); // And save it to the file
  167. format(LineForFile, 100, "BusLicense %i\r\n", APlayerData[playerid][BusLicense]); // Construct the line: "BusLicense <playerbuslicense>"
  168. fwrite(PFile, LineForFile); // And save it to the file
  169. if (APlayerData[playerid][Muted] == true) // Check if the player is muted
  170. format(LineForFile, 100, "Muted Yes\r\n"); // Construct the line: "Muted <Yes>"
  171. else
  172. format(LineForFile, 100, "Muted No\r\n"); // Construct the line: "Muted <No>"
  173. fwrite(PFile, LineForFile); // And save it to the file
  174. if (APlayerData[playerid][RulesRead] == true) // Check if the player has accepted the rules
  175. format(LineForFile, 100, "RulesRead Yes\r\n"); // Construct the line: "RulesRead <Yes>"
  176. else
  177. format(LineForFile, 100, "RulesRead No\r\n"); // Construct the line: "RulesRead <No>"
  178. fwrite(PFile, LineForFile); // And save it to the file
  179. format(LineForFile, 100, "StatsMetersDriven %f\r\n", APlayerData[playerid][StatsMetersDriven]); // Construct the line: "StatsMetersDriven <StatsMetersDriven>"
  180. fwrite(PFile, LineForFile); // And save it to the file
  181. format(LineForFile, 100, "StatsTruckerJobs %i\r\n", APlayerData[playerid][StatsTruckerJobs]); // Construct the line: "StatsTruckerJobs <StatsTruckerJobs>"
  182. fwrite(PFile, LineForFile); // And save it to the file
  183. format(LineForFile, 100, "StatsConvoyJobs %i\r\n", APlayerData[playerid][StatsConvoyJobs]); // Construct the line: "StatsConvoyJobs <StatsConvoyJobs>"
  184. fwrite(PFile, LineForFile); // And save it to the file
  185. format(LineForFile, 100, "StatsBusDriverJobs %i\r\n", APlayerData[playerid][StatsBusDriverJobs]); // Construct the line: "StatsBusDriverJobs <StatsBusDriverJobs>"
  186. fwrite(PFile, LineForFile); // And save it to the file
  187. format(LineForFile, 100, "StatsPilotJobs %i\r\n", APlayerData[playerid][StatsPilotJobs]); // Construct the line: "StatsPilotJobs <StatsPilotJobs>"
  188. fwrite(PFile, LineForFile); // And save it to the file
  189. format(LineForFile, 100, "StatsMafiaJobs %i\r\n", APlayerData[playerid][StatsMafiaJobs]); // Construct the line: "StatsMafiaJobs <StatsMafiaJobs>"
  190. fwrite(PFile, LineForFile); // And save it to the file
  191. format(LineForFile, 100, "StatsMafiaStolen %i\r\n", APlayerData[playerid][StatsMafiaStolen]); // Construct the line: "StatsMafiaStolen <StatsMafiaStolen>"
  192. fwrite(PFile, LineForFile); // And save it to the file
  193. format(LineForFile, 100, "StatsPoliceFined %i\r\n", APlayerData[playerid][StatsPoliceFined]); // Construct the line: "StatsPoliceFined <StatsPoliceFined>"
  194. fwrite(PFile, LineForFile); // And save it to the file
  195. format(LineForFile, 100, "StatsPoliceJailed %i\r\n", APlayerData[playerid][StatsPoliceJailed]); // Construct the line: "StatsPoliceJailed <StatsPoliceJailed>"
  196. fwrite(PFile, LineForFile); // And save it to the file
  197. format(LineForFile, 100, "StatsAssistance %i\r\n", APlayerData[playerid][StatsAssistance]); // Construct the line: "StatsAssistance <StatsAssistance>"
  198. fwrite(PFile, LineForFile); // And save it to the file
  199. format(LineForFile, 100, "StatsCourierJobs %i\r\n", APlayerData[playerid][StatsCourierJobs]); // Construct the line: "StatsCourierJobs <StatsCourierJobs>"
  200. fwrite(PFile, LineForFile); // And save it to the file
  201. format(LineForFile, 100, "StatsRoadworkerJobs %i\r\n", APlayerData[playerid][StatsRoadworkerJobs]); // Construct the line: "StatsRoadworkerJobs <StatsRoadworkerJobs>"
  202. fwrite(PFile, LineForFile); // And save it to the file
  203. // Save all the valid house-id's
  204. for (new i; i < MAX_HOUSESPERPLAYER; i++)
  205. {
  206. // Check if there is a valid house-id in this slot
  207. if (APlayerData[playerid][Houses][i] != 0)
  208. {
  209. format(LineForFile, 100, "House %i\r\n", APlayerData[playerid][Houses][i]); // Construct the line: "House <HouseID>"
  210. fwrite(PFile, LineForFile); // And save it to the file
  211. }
  212. }
  213. // Save all the valid business-id's
  214. for (new i; i < MAX_BUSINESSPERPLAYER; i++)
  215. {
  216. // Check if there is a valid business-id in this slot
  217. if (APlayerData[playerid][Business][i] != 0)
  218. {
  219. format(LineForFile, 100, "Business %i\r\n", APlayerData[playerid][Business][i]); // Construct the line: "Business <BusinessID>"
  220. fwrite(PFile, LineForFile); // And save it to the file
  221. }
  222. }
  223. format(LineForFile, 100, "Money %i\r\n", APlayerData[playerid][PlayerMoney]); // Construct the line: "Money <playermoney>"
  224. fwrite(PFile, LineForFile); // And save it to the file
  225. format(LineForFile, 100, "Score %i\r\n", APlayerData[playerid][PlayerScore]); // Construct the line: "Score <playerscore>"
  226. fwrite(PFile, LineForFile); // And save it to the file
  227. fclose(PFile); // Close the file
  228. // Also save the houses that this player owns
  229. for (new i; i < MAX_HOUSESPERPLAYER; i++)
  230. {
  231. // Check if there is a valid house-id in this slot
  232. if (APlayerData[playerid][Houses][i] != 0)
  233. {
  234. // Save the house (and linked vehicles)
  235. HouseFile_Save(APlayerData[playerid][Houses][i]);
  236. }
  237. }
  238. // Save all the valid business-id's
  239. for (new i; i < MAX_BUSINESSPERPLAYER; i++)
  240. {
  241. // Check if there is a valid business-id in this slot
  242. if (APlayerData[playerid][Business][i] != 0)
  243. {
  244. // Save the business
  245. BusinessFile_Save(APlayerData[playerid][Business][i]);
  246. }
  247. }
  248. return 1;
  249. }
  250. // This function loads all houses
  251. Housing_LoadAll()
  252. {
  253. // Loop through all houses and try to load them
  254. for (new HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
  255. {
  256. // Try to load the file and check if it was succesfully loaded (file exists)
  257. if (HouseFile_Load(HouseID) == 1)
  258. {
  259. // Add a pickup and 3DText for this house
  260. House_CreateEntrance(HouseID);
  261. // Count the amount of houses that are loaded
  262. TotalHouses++;
  263. }
  264. }
  265. return 1;
  266. }
  267. // This function will load the house's datafile (used when the server is started to load all houses)
  268. HouseFile_Load(HouseID, bool:OnlyLoadVehicles = false)
  269. {
  270. new file[100], File:HFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  271. // Setup local variables
  272. new cModel, cPaint, components[14], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, vid, bool:VehicleClamped, cFuel = -1;
  273. format(file, sizeof(file), HouseFile, HouseID); // Construct the complete filename for this house-file
  274. if (fexist(file))
  275. {
  276. HFile = fopen(file, io_read); // Open the housefile for reading
  277. fread(HFile, LineFromFile); // Read the first line of the file
  278. // Set the house so it cannot be entered by anyone, except the owner (close the house)
  279. AHouseData[HouseID][HouseOpened] = false;
  280. // Keep reading until the end of the file is found (no more data)
  281. while (strlen(LineFromFile) > 0)
  282. {
  283. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  284. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  285. // If OnlyLoadVehicles is "false", only load the house-data
  286. // If OnlyLoadVehicles is "true", only load the vehicle-data
  287. if (OnlyLoadVehicles == false)
  288. {
  289. // Store the proper value in the proper place
  290. if (strcmp(ParameterName, "HouseName", false) == 0) // If the parametername is correct ("HouseName")
  291. format(AHouseData[HouseID][HouseName], 24, ParameterValue); // Store the HouseName
  292. if (strcmp(ParameterName, "HouseX", false) == 0) // If the parametername is correct ("HouseX")
  293. AHouseData[HouseID][HouseX] = floatstr(ParameterValue); // Store the HouseX
  294. if (strcmp(ParameterName, "HouseY", false) == 0) // If the parametername is correct ("HouseY")
  295. AHouseData[HouseID][HouseY] = floatstr(ParameterValue); // Store the HouseY
  296. if (strcmp(ParameterName, "HouseZ", false) == 0) // If the parametername is correct ("HouseZ")
  297. AHouseData[HouseID][HouseZ] = floatstr(ParameterValue); // Store the HouseZ
  298. if (strcmp(ParameterName, "HouseLevel", false) == 0) // If the parametername is correct ("HouseLevel")
  299. AHouseData[HouseID][HouseLevel] = strval(ParameterValue); // Store the HouseLevel
  300. if (strcmp(ParameterName, "HouseMaxLevel", false) == 0) // If the parametername is correct ("HouseMaxLevel")
  301. AHouseData[HouseID][HouseMaxLevel] = strval(ParameterValue); // Store the HouseMaxLevel
  302. if (strcmp(ParameterName, "HousePrice", false) == 0) // If the parametername is correct ("HousePrice")
  303. AHouseData[HouseID][HousePrice] = strval(ParameterValue); // Store the HousePrice
  304. if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
  305. {
  306. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  307. AHouseData[HouseID][Owned] = true; // House is owned
  308. else
  309. AHouseData[HouseID][Owned] = false; // House is not owned
  310. }
  311. if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
  312. // Store the Owner (Owner will hold "1" if there is no owner (empty string), done by "sscanf" I guess)
  313. // But this doesn't matter, as the owner will never be displayed when the house is not owned by someone
  314. format(AHouseData[HouseID][Owner], 24, ParameterValue);
  315. if (strcmp(ParameterName, "Insurance", false) == 0) // If the parametername is correct ("Insurance")
  316. AHouseData[HouseID][Insurance] = strval(ParameterValue); // Store the Insurance
  317. }
  318. else // OnlyLoadVehicles is "true", so only read the vehicle-data
  319. {
  320. if (strcmp(ParameterName, "[Vehicle]", false) == 0) // If the parametername is correct ("[Vehicle]")
  321. {
  322. // Clear all data to start a new vehicle
  323. cModel = 0;
  324. cPaint = 0;
  325. cFuel = -1;
  326. for (new i; i < 14; i++)
  327. components[i] = 0;
  328. }
  329. if (strcmp(ParameterName, "VehicleModel", false) == 0) // If the parametername is correct ("VehicleModel")
  330. cModel = strval(ParameterValue); // Store the VehicleModel
  331. if (strcmp(ParameterName, "Fuel", false) == 0) // If the parametername is correct ("Fuel")
  332. cFuel = strval(ParameterValue); // Store the Fuel
  333. if (strcmp(ParameterName, "VehiclePaintJob", false) == 0) // If the parametername is correct ("VehiclePaintJob")
  334. cPaint = strval(ParameterValue); // Store the VehiclePaintJob
  335. if (strcmp(ParameterName, "VehicleSpoiler", false) == 0) // If the parametername is correct ("VehicleSpoiler")
  336. components[0] = strval(ParameterValue); // Store the VehicleSpoiler
  337. if (strcmp(ParameterName, "VehicleHood", false) == 0) // If the parametername is correct ("VehicleHood")
  338. components[1] = strval(ParameterValue); // Store the VehicleHood
  339. if (strcmp(ParameterName, "VehicleRoof", false) == 0) // If the parametername is correct ("VehicleRoof")
  340. components[2] = strval(ParameterValue); // Store the VehicleRoof
  341. if (strcmp(ParameterName, "VehicleSideSkirt", false) == 0) // If the parametername is correct ("VehicleSideSkirt")
  342. components[3] = strval(ParameterValue); // Store the VehicleSideSkirt
  343. if (strcmp(ParameterName, "VehicleLamps", false) == 0) // If the parametername is correct ("VehicleLamps")
  344. components[4] = strval(ParameterValue); // Store the VehicleLamps
  345. if (strcmp(ParameterName, "VehicleNitro", false) == 0) // If the parametername is correct ("VehicleNitro")
  346. components[5] = strval(ParameterValue); // Store the VehicleNitro
  347. if (strcmp(ParameterName, "VehicleExhaust", false) == 0) // If the parametername is correct ("VehicleExhaust")
  348. components[6] = strval(ParameterValue); // Store the VehicleExhaust
  349. if (strcmp(ParameterName, "VehicleWheels", false) == 0) // If the parametername is correct ("VehicleWheels")
  350. components[7] = strval(ParameterValue); // Store the VehicleWheels
  351. if (strcmp(ParameterName, "VehicleStereo", false) == 0) // If the parametername is correct ("VehicleStereo")
  352. components[8] = strval(ParameterValue); // Store the VehicleStereo
  353. if (strcmp(ParameterName, "VehicleHydraulics", false) == 0) // If the parametername is correct ("VehicleHydraulics")
  354. components[9] = strval(ParameterValue); // Store the VehicleHydraulics
  355. if (strcmp(ParameterName, "VehicleFrontBumper", false) == 0) // If the parametername is correct ("VehicleFrontBumper")
  356. components[10] = strval(ParameterValue); // Store the VehicleFrontBumper
  357. if (strcmp(ParameterName, "VehicleRearBumper", false) == 0) // If the parametername is correct ("VehicleRearBumper")
  358. components[11] = strval(ParameterValue); // Store the VehicleRearBumper
  359. if (strcmp(ParameterName, "VehicleVentRight", false) == 0) // If the parametername is correct ("VehicleVentRight")
  360. components[12] = strval(ParameterValue); // Store the VehicleVentRight
  361. if (strcmp(ParameterName, "VehicleVentLeft", false) == 0) // If the parametername is correct ("VehicleVentLeft")
  362. components[13] = strval(ParameterValue); // Store the VehicleVentLeft
  363. if (strcmp(ParameterName, "Color1", false) == 0) // If the parametername is correct ("Color1")
  364. Col1 = strval(ParameterValue); // Store the Color1
  365. if (strcmp(ParameterName, "Color2", false) == 0) // If the parametername is correct ("Color2")
  366. Col2 = strval(ParameterValue); // Store the Color2
  367. if (strcmp(ParameterName, "VehicleX", false) == 0) // If the parametername is correct ("VehicleX")
  368. cx = floatstr(ParameterValue); // Store the VehicleX
  369. if (strcmp(ParameterName, "VehicleY", false) == 0) // If the parametername is correct ("VehicleY")
  370. cy = floatstr(ParameterValue); // Store the VehicleY
  371. if (strcmp(ParameterName, "VehicleZ", false) == 0) // If the parametername is correct ("VehicleZ")
  372. cz = floatstr(ParameterValue); // Store the VehicleZ
  373. if (strcmp(ParameterName, "VehicleAngle", false) == 0) // If the parametername is correct ("VehicleAngle")
  374. crot = floatstr(ParameterValue); // Store the VehicleAngle
  375. if (strcmp(ParameterName, "Clamped", false) == 0) // If the parametername is correct ("Clamped")
  376. {
  377. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  378. VehicleClamped = true; // Vehicle is clamped
  379. else
  380. VehicleClamped = false; // Vehicle is not clamped
  381. }
  382. if (strcmp(ParameterName, "[/Vehicle]", false) == 0) // If the parametername is correct ("[/Vehicle]")
  383. {
  384. // Set both colors to 1 if they are 0 AND if there is a paintjob applied
  385. if ((Col1 == 0) && (cPaint != 0))
  386. Col1 = 1;
  387. if ((Col2 == 0) && (cPaint != 0))
  388. Col2 = 1;
  389. // The "[/Vehicle]" is found, this means that all data about this vehicle is now stored in the variables
  390. // Now add the vehicle to the house and set it's data
  391. vid = House_AddVehicle(HouseID, cModel, cPaint, components, cx, cy, cz, crot, Col1, Col2);
  392. AVehicleData[vid][Clamped] = VehicleClamped;
  393. // Also set the fuel (set it to maximum when the fuel parameter wasn't inside the file)
  394. if (cFuel == -1)
  395. AVehicleData[vid][Fuel] = MaxFuel;
  396. else // If the parameter was there, store it
  397. AVehicleData[vid][Fuel] = cFuel;
  398. }
  399. }
  400. // Read the next line of the file
  401. fread(HFile, LineFromFile);
  402. }
  403. // Check if the maximum house-level isn't 0 (when updating to the new version)
  404. if (AHouseData[HouseID][HouseMaxLevel] == 0)
  405. AHouseData[HouseID][HouseMaxLevel] = 10; // Set the maximum level to 10
  406. // Close the file
  407. fclose(HFile);
  408. // Return if the file was read correctly
  409. return 1;
  410. }
  411. else
  412. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  413. }
  414. // This function will save the given house
  415. HouseFile_Save(HouseID)
  416. {
  417. new file[100], File:HFile, LineForFile[100], vid;
  418. // Construct the complete filename for this house
  419. format(file, sizeof(file), HouseFile, HouseID);
  420. HFile = fopen(file, io_write); // Open the playerfile for writing
  421. format(LineForFile, 100, "HouseName %s\r\n", AHouseData[HouseID][HouseName]); // Construct the line: "HouseName <HouseName>"
  422. fwrite(HFile, LineForFile); // And save it to the file
  423. format(LineForFile, 100, "HouseX %f\r\n", AHouseData[HouseID][HouseX]); // Construct the line: "HouseX <HouseX>"
  424. fwrite(HFile, LineForFile); // And save it to the file
  425. format(LineForFile, 100, "HouseY %f\r\n", AHouseData[HouseID][HouseY]); // Construct the line: "HouseY <HouseY>"
  426. fwrite(HFile, LineForFile); // And save it to the file
  427. format(LineForFile, 100, "HouseZ %f\r\n", AHouseData[HouseID][HouseZ]); // Construct the line: "HouseZ <HouseZ>"
  428. fwrite(HFile, LineForFile); // And save it to the file
  429. format(LineForFile, 100, "HouseLevel %i\r\n", AHouseData[HouseID][HouseLevel]); // Construct the line: "HouseLevel <HouseLevel>"
  430. fwrite(HFile, LineForFile); // And save it to the file
  431. format(LineForFile, 100, "HouseMaxLevel %i\r\n", AHouseData[HouseID][HouseMaxLevel]); // Construct the line: "HouseMaxLevel <HouseMaxLevel>"
  432. fwrite(HFile, LineForFile); // And save it to the file
  433. format(LineForFile, 100, "HousePrice %i\r\n", AHouseData[HouseID][HousePrice]); // Construct the line: "HousePrice <HousePrice>"
  434. fwrite(HFile, LineForFile); // And save it to the file
  435. if (AHouseData[HouseID][Owned] == true) // Check if the house is owned
  436. {
  437. format(LineForFile, 100, "Owned Yes\r\n"); // Construct the line: "Owned Yes"
  438. fwrite(HFile, LineForFile); // And save it to the file
  439. }
  440. else
  441. {
  442. format(LineForFile, 100, "Owned No\r\n"); // Construct the line: "Owned No"
  443. fwrite(HFile, LineForFile); // And save it to the file
  444. }
  445. format(LineForFile, 100, "Owner %s\r\n", AHouseData[HouseID][Owner]); // Construct the line: "Owner <Owner>"
  446. fwrite(HFile, LineForFile); // And save it to the file
  447. format(LineForFile, 100, "Insurance %i\r\n", AHouseData[HouseID][Insurance]); // Construct the line: "Insurance <Insurance>"
  448. fwrite(HFile, LineForFile); // And save it to the file
  449. // Save the vehicle-data for every vehicle added to the house
  450. for (new CarSlot; CarSlot < 10; CarSlot++)
  451. {
  452. // If a valid vehicle-id has been found
  453. if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
  454. {
  455. // Get the vehicle id
  456. vid = AHouseData[HouseID][VehicleIDs][CarSlot];
  457. format(LineForFile, 100, "[Vehicle]\r\n"); // Construct the line: "[Vehicle]"
  458. fwrite(HFile, LineForFile); // And save it to the file
  459. format(LineForFile, 100, "VehicleModel %i\r\n", AVehicleData[vid][Model]); // Construct the line: "VehicleModel <VehicleModel>"
  460. fwrite(HFile, LineForFile); // And save it to the file
  461. format(LineForFile, 100, "Fuel %i\r\n", AVehicleData[vid][Fuel]); // Construct the line: "Fuel <Fuel>"
  462. fwrite(HFile, LineForFile); // And save it to the file
  463. format(LineForFile, 100, "VehiclePaintJob %i\r\n", AVehicleData[vid][PaintJob]); // Construct the line: "VehiclePaintJob <VehiclePaintJob>"
  464. fwrite(HFile, LineForFile); // And save it to the file
  465. format(LineForFile, 100, "VehicleSpoiler %i\r\n", AVehicleData[vid][Components][0]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
  466. fwrite(HFile, LineForFile); // And save it to the file
  467. format(LineForFile, 100, "VehicleHood %i\r\n", AVehicleData[vid][Components][1]); // Construct the line: "VehicleHood <VehicleHood>"
  468. fwrite(HFile, LineForFile); // And save it to the file
  469. format(LineForFile, 100, "VehicleRoof %i\r\n", AVehicleData[vid][Components][2]); // Construct the line: "VehicleRoof <VehicleRoof>"
  470. fwrite(HFile, LineForFile); // And save it to the file
  471. format(LineForFile, 100, "VehicleSideSkirt %i\r\n", AVehicleData[vid][Components][3]); // Construct the line: "VehicleSideSkirt <VehicleSideSkirt>"
  472. fwrite(HFile, LineForFile); // And save it to the file
  473. format(LineForFile, 100, "VehicleLamps %i\r\n", AVehicleData[vid][Components][4]); // Construct the line: "VehicleLamps <VehicleLamps>"
  474. fwrite(HFile, LineForFile); // And save it to the file
  475. format(LineForFile, 100, "VehicleNitro %i\r\n", AVehicleData[vid][Components][5]); // Construct the line: "VehicleNitro <VehicleNitro>"
  476. fwrite(HFile, LineForFile); // And save it to the file
  477. format(LineForFile, 100, "VehicleExhaust %i\r\n", AVehicleData[vid][Components][6]); // Construct the line: "VehicleSpoiler <VehicleSpoiler>"
  478. fwrite(HFile, LineForFile); // And save it to the file
  479. format(LineForFile, 100, "VehicleWheels %i\r\n", AVehicleData[vid][Components][7]); // Construct the line: "VehicleWheels <VehicleWheels>"
  480. fwrite(HFile, LineForFile); // And save it to the file
  481. format(LineForFile, 100, "VehicleStereo %i\r\n", AVehicleData[vid][Components][8]); // Construct the line: "VehicleStereo <VehicleStereo>"
  482. fwrite(HFile, LineForFile); // And save it to the file
  483. format(LineForFile, 100, "VehicleHydraulics %i\r\n", AVehicleData[vid][Components][9]); // Construct the line: "VehicleHydraulics <VehicleHydraulics>"
  484. fwrite(HFile, LineForFile); // And save it to the file
  485. format(LineForFile, 100, "VehicleFrontBumper %i\r\n", AVehicleData[vid][Components][10]); // Construct the line: "VehicleFrontBumper <VehicleFrontBumper>"
  486. fwrite(HFile, LineForFile); // And save it to the file
  487. format(LineForFile, 100, "VehicleRearBumper %i\r\n", AVehicleData[vid][Components][11]); // Construct the line: "VehicleRearBumper <VehicleRearBumper>"
  488. fwrite(HFile, LineForFile); // And save it to the file
  489. format(LineForFile, 100, "VehicleVentRight %i\r\n", AVehicleData[vid][Components][12]); // Construct the line: "VehicleVentRight <VehicleVentRight>"
  490. fwrite(HFile, LineForFile); // And save it to the file
  491. format(LineForFile, 100, "VehicleVentLeft %i\r\n", AVehicleData[vid][Components][13]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  492. fwrite(HFile, LineForFile); // And save it to the file
  493. format(LineForFile, 100, "Color1 %i\r\n", AVehicleData[vid][Color1]); // Construct the line: "Color1 <Color1>"
  494. fwrite(HFile, LineForFile); // And save it to the file
  495. format(LineForFile, 100, "Color2 %i\r\n", AVehicleData[vid][Color2]); // Construct the line: "Color2 <Color2>"
  496. fwrite(HFile, LineForFile); // And save it to the file
  497. format(LineForFile, 100, "VehicleX %f\r\n", AVehicleData[vid][SpawnX]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  498. fwrite(HFile, LineForFile); // And save it to the file
  499. format(LineForFile, 100, "VehicleY %f\r\n", AVehicleData[vid][SpawnY]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  500. fwrite(HFile, LineForFile); // And save it to the file
  501. format(LineForFile, 100, "VehicleZ %f\r\n", AVehicleData[vid][SpawnZ]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  502. fwrite(HFile, LineForFile); // And save it to the file
  503. format(LineForFile, 100, "VehicleAngle %f\r\n", AVehicleData[vid][SpawnRot]); // Construct the line: "VehicleVentLeft <VehicleVentLeft>"
  504. fwrite(HFile, LineForFile); // And save it to the file
  505. if (AVehicleData[vid][Clamped] == true)
  506. format(LineForFile, 100, "Clamped Yes\r\n"); // Construct the line: "Clamped <Yes>"
  507. else
  508. format(LineForFile, 100, "Clamped No\r\n"); // Construct the line: "Clamped <No>"
  509. fwrite(HFile, LineForFile); // And save it to the file
  510. format(LineForFile, 100, "[/Vehicle]\r\n"); // Construct the line: "[/Vehicle]"
  511. fwrite(HFile, LineForFile); // And save it to the file
  512. }
  513. }
  514. fclose(HFile); // Close the file
  515. return 1;
  516. }
  517. // This function loads all speedcameras
  518. Camera_LoadAll()
  519. {
  520. // Loop through all cameras and try to load them
  521. for (new CamID; CamID < MAX_CAMERAS; CamID++)
  522. {
  523. // Try to load the file and check if it was succesfully loaded (file exists)
  524. if (CameraFile_Load(CamID) == 1)
  525. {
  526. // Save the number of camera's that have been loaded, so it can be displayed
  527. TotalCameras++;
  528. }
  529. }
  530. return 1;
  531. }
  532. // This function will load the speedcamera's datafile (used when the server is started to load all cameras)
  533. CameraFile_Load(CamID)
  534. {
  535. // Setup local variables
  536. new file[100], File:CFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  537. new Float:x, Float:y, Float:z, Float:rot, MaxSpeed;
  538. format(file, sizeof(file), CameraFile, CamID); // Construct the complete filename for this camera-file
  539. if (fexist(file))
  540. {
  541. CFile = fopen(file, io_read); // Open the camerafile for reading
  542. fread(CFile, LineFromFile); // Read the first line of the file
  543. // Keep reading until the end of the file is found (no more data)
  544. while (strlen(LineFromFile) > 0)
  545. {
  546. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  547. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  548. // Store the proper value in the proper place
  549. if (strcmp(ParameterName, "CamX", false) == 0) // If the parametername is correct ("CamX")
  550. x = floatstr(ParameterValue); // Store the CamX
  551. if (strcmp(ParameterName, "CamY", false) == 0) // If the parametername is correct ("CamY")
  552. y = floatstr(ParameterValue); // Store the CamY
  553. if (strcmp(ParameterName, "CamZ", false) == 0) // If the parametername is correct ("CamZ")
  554. z = floatstr(ParameterValue); // Store the CamZ
  555. if (strcmp(ParameterName, "CamAngle", false) == 0) // If the parametername is correct ("CamAngle")
  556. rot = floatstr(ParameterValue); // Store the CamAngle
  557. if (strcmp(ParameterName, "CamSpeed", false) == 0) // If the parametername is correct ("CamSpeed")
  558. MaxSpeed = strval(ParameterValue); // Store the CamSpeed
  559. fread(CFile, LineFromFile); // Read the next line of the file
  560. }
  561. fclose(CFile); // Close the file
  562. // All data has been read about the camera, now setup the camera
  563. SetupSpeedCamera(CamID, x, y, z, rot, MaxSpeed);
  564. return 1; // Return that the file was read correctly
  565. }
  566. else
  567. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  568. }
  569. // This function loads all businesses
  570. Business_LoadAll()
  571. {
  572. // First load the business-time file, this one holds the current business-time which is increased every minute the server if online
  573. BusinessTime_Load();
  574. // Loop through all businesses and try to load them
  575. for (new BusID = 1; BusID < MAX_BUSINESS; BusID++)
  576. {
  577. // Try to load the file and check if it was succesfully loaded (file exists)
  578. if (BusinessFile_Load(BusID) == 1)
  579. {
  580. // Add a pickup and 3DText for this business
  581. Business_CreateEntrance(BusID);
  582. // Count the loaded businesses
  583. TotalBusiness++;
  584. }
  585. }
  586. return 1;
  587. }
  588. // This function loads the file that holds the current business-time
  589. BusinessTime_Load()
  590. {
  591. // Setup local variables
  592. new File:BFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  593. // Try to load the businesstime file
  594. if (fexist("ServerData/Business/BusinessTime.ini"))
  595. {
  596. BFile = fopen("ServerData/Business/BusinessTime.ini", io_read); // Open the businesstime-file for reading
  597. fread(BFile, LineFromFile); // Read the first line of the file
  598. // Keep reading until the end of the file is found (no more data)
  599. while (strlen(LineFromFile) > 0)
  600. {
  601. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  602. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  603. // Store the proper value in the proper place
  604. if (strcmp(ParameterName, "BusinessTime", false) == 0) // If the parametername is correct ("BusinessTime")
  605. BusinessTransactionTime = strval(ParameterValue); // Store the BusinessTime
  606. // Read the next line of the file
  607. fread(BFile, LineFromFile);
  608. }
  609. // Close the file
  610. fclose(BFile);
  611. // Return if the file was read correctly
  612. return 1;
  613. }
  614. else
  615. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  616. }
  617. // This function saves the file that holds the current business-time
  618. BusinessTime_Save()
  619. {
  620. new File:BFile, LineForFile[100];
  621. BFile = fopen("ServerData/Business/BusinessTime.ini", io_write); // Open the businesstime-file for writing
  622. format(LineForFile, 100, "BusinessTime %i\r\n", BusinessTransactionTime); // Construct the line: "BusinessTime <BusinessTransactionTime>"
  623. fwrite(BFile, LineForFile); // And save it to the file
  624. fclose(BFile); // Close the file
  625. return 1;
  626. }
  627. // This function will load the business's datafile (used when the server is started to load all businesses)
  628. BusinessFile_Load(BusID)
  629. {
  630. // Setup local variables
  631. new file[100], File:BFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  632. format(file, sizeof(file), BusinessFile, BusID); // Construct the complete filename for this business-file
  633. if (fexist(file))
  634. {
  635. BFile = fopen(file, io_read); // Open the housefile for reading
  636. fread(BFile, LineFromFile); // Read the first line of the file
  637. // Keep reading until the end of the file is found (no more data)
  638. while (strlen(LineFromFile) > 0)
  639. {
  640. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  641. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  642. // Store the proper value in the proper place
  643. if (strcmp(ParameterName, "BusinessName", false) == 0) // If the parametername is correct ("BusinessName")
  644. format(ABusinessData[BusID][BusinessName], 24, ParameterValue); // Store the BusinessName
  645. if (strcmp(ParameterName, "BusinessX", false) == 0) // If the parametername is correct ("BusinessX")
  646. ABusinessData[BusID][BusinessX] = floatstr(ParameterValue); // Store the BusinessX
  647. if (strcmp(ParameterName, "BusinessY", false) == 0) // If the parametername is correct ("BusinessY")
  648. ABusinessData[BusID][BusinessY] = floatstr(ParameterValue); // Store the BusinessY
  649. if (strcmp(ParameterName, "BusinessZ", false) == 0) // If the parametername is correct ("BusinessZ")
  650. ABusinessData[BusID][BusinessZ] = floatstr(ParameterValue); // Store the BusinessZ
  651. if (strcmp(ParameterName, "BusinessType", false) == 0) // If the parametername is correct ("BusinessType")
  652. ABusinessData[BusID][BusinessType] = strval(ParameterValue); // Store the BusinessType
  653. if (strcmp(ParameterName, "BusinessLevel", false) == 0) // If the parametername is correct ("BusinessLevel")
  654. ABusinessData[BusID][BusinessLevel] = strval(ParameterValue); // Store the BusinessLevel
  655. if (strcmp(ParameterName, "LastTransaction", false) == 0) // If the parametername is correct ("LastTransaction")
  656. ABusinessData[BusID][LastTransaction] = strval(ParameterValue); // Store the LastTransaction
  657. if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
  658. {
  659. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  660. ABusinessData[BusID][Owned] = true; // House is owned
  661. else
  662. ABusinessData[BusID][Owned] = false; // House is not owned
  663. }
  664. if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
  665. format(ABusinessData[BusID][Owner], 24, ParameterValue);
  666. // Read the next line of the file
  667. fread(BFile, LineFromFile);
  668. }
  669. // Close the file
  670. fclose(BFile);
  671. // Return if the file was read correctly
  672. return 1;
  673. }
  674. else
  675. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  676. }
  677. // This function will save the given business
  678. BusinessFile_Save(BusID)
  679. {
  680. new file[100], File:BFile, LineForFile[100];
  681. // Construct the complete filename for this business
  682. format(file, sizeof(file), BusinessFile, BusID);
  683. BFile = fopen(file, io_write); // Open the business-file for writing
  684. format(LineForFile, 100, "BusinessName %s\r\n", ABusinessData[BusID][BusinessName]); // Construct the line: "BusinessName <BusinessName>"
  685. fwrite(BFile, LineForFile); // And save it to the file
  686. format(LineForFile, 100, "BusinessX %f\r\n", ABusinessData[BusID][BusinessX]); // Construct the line: "BusinessX <BusinessX>"
  687. fwrite(BFile, LineForFile); // And save it to the file
  688. format(LineForFile, 100, "BusinessY %f\r\n", ABusinessData[BusID][BusinessY]); // Construct the line: "BusinessY <BusinessY>"
  689. fwrite(BFile, LineForFile); // And save it to the file
  690. format(LineForFile, 100, "BusinessZ %f\r\n", ABusinessData[BusID][BusinessZ]); // Construct the line: "BusinessZ <BusinessZ>"
  691. fwrite(BFile, LineForFile); // And save it to the file
  692. format(LineForFile, 100, "BusinessType %i\r\n", ABusinessData[BusID][BusinessType]); // Construct the line: "BusinessType <BusinessType>"
  693. fwrite(BFile, LineForFile); // And save it to the file
  694. format(LineForFile, 100, "BusinessLevel %i\r\n", ABusinessData[BusID][BusinessLevel]); // Construct the line: "BusinessLevel <BusinessLevel>"
  695. fwrite(BFile, LineForFile); // And save it to the file
  696. format(LineForFile, 100, "LastTransaction %i\r\n", ABusinessData[BusID][LastTransaction]); // Construct the line: "LastTransaction <LastTransaction>"
  697. fwrite(BFile, LineForFile); // And save it to the file
  698. if (ABusinessData[BusID][Owned] == true) // Check if the house is owned
  699. {
  700. format(LineForFile, 100, "Owned Yes\r\n"); // Construct the line: "Owned Yes"
  701. fwrite(BFile, LineForFile); // And save it to the file
  702. }
  703. else
  704. {
  705. format(LineForFile, 100, "Owned No\r\n"); // Construct the line: "Owned No"
  706. fwrite(BFile, LineForFile); // And save it to the file
  707. }
  708. format(LineForFile, 100, "Owner %s\r\n", ABusinessData[BusID][Owner]); // Construct the line: "Owner <Owner>"
  709. fwrite(BFile, LineForFile); // And save it to the file
  710. fclose(BFile); // Close the file
  711. return 1;
  712. }
  713. // This function will load the player's bank account and process transfers that were made to his account when he was offline
  714. BankFile_Load(playerid)
  715. {
  716. // Setup local variables
  717. new file[100], File:BFile, Name[24], LineFromFile[100], ParameterName[50], ParameterValue[50];
  718. new TransferMoney, TransferName[24], TransferTime[24], Msg[128];
  719. new IntrestAmount, OldBankMoney, NewBankMoney;
  720. format(Name, sizeof(Name), APlayerData[playerid][PlayerName]); // Get the playername
  721. format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's bank-account
  722. if (fexist(file))
  723. {
  724. // Send a message to the player to inform him that he has a bank account
  725. SendClientMessage(playerid, 0xFFFFFFFF, "{00BBFF}You have a bank-account. Use {FFBB00}/bank{00BBFF} to login");
  726. BFile = fopen(file, io_read); // Open the bankfile for reading
  727. fread(BFile, LineFromFile); // Read the first line of the file
  728. // Keep reading until the end of the file is found (no more data)
  729. while (strlen(LineFromFile) > 0)
  730. {
  731. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  732. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  733. // Store the proper value in the proper place
  734. if (strcmp(ParameterName, "Password", false) == 0) // If the parametername is correct ("Password")
  735. format(APlayerData[playerid][BankPassword], 24, ParameterValue); // Store the Password
  736. if (strcmp(ParameterName, "Money", false) == 0) // If the parametername is correct ("Money")
  737. APlayerData[playerid][BankMoney] = strval(ParameterValue); // Store the Money
  738. if (strcmp(ParameterName, "LastIntrestTime", false) == 0) // If the parametername is correct ("LastIntrestTime")
  739. APlayerData[playerid][LastIntrestTime] = strval(ParameterValue); // Store the LastIntrestTime
  740. // Process transfer-data
  741. if (strcmp(ParameterName, "[Transfer]", false) == 0) // If the parametername is correct ("[Transfer]")
  742. {
  743. TransferMoney = 0; // Clear the money variable
  744. for (new i; i < sizeof(TransferName); i++) // Clear the name variable
  745. TransferName[i] = 0;
  746. for (new i; i < sizeof(TransferTime); i++) // Clear the time variable
  747. TransferTime[i] = 0;
  748. }
  749. if (strcmp(ParameterName, "TransferMoney", false) == 0) // If the parametername is correct ("TransferMoney")
  750. TransferMoney = strval(ParameterValue); // Store the TransferMoney
  751. if (strcmp(ParameterName, "TransferName", false) == 0) // If the parametername is correct ("TransferName")
  752. format(TransferName, sizeof(TransferName), ParameterValue); // Store the TransferName
  753. if (strcmp(ParameterName, "TransferTime", false) == 0) // If the parametername is correct ("TransferTime")
  754. format(TransferTime, sizeof(TransferTime), ParameterValue); // Store the TransferTime
  755. if (strcmp(ParameterName, "[/Transfer]", false) == 0) // If the parametername is correct ("[/Transfer]")
  756. {
  757. // Add the money to your bank-account that was transferred by another player
  758. APlayerData[playerid][BankMoney] = APlayerData[playerid][BankMoney] + TransferMoney;
  759. // Inform the player that a player has transferred some money to your bank account
  760. format(Msg, 128, "{00BBFF}Player {FFBB00}%s{00BBFF} has transferred {FFBB00}$%i{00BBFF}", TransferName, TransferMoney);
  761. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  762. format(Msg, 128, "{00BBFF}to your bank account on {FFBB00}%s", TransferTime);
  763. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  764. }
  765. // Read the next line of the file
  766. fread(BFile, LineFromFile);
  767. }
  768. // Close the file
  769. fclose(BFile);
  770. // Process intrest if intrest is enabled for the time the player was offline
  771. if (IntrestEnabled == true)
  772. {
  773. // Check if the player has any money in his bank account (adding intrest to $0 is useless)
  774. if (APlayerData[playerid][BankMoney] > 0)
  775. {
  776. // Also process intrest for this bank account for every hour the player was offline
  777. if (APlayerData[playerid][LastIntrestTime] < CurrentIntrestTime)
  778. {
  779. // Get the old amount of money
  780. OldBankMoney = APlayerData[playerid][BankMoney];
  781. // Count the hours the player was offline and didn't receive intrest yet
  782. for (new i; i < (CurrentIntrestTime - APlayerData[playerid][LastIntrestTime]); i++)
  783. {
  784. // Calculate the intrest
  785. IntrestAmount = floatround(floatmul(APlayerData[playerid][BankMoney], BankIntrest), floatround_floor);
  786. // Add the intrest to this player's bank account
  787. APlayerData[playerid][BankMoney] = APlayerData[playerid][BankMoney] + IntrestAmount;
  788. }
  789. // Get the new amount of money
  790. NewBankMoney = APlayerData[playerid][BankMoney];
  791. // Save the CurrentIntrestTime for this bank account
  792. APlayerData[playerid][LastIntrestTime] = CurrentIntrestTime;
  793. // Inform the player that he received intrest on his bank account and how much
  794. format(Msg, 128, "{00BBFF}You've received {FFBB00}$%i{00BBFF} intrest on your bank account", NewBankMoney - OldBankMoney);
  795. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  796. }
  797. }
  798. }
  799. // Re-save the bank account (in case intrest and transfers have been processed)
  800. BankFile_Save(playerid);
  801. // Return if the file was read correctly
  802. return 1;
  803. }
  804. else
  805. {
  806. // Send a message if the player doesn't have a bank account
  807. SendClientMessage(playerid, 0xFFFFFFFF, "{00BBFF}You don't have a bank-account. Use {FFBB00}/bank{00BBFF} to set it up");
  808. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  809. }
  810. }
  811. // This function will save the player's bank account
  812. BankFile_Save(playerid)
  813. {
  814. // Setup local variables
  815. new file[100], File:BFile, LineForFile[100], Name[24];
  816. format(Name, sizeof(Name), APlayerData[playerid][PlayerName]); // Get the playername
  817. format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's bank-account
  818. BFile = fopen(file, io_write); // Open the business-file for writing
  819. format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][BankPassword]); // Construct the line: "Password <BankPassword>"
  820. fwrite(BFile, LineForFile); // And save it to the file
  821. format(LineForFile, 100, "Money %i\r\n", APlayerData[playerid][BankMoney]); // Construct the line: "Money <BankMoney>"
  822. fwrite(BFile, LineForFile); // And save it to the file
  823. format(LineForFile, 100, "LastIntrestTime %i\r\n", APlayerData[playerid][LastIntrestTime]); // Construct the line: "LastIntrestTime <LastIntrestTime>"
  824. fwrite(BFile, LineForFile); // And save it to the file
  825. fclose(BFile); // Close the file
  826. return 1;
  827. }
  828. // This function loads the file that holds the current intrest-time
  829. IntrestTime_Load()
  830. {
  831. // Setup local variables
  832. new File:BFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  833. // Try to load the businesstime file
  834. if (fexist("ServerData/Bank/IntrestTime.ini"))
  835. {
  836. BFile = fopen("ServerData/Bank/IntrestTime.ini", io_read); // Open the intrest-time-file for reading
  837. fread(BFile, LineFromFile); // Read the first line of the file
  838. // Keep reading until the end of the file is found (no more data)
  839. while (strlen(LineFromFile) > 0)
  840. {
  841. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  842. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  843. // Store the proper value in the proper place
  844. if (strcmp(ParameterName, "CurrentIntrestTime", false) == 0) // If the parametername is correct ("CurrentIntrestTime")
  845. CurrentIntrestTime = strval(ParameterValue); // Store the CurrentIntrestTime
  846. // Read the next line of the file
  847. fread(BFile, LineFromFile);
  848. }
  849. // Close the file
  850. fclose(BFile);
  851. // Return if the file was read correctly
  852. return 1;
  853. }
  854. else
  855. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  856. }
  857. // This function saves the file that holds the current intrest-time
  858. IntrestTime_Save()
  859. {
  860. new File:BFile, LineForFile[100];
  861. BFile = fopen("ServerData/Bank/IntrestTime.ini", io_write); // Open the intresttime-file for writing
  862. format(LineForFile, 100, "CurrentIntrestTime %i\r\n", CurrentIntrestTime); // Construct the line: "CurrentIntrestTime <CurrentIntrestTime>"
  863. fwrite(BFile, LineForFile); // And save it to the file
  864. fclose(BFile); // Close the file
  865. return 1;
  866. }