Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.98 KB | None | 0 0
  1. // Make sure you don't get warnings about tabsize
  2. #pragma tabsize 0
  3.  
  4. // Include default files
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <sscanf2>
  8. #include <streamer>
  9.  
  10.  
  11.  
  12. // ******************************************************************************************************************************
  13. // Settings that can be changed
  14. // ******************************************************************************************************************************
  15.  
  16. // Default max number of players is set to 500, re-define it to 50
  17. #undef MAX_PLAYERS
  18. #define MAX_PLAYERS 50
  19.  
  20. // Define housing parameters
  21. #define MAX_BUSINESS 500 // Defines the maximum number of businesses that can be created
  22. #define MAX_BUSINESSPERPLAYER 20 // Defines the maximum number of businesses that any player can own (useable values: 1 to 20)
  23.  
  24. // Define path to business-files
  25. #define BusinessFile "PPC_Business/Business%i.ini"
  26. #define BusinessTimeFile "PPC_Business/BusinessTime.ini"
  27.  
  28. // Set the exit-time for exiting a business (required if you use custom-made islands, otherwise you'll fall into the water)
  29. // Default: 1 second (1000 milliseconds)
  30. new ExitBusinessTimer = 1000;
  31.  
  32.  
  33.  
  34.  
  35. // Define Dialogs
  36. #define DialogCreateBusSelType 2001
  37. #define DialogBusinessNameChange 2002
  38. #define DialogSellBusiness 2003
  39. #define DialogBusinessMenu 2004
  40. #define DialogGoBusiness 2005
  41.  
  42.  
  43.  
  44. // ******************************************************************************************************************************
  45. // Enums and the array-setups that use them
  46. // ******************************************************************************************************************************
  47.  
  48. // Setup a custom type that holds all data for businesses
  49. enum TBusinessData
  50. {
  51. PickupID, // Holds the pickup-id that is linked to this business
  52. Text3D:DoorText, // Holds the reference to the 3DText above the business's pickup
  53. MapIconID, // Holds the ID of the mapicon for the business
  54.  
  55. BusinessName[100], // Holds the name of the business (this will be displayed above the pickup near the business when it's owned)
  56. Float:BusinessX, // Holds the X-coordinate of the pickup for the Business
  57. Float:BusinessY, // Holds the Y-coordinate of the pickup for the Business
  58. Float:BusinessZ, // Holds the Z-coordinate of the pickup for the Business
  59. BusinessType, // Holds the type of business (well stacked pizza, burger shot, ...), this defines which icon and interior to use
  60. BusinessLevel, // Holds the level of upgrades the business has
  61. LastTransaction, // Holds the amount of minutes when the last transaction took place (buying the business or retrieving the money by the owner)
  62. bool:Owned, // Holds true if the Business is owned by somebody
  63. Owner[24] // Holds the name of the owner of the Business
  64. }
  65. // Holds the data for all houses
  66. new ABusinessData[MAX_BUSINESS][TBusinessData];
  67. // This variable holds the business-time (this value is increased every hour and is used to calculate the amount of money a business
  68. // has generated after the last transaction of the business)
  69. new BusinessTransactionTime;
  70.  
  71.  
  72.  
  73. // Setup a custom type that holds all data about a business
  74. enum TBusinessType
  75. {
  76. InteriorName[50], // Holds the name of the interior
  77. InteriorID, // Holds the interior-id
  78. Float:IntX, // Holds the X-coordinate of the spawn-location where you enter the business
  79. Float:IntY, // Holds the Y-coordinate of the spawn-location where you enter the business
  80. Float:IntZ, // Holds the Z-coordinate of the spawn-location where you enter the business
  81. BusPrice, // Holds the price for the business
  82. BusEarnings, // Holds the earnings for this type of business (a business earns this money every minute even when the player is offline)
  83. // The earnings may not seem that high, but earning $5 every minute will earn you $7200 every day, even when you're offline
  84. // These are multiplied by the level of your business, so a level 5 business earns you $36000 every day
  85. // Using the default buying prices, you'll need about 70 days to refund your business and start making money with it
  86. IconID // Holds the icon-id which represents the business
  87. }
  88. // Holds the data for all interiors for businesses
  89. new ABusinessInteriors[][TBusinessType] =
  90. {
  91. {"Dummy", 0, 0.0, 0.0, 0.0, 0, 0, 0}, // Dummy business (Type 0), never used
  92. {"24/7 (Small)", 6, -26.75, -55.75, 1003.6, 500000, 5, 52}, // Type 1 (earnings per day: $7200)
  93. {"24/7 (Medium)", 18, -31.0, -89.5, 1003.6, 700000, 7, 52}, // Type 2 (earnings per day: $10080)
  94. {"Bar", 11, 502.25, -69.75, 998.8, 400000, 4, 49}, // Type 3 (earnings per day: $5760)
  95. {"Barber (Small)", 2, 411.5, -21.25, 1001.8, 300000, 3, 7}, // Type 4 (earnings per day: $4320)
  96. {"Barber (Medium)", 3, 418.75, -82.5, 1001.8, 400000, 4, 7}, // Type 5 (earnings per day: $5760)
  97. {"Betting shop", 3, 833.25, 7.0, 1004.2, 1500000, 15, 52}, // Type 6 (earnings per day: $21600)
  98. {"Burger Shot", 10, 363.5, -74.5, 1001.5, 700000, 7, 10}, // Type 7 (earnings per day: $10080)
  99. {"Casino (4 Dragons)", 10, 2017.25, 1017.75, 996.9, 2500000, 25, 44}, // Type 8 (earnings per day: $36000)
  100. {"Casino (Caligula's)", 1, 2234.0, 1710.75, 1011.3, 2500000, 25, 25}, // Type 9 (earnings per day: $36000)
  101. {"Casino (Small)", 12, 1133.0, -9.5, 1000.7, 2000000, 20, 43}, // Type 10 (earnings per day: $28800)
  102. {"Clothing (Binco)", 15, 207.75, -109.0, 1005.2, 800000, 8, 45}, // Type 11 (earnings per day: $11520)
  103. {"Clothing (Pro)", 3, 207.0, -138.75, 1003.5, 800000, 8, 45}, // Type 12 (earnings per day: $11520)
  104. {"Clothing (Urban)", 1, 203.75, -48.5, 1001.8, 800000, 8, 45}, // Type 13 (earnings per day: $11520)
  105. {"Clothing (Victim)", 5, 226.25, -7.5, 1002.3, 800000, 8, 45}, // Type 14 (earnings per day: $11520)
  106. {"Clothing (ZIP)", 18, 161.5, -92.25, 1001.8, 800000, 8, 45}, // Type 15 (earnings per day: $11520)
  107. {"Cluckin' Bell", 9, 365.75, -10.75, 1001.9, 700000, 7, 14}, // Type 16 (earnings per day: $10080)
  108. {"Disco (Small)", 17, 492.75, -22.0, 1000.7, 1000000, 10, 48}, // Type 17 (earnings per day: $14400)
  109. {"Disco (Large)", 3, -2642.0, 1406.5, 906.5, 1200000, 12, 48}, // Type 18 (earnings per day: $17280)
  110. {"Gym (LS)", 5, 772.0, -3.0, 1000.8, 500000, 5, 54}, // Type 19 (earnings per day: $7200)
  111. {"Gym (SF)", 6, 774.25, -49.0, 1000.6, 500000, 5, 54}, // Type 20 (earnings per day: $7200)
  112. {"Gym (LV)", 7, 774.25, -74.0, 1000.7, 500000, 5, 54}, // Type 21 (earnings per day: $7200)
  113. {"Motel", 15, 2216.25, -1150.5, 1025.8, 1000000, 10, 37}, // Type 22 (earnings per day: $14400)
  114. {"RC shop", 6, -2238.75, 131.0, 1035.5, 600000, 6, 46}, // Type 23 (earnings per day: $8640)
  115. {"Sex-shop", 3, -100.25, -22.75, 1000.8, 800000, 8, 38}, // Type 24 (earnings per day: $11520)
  116. {"Slaughterhouse", 1, 933.75, 2151.0, 1011.1, 500000, 5, 50}, // Type 25 (earnings per day: $7200)
  117. {"Stadium (Bloodbowl)", 15, -1394.25, 987.5, 1024.0, 1700000, 17, 33}, // Type 26 (earnings per day: $24480)
  118. {"Stadium (Kickstart)", 14, -1410.75, 1591.25, 1052.6, 1700000, 17, 33}, // Type 27 (earnings per day: $24480)
  119. {"Stadium (8-Track)", 7, -1396.0, -208.25, 1051.2, 1700000, 17, 33}, // Type 28 (earnings per day: $24480)
  120. {"Stadium (Dirt Bike)", 4, -1425.0, -664.5, 1059.9, 1700000, 17, 33}, // Type 29 (earnings per day: $24480)
  121. {"Stripclub (Small)", 3, 1212.75, -30.0, 1001.0, 700000, 7, 48}, // Type 30 (earnings per day: $10080)
  122. {"Stripclub (Large)", 2, 1204.75, -12.5, 1001.0, 900000, 9, 48}, // Type 31 (earnings per day: $12960)
  123. {"Tattoo LS", 16, -203.0, -24.25, 1002.3, 500000, 5, 39}, // Type 32 (earnings per day: $7200)
  124. {"Well Stacked Pizza", 5, 372.25, -131.50, 1001.5, 600000, 6, 29} // Type 33 (earnings per day: $8640)
  125. };
  126.  
  127.  
  128.  
  129. // Setup all the fields required for the player data (Speedometer TextDraw, current job, ...)
  130. enum TPlayerData
  131. {
  132. Business[20], // Holds the BusinessID's of the businesses that the player owns (index of the ABusinessData array), maximum 20 businesses per player
  133. CurrentBusiness // Holds the BusinessID to track in which business the player currently is (used when accessing the businessmenu)
  134. }
  135. // Create an array to hold the playerdata for every player
  136. new APlayerData[MAX_PLAYERS][TPlayerData];
  137.  
  138.  
  139.  
  140. // These variables are used when starting the script and debugging purposes
  141. new TotalBusiness;
  142.  
  143.  
  144.  
  145. // ******************************************************************************************************************************
  146. // Callbacks
  147. // ******************************************************************************************************************************
  148.  
  149. // The main function (used only once when the server loads)
  150. main()
  151. {
  152. }
  153.  
  154. // This callback gets called when the server initializes the filterscript
  155. public OnFilterScriptInit()
  156. {
  157. // Load the businesstime-file (which holds the current time for the businesses, used for calculating the earnings every minute)
  158. BusinessTime_Load();
  159.  
  160. // Loop through all businesses and try to load them (BusID 0 isn't used)
  161. for (new BusID = 1; BusID < MAX_BUSINESS; BusID++)
  162. BusinessFile_Load(BusID); // Try to load the business-file
  163.  
  164. // Start the businesstimer and run it every minute
  165. SetTimer("Business_TransactionTimer", 1000 * 60, true);
  166.  
  167. // Print information about the filterscript on the server-console
  168. printf("-------------------------------------");
  169. printf("PPC Business filterscript initialized");
  170. printf("Businesses loaded: %i", TotalBusiness);
  171. printf("-------------------------------------");
  172.  
  173. return 1;
  174. }
  175.  
  176. // This callback gets called when a player connects to the server
  177. public OnPlayerConnect(playerid)
  178. {
  179. // Setup local variables
  180. new BusID, BusSlot, Name[24];
  181.  
  182. // Get the player's name
  183. GetPlayerName(playerid, Name, sizeof(Name));
  184.  
  185. // Loop through all businesses to find the ones which belong to this player
  186. for (BusID = 1; BusID < MAX_BUSINESS; BusID++)
  187. {
  188. // Check if the business exists
  189. if (IsValidDynamicPickup(ABusinessData[BusID][PickupID]))
  190. {
  191. // Check if the business is owned
  192. if (ABusinessData[BusID][Owned] == true)
  193. {
  194. // Check if the player is the owner of the business
  195. if (strcmp(ABusinessData[BusID][Owner], Name, false) == 0)
  196. {
  197. // Add the BusID to the player's account for faster reference later on
  198. APlayerData[playerid][Business][BusSlot] = BusID;
  199.  
  200. // Select the next BusSlot
  201. BusSlot++;
  202. }
  203. }
  204. }
  205. }
  206.  
  207. return 1;
  208. }
  209.  
  210. // This callback gets called when a player disconnects from the server
  211. public OnPlayerDisconnect(playerid, reason)
  212. {
  213. // Setup local variables
  214. new BusSlot;
  215.  
  216. // Loop through all businesses the player owns
  217. for (BusSlot = 0; BusSlot < MAX_BUSINESSPERPLAYER; BusSlot++)
  218. {
  219. // Check if the player has a business in this busslot
  220. if (APlayerData[playerid][Business][BusSlot] != 0)
  221. {
  222. // Save the Busfile
  223. BusinessFile_Save(APlayerData[playerid][Business][BusSlot]);
  224.  
  225. // Clear the BusID stored in this busslot
  226. APlayerData[playerid][Business][BusSlot] = 0;
  227. }
  228. }
  229.  
  230. // Clear all data for this player
  231. APlayerData[playerid][CurrentBusiness] = 0;
  232.  
  233. return 1;
  234. }
  235.  
  236. // This callback gets called when a player interacts with a dialog
  237. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  238. {
  239. // Select the proper dialog to process
  240. switch (dialogid)
  241. {
  242. case DialogCreateBusSelType: Dialog_CreateBusSelType(playerid, response, listitem);
  243. case DialogBusinessMenu: Dialog_BusinessMenu(playerid, response, listitem);
  244. case DialogGoBusiness: Dialog_GoBusiness(playerid, response, listitem);
  245. case DialogBusinessNameChange: Dialog_ChangeBusinessName(playerid, response, inputtext); // Change the name of your business
  246. case DialogSellBusiness: Dialog_SellBusiness(playerid, response); // Sell the business
  247. }
  248.  
  249. return 0;
  250. }
  251.  
  252. // This callback gets called when a player spawns somewhere
  253. public OnPlayerSpawn(playerid)
  254. {
  255. // Reset the BusID where the player is located
  256. APlayerData[playerid][CurrentBusiness] = 0;
  257.  
  258. return 1;
  259. }
  260.  
  261. // This callback gets called whenever a player dies
  262. public OnPlayerDeath(playerid, killerid, reason)
  263. {
  264. // Reset the BusID where the player is located
  265. APlayerData[playerid][CurrentBusiness] = 0;
  266.  
  267. return 1;
  268. }
  269.  
  270. // This callback gets called when the player is selecting a class (but hasn't clicked "Spawn" yet)
  271. public OnPlayerRequestClass(playerid, classid)
  272. {
  273. // Reset the BusID where the player is located
  274. APlayerData[playerid][CurrentBusiness] = 0;
  275.  
  276. return 1;
  277. }
  278.  
  279. // This callback is called when the player attempts to spawn via class-selection
  280. public OnPlayerRequestSpawn(playerid)
  281. {
  282. // Reset the BusID where the player is located
  283. APlayerData[playerid][CurrentBusiness] = 0;
  284.  
  285. return 1;
  286. }
  287.  
  288.  
  289.  
  290. // ******************************************************************************************************************************
  291. // Commands
  292. // ******************************************************************************************************************************
  293.  
  294. // Lets the player add new businesses
  295. COMMAND:createbusiness(playerid, params[])
  296. {
  297. // If a player hasn't logged in properly, he cannot use this command
  298. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  299. // If the player has an insufficient admin-level (he needs level 5 or RCON admin), exit the command
  300. // returning "SERVER: Unknown command" to the player
  301. if (INT_CheckPlayerAdminLevel(playerid, 5) == 0) return 0;
  302.  
  303. // Setup local variables
  304. new BusinessList[2000];
  305.  
  306. // Check if the player isn't inside a vehicle
  307. if (GetPlayerVehicleSeat(playerid) == -1)
  308. {
  309. // Construct the list of businesses
  310. for (new BusType = 1; BusType < sizeof(ABusinessInteriors); BusType++)
  311. {
  312. format(BusinessList, sizeof(BusinessList), "%s%s\n", BusinessList, ABusinessInteriors[BusType][InteriorName]);
  313. }
  314.  
  315. // Let the player choose a business-type via a dialog
  316. ShowPlayerDialog(playerid, DialogCreateBusSelType, DIALOG_STYLE_LIST, "Choose business-type:", BusinessList, "Select", "Cancel");
  317. }
  318. else
  319. SendClientMessage(playerid, 0xFF0000FF, "You must be on foot to create a business");
  320.  
  321. // Let the server know that this was a valid command
  322. return 1;
  323. }
  324.  
  325. // This command lets the player delete a business
  326. COMMAND:delbusiness(playerid, params[])
  327. {
  328. // If a player hasn't logged in properly, he cannot use this command
  329. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  330. // If the player has an insufficient admin-level (he needs level 5 or RCON admin), exit the command
  331. // returning "SERVER: Unknown command" to the player
  332. if (INT_CheckPlayerAdminLevel(playerid, 5) == 0) return 0;
  333.  
  334. // Setup local variables
  335. new file[100], Msg[128];
  336.  
  337. // Make sure the player isn't inside a vehicle
  338. if (GetPlayerVehicleSeat(playerid) == -1)
  339. {
  340. // Loop through all player-owned businesses
  341. for (new BusID = 1; BusID < MAX_BUSINESS; BusID++)
  342. {
  343. // Check if the business exists
  344. if (IsValidDynamicPickup(ABusinessData[BusID][PickupID]))
  345. {
  346. // Check if the business has no owner
  347. if (ABusinessData[BusID][Owned] == false)
  348. {
  349. // Check if the player is in range of the business-pickup
  350. if (IsPlayerInRangeOfPoint(playerid, 2.5, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]))
  351. {
  352. // Clear all data of the business
  353. ABusinessData[BusID][BusinessName] = 0;
  354. ABusinessData[BusID][BusinessX] = 0.0;
  355. ABusinessData[BusID][BusinessY] = 0.0;
  356. ABusinessData[BusID][BusinessZ] = 0.0;
  357. ABusinessData[BusID][BusinessType] = 0;
  358. ABusinessData[BusID][BusinessLevel] = 0;
  359. ABusinessData[BusID][LastTransaction] = 0;
  360. ABusinessData[BusID][Owned] = false;
  361. ABusinessData[BusID][Owner] = 0;
  362. // Destroy the mapicon, 3DText and pickup for the house
  363. DestroyDynamicPickup(ABusinessData[BusID][PickupID]);
  364. DestroyDynamicMapIcon(ABusinessData[BusID][MapIconID]);
  365. DestroyDynamic3DTextLabel(ABusinessData[BusID][DoorText]);
  366. ABusinessData[BusID][PickupID] = 0;
  367. ABusinessData[BusID][MapIconID] = 0;
  368.  
  369. // Delete the business-file
  370. format(file, sizeof(file), BusinessFile, BusID); // Construct the complete filename for this business-file
  371. if (fexist(file)) // Make sure the file exists
  372. fremove(file); // Delete the file
  373.  
  374. // Also let the player know he deleted the business
  375. format(Msg, 128, "{00FF00}You have deleted the business with ID: {FFFF00}%i", BusID);
  376. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  377.  
  378. // Exit the function
  379. return 1;
  380. }
  381. }
  382. else
  383. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot delete an owned business");
  384. }
  385. }
  386.  
  387. // There was no house in range, so let the player know about it
  388. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}No business in range to delete");
  389. }
  390. else
  391. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You must be on foot to delete a business");
  392.  
  393. // Let the server know that this was a valid command
  394. return 1;
  395. }
  396.  
  397. // This command lets the player buy a business when he's standing in range of a business that isn't owned yet
  398. COMMAND:buybus(playerid, params[])
  399. {
  400. // If a player hasn't logged in properly, he cannot use this command
  401. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  402.  
  403. // Setup local variables
  404. new Msg[128], BusType;
  405.  
  406. // Make sure the player isn't inside a vehicle
  407. if (GetPlayerVehicleSeat(playerid) == -1)
  408. {
  409. // Check if the player is near a business-pickup
  410. for (new BusID = 1; BusID < sizeof(ABusinessData); BusID++)
  411. {
  412. // Check if this business is created (it would have a valid pickup in front of the door)
  413. if (IsValidDynamicPickup(ABusinessData[BusID][PickupID]))
  414. {
  415. // Check if the player is in range of the business-pickup
  416. if (IsPlayerInRangeOfPoint(playerid, 2.5, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]))
  417. {
  418. // Check if the business isn't owned yet
  419. if (ABusinessData[BusID][Owned] == false)
  420. {
  421. // Get the type of business
  422. BusType = ABusinessData[BusID][BusinessType];
  423. // Check if the player can afford this type of business business
  424. if (INT_GetPlayerMoney(playerid) >= ABusinessInteriors[BusType][BusPrice])
  425. Business_SetOwner(playerid, BusID); // Give ownership of the business to the player
  426. else
  427. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot afford this business"); // The player cannot afford this business
  428. }
  429. else
  430. {
  431. // Let the player know that this business is already owned by a player
  432. format(Msg, 128, "{FF0000}This business is already owned by {FFFF00}%s", ABusinessData[BusID][Owner]);
  433. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  434. }
  435.  
  436. // The player was in range of a business-pickup, so stop searching for the other business pickups
  437. return 1;
  438. }
  439. }
  440. }
  441.  
  442. // All businesses have been processed, but the player wasn't in range of any business-pickup, let him know about it
  443. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}To buy a business, you have to be near a business-pickup");
  444. }
  445. else
  446. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You can't buy a business when you're inside a vehicle");
  447.  
  448. // Let the server know that this was a valid command
  449. return 1;
  450. }
  451.  
  452. // This command lets the player enter the house/business if he's the owner
  453. COMMAND:enterbus(playerid, params[])
  454. {
  455. // If a player hasn't logged in properly, he cannot use this command
  456. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  457.  
  458. // Setup local variables
  459. new BusID, BusType;
  460.  
  461. // Make sure the player isn't inside a vehicle
  462. if (GetPlayerVehicleSeat(playerid) == -1)
  463. {
  464. // Loop through all player-owned businesses
  465. for (new BusSlot; BusSlot < MAX_BUSINESSPERPLAYER; BusSlot++)
  466. {
  467. // Get the business-id at the selected slot from the player
  468. BusID = APlayerData[playerid][Business][BusSlot];
  469.  
  470. // Check if the player has a business in this slot
  471. if (BusID != 0)
  472. {
  473. // Check if the player is in range of the business-pickup
  474. if (IsPlayerInRangeOfPoint(playerid, 2.5, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]))
  475. {
  476. // Get the business-type
  477. BusType = ABusinessData[BusID][BusinessType];
  478.  
  479. // Set the worldid so other players cannot see him anymore
  480. SetPlayerVirtualWorld(playerid, 2000 + BusID);
  481. // Set the player inside the interior of the business
  482. SetPlayerInterior(playerid, ABusinessInteriors[BusType][InteriorID]);
  483. // Set the position of the player at the spawn-location of the business's interior
  484. SetPlayerPos(playerid, ABusinessInteriors[BusType][IntX], ABusinessInteriors[BusType][IntY], ABusinessInteriors[BusType][IntZ]);
  485.  
  486. // Also set a tracking-variable to enable /busmenu to track in which business the player is
  487. APlayerData[playerid][CurrentBusiness] = BusID;
  488. // Also let the player know he can use /busmenu to control his business
  489. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Use {FFFF00}/busmenu{00FF00} to change options for your business");
  490.  
  491. // Exit the function
  492. return 1;
  493. }
  494. }
  495. }
  496. }
  497.  
  498. // If no business was in range, allow other scripts to use the same command (like the housing-script)
  499. return 0;
  500. }
  501.  
  502. // This command opens a menu when you're inside your business to allow to access the options of your business
  503. COMMAND:busmenu(playerid, params[])
  504. {
  505. // If a player hasn't logged in properly, he cannot use this command
  506. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  507.  
  508. // Setup local variables
  509. new OptionsList[200], DialogTitle[200];
  510.  
  511. // Check if the player is inside a business
  512. if (APlayerData[playerid][CurrentBusiness] != 0)
  513. {
  514. // Create the dialog title
  515. format(DialogTitle, sizeof(DialogTitle), "Select option for %s", ABusinessData[APlayerData[playerid][CurrentBusiness]][BusinessName]);
  516. // Create the options in the dialog
  517. format(OptionsList, sizeof(OptionsList), "%sChange business-name\n", OptionsList);
  518. format(OptionsList, sizeof(OptionsList), "%sUpgrade business\n", OptionsList);
  519. format(OptionsList, sizeof(OptionsList), "%sRetrieve business earnings\n", OptionsList);
  520. format(OptionsList, sizeof(OptionsList), "%sSell business\n", OptionsList);
  521. format(OptionsList, sizeof(OptionsList), "%sExit business\n", OptionsList);
  522. // Show the businessmenu
  523. ShowPlayerDialog(playerid, DialogBusinessMenu, DIALOG_STYLE_LIST, DialogTitle, OptionsList, "Select", "Cancel");
  524. }
  525. else
  526. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You're not inside a business");
  527.  
  528. // Let the server know that this was a valid command
  529. return 1;
  530. }
  531.  
  532. // This command teleports you to your selected business
  533. COMMAND:gobus(playerid, params[])
  534. {
  535. // If a player hasn't logged in properly, he cannot use this command
  536. if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
  537.  
  538. // Setup local variables
  539. new BusinessList[1000], BusID, BusType, Earnings;
  540.  
  541. // Check if the player is not jailed
  542. if (INT_IsPlayerJailed(playerid) == 0)
  543. {
  544. // Check if the player has a wanted level of less than 3
  545. if (GetPlayerWantedLevel(playerid) < 3)
  546. {
  547. // Check if the player is not inside a vehicle
  548. if (GetPlayerVehicleSeat(playerid) == -1)
  549. {
  550. // Ask to which business the player wants to port
  551. for (new BusSlot; BusSlot < MAX_BUSINESSPERPLAYER; BusSlot++)
  552. {
  553. // Get the business-id
  554. BusID = APlayerData[playerid][Business][BusSlot];
  555.  
  556. // Check if this businessindex is occupied
  557. if (BusID != 0)
  558. {
  559. // Get the business-type
  560. BusType = ABusinessData[BusID][BusinessType];
  561. Earnings = (BusinessTransactionTime - ABusinessData[BusID][LastTransaction]) * ABusinessInteriors[BusType][BusEarnings] * ABusinessData[BusID][BusinessLevel];
  562. format(BusinessList, 1000, "%s{00FF00}%s{FFFFFF} (earnings: $%i)\n", BusinessList, ABusinessData[BusID][BusinessName], Earnings);
  563. }
  564. else
  565. format(BusinessList, 1000, "%s{FFFFFF}%s{FFFFFF}\n", BusinessList, "Empty business-slot");
  566. }
  567. ShowPlayerDialog(playerid, DialogGoBusiness, DIALOG_STYLE_LIST, "Choose the business to go to:", BusinessList, "Select", "Cancel");
  568. }
  569. else
  570. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need to be on-foot to port to your business");
  571. }
  572. else
  573. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use /gobus when you're wanted");
  574. }
  575. else
  576. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use /gobus when you're in jail");
  577.  
  578. // Let the server know that this was a valid command
  579. return 1;
  580. }
  581.  
  582.  
  583.  
  584. // ******************************************************************************************************************************
  585. // Dialog-responses
  586. // ******************************************************************************************************************************
  587.  
  588. // This dialog processes the chosen business-type and creates the business
  589. Dialog_CreateBusSelType(playerid, response, listitem)
  590. {
  591. // Just close the dialog if the player clicked "Cancel"
  592. if(!response) return 1;
  593.  
  594. // Setup some local variables
  595. new BusType, BusID, Float:x, Float:y, Float:z, Msg[128], bool:EmptySlotFound = false;
  596.  
  597. // Get the player's position
  598. GetPlayerPos(playerid, x, y, z);
  599.  
  600. // Get the business-type from the option the player chose
  601. BusType = listitem + 1;
  602.  
  603. // Find a free business-id
  604. for (BusID = 1; BusID < MAX_BUSINESS; BusID++)
  605. {
  606. // Check if this business ID is free
  607. if (ABusinessData[BusID][BusinessType] == 0)
  608. {
  609. EmptySlotFound = true;
  610. break; // Stop processing
  611. }
  612. }
  613.  
  614. // Check if an empty slot has been found
  615. if (EmptySlotFound == false)
  616. {
  617. // If no empty slot was found, let the player know about it and exit the function
  618. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Maximum number of businesses reached");
  619. return 1;
  620. }
  621.  
  622. // Set some default data at the index of NextFreeBusinessID (NextFreeBusinessID will point to the next free business-index)
  623. ABusinessData[BusID][BusinessX] = x;
  624. ABusinessData[BusID][BusinessY] = y;
  625. ABusinessData[BusID][BusinessZ] = z;
  626. ABusinessData[BusID][BusinessType] = BusType;
  627. ABusinessData[BusID][BusinessLevel] = 1;
  628. ABusinessData[BusID][Owned] = false;
  629.  
  630. // Add the pickup and 3DText at the location of the business-entrance (where the player is standing when he creates the business)
  631. Business_CreateEntrance(BusID);
  632.  
  633. // Save the business
  634. BusinessFile_Save(BusID);
  635.  
  636. // Inform the player that he created a new house
  637. format(Msg, 128, "{00FF00}You've succesfully created business {FFFF00}%i{00FF00}", BusID);
  638. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  639.  
  640. return 1;
  641. }
  642.  
  643. // This function processes the businessmenu dialog
  644. Dialog_BusinessMenu(playerid, response, listitem)
  645. {
  646. // Just close the dialog if the player clicked "Cancel"
  647. if(!response) return 1;
  648.  
  649. // Setup local variables
  650. new BusID, BusType, Msg[128], DialogTitle[200], UpgradePrice;
  651.  
  652. // Get the HouseID of the house where the player is
  653. BusID = APlayerData[playerid][CurrentBusiness];
  654. BusType = ABusinessData[BusID][BusinessType];
  655.  
  656. // Select an option based on the selection in the list
  657. switch(listitem)
  658. {
  659. case 0: // Change business name
  660. {
  661. format(DialogTitle, 200, "Old business-name: %s", ABusinessData[BusID][BusinessName]);
  662. ShowPlayerDialog(playerid, DialogBusinessNameChange, DIALOG_STYLE_INPUT, DialogTitle, "Enter a new name for your business", "OK", "Cancel");
  663. }
  664. case 1: // Upgrade the business
  665. {
  666. // Check if it's possible to upgrade further
  667. if (ABusinessData[BusID][BusinessLevel] < 5)
  668. {
  669. // Get the upgrade-price
  670. UpgradePrice = ABusinessInteriors[BusType][BusPrice];
  671. // Check if the player can afford the upgrade
  672. if (INT_GetPlayerMoney(playerid) >= UpgradePrice)
  673. {
  674. // Give the current earnings of the business to the player and update the LastTransaction time
  675. Business_PayEarnings(playerid, BusID);
  676. // Upgrade the business 1 level
  677. ABusinessData[BusID][BusinessLevel]++;
  678. // Let the player pay for the upgrade
  679. INT_GivePlayerMoney(playerid, -UpgradePrice);
  680. // Update the 3DText near the business's entrance to show what level the business is
  681. Business_UpdateEntrance(BusID);
  682. // Let the player know about it
  683. format(Msg, 128, "{00FF00}You have upgraded your business to level {FFFF00}%i", ABusinessData[BusID][BusinessLevel]);
  684. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  685. }
  686. else
  687. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot afford the upgrade");
  688. }
  689. else
  690. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Your business has reached the maximum level, you cannot upgrade it further");
  691. }
  692. case 2: // Retrieve business earnings
  693. {
  694. // Give the current earnings of the business to the player and update the LastTransaction time
  695. Business_PayEarnings(playerid, BusID);
  696. }
  697. case 3: // Sell business
  698. {
  699. format(Msg, 128, "Are you sure you want to sell your business for $%i?", (ABusinessInteriors[BusType][BusPrice] * ABusinessData[BusID][BusinessLevel]) / 2);
  700. ShowPlayerDialog(playerid, DialogSellBusiness, DIALOG_STYLE_MSGBOX, "Are you sure?", Msg, "Yes", "No");
  701. }
  702. case 4: // Exit the business
  703. {
  704. Business_Exit(playerid, BusID);
  705. }
  706. }
  707.  
  708. return 1;
  709. }
  710.  
  711. // Let the player change the name of his business
  712. Dialog_ChangeBusinessName(playerid, response, inputtext[])
  713. {
  714. // Just close the dialog if the player clicked "Cancel" or if the player didn't input any text
  715. if ((!response) || (strlen(inputtext) == 0)) return 1;
  716.  
  717. // Change the name of the business
  718. format(ABusinessData[APlayerData[playerid][CurrentBusiness]][BusinessName], 100, inputtext);
  719. // Also update the 3DText at the entrance of the business
  720. Business_UpdateEntrance(APlayerData[playerid][CurrentBusiness]);
  721. // Let the player know that the name of his business has been changed
  722. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've changed the name of your business");
  723.  
  724. // Save the business-file
  725. BusinessFile_Save(APlayerData[playerid][CurrentBusiness]);
  726.  
  727. return 1;
  728. }
  729.  
  730. // Sell the business
  731. Dialog_SellBusiness(playerid, response)
  732. {
  733. // Just close the dialog if the player clicked "Cancel"
  734. if(!response) return 1;
  735.  
  736. // Get the BusinessID where the player is right now and the business-type
  737. new BusID = APlayerData[playerid][CurrentBusiness];
  738. new BusType = ABusinessData[BusID][BusinessType];
  739.  
  740. // Set the player in the normal world again
  741. SetPlayerVirtualWorld(playerid, 0);
  742. SetPlayerInterior(playerid, 0);
  743. // Set the position of the player at the entrance of his business
  744. SetPlayerPos(playerid, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]);
  745.  
  746. // Also clear the tracking-variable to track in which business the player is
  747. APlayerData[playerid][CurrentBusiness] = 0;
  748.  
  749. // Clear the owner of the business
  750. ABusinessData[BusID][Owned] = false;
  751. ABusinessData[BusID][Owner] = 0;
  752. // Clear the business-name and business-level
  753. ABusinessData[BusID][BusinessName] = 0;
  754. ABusinessData[BusID][BusinessLevel] = 1;
  755.  
  756. // Refund the player 50% of the worth of the business
  757. INT_GivePlayerMoney(playerid, (ABusinessInteriors[BusType][BusPrice] * ABusinessData[BusID][BusinessLevel]) / 2);
  758. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've sold your business");
  759.  
  760. // Clear the business-id from the player
  761. for (new BusSlot; BusSlot < MAX_BUSINESSPERPLAYER; BusSlot++)
  762. {
  763. // If the business-slot if found where the business was added to the player
  764. if (APlayerData[playerid][Business][BusSlot] == BusID)
  765. {
  766. // Clear the business-id
  767. APlayerData[playerid][Business][BusSlot] = 0;
  768. // Stop searching
  769. break;
  770. }
  771. }
  772.  
  773. // Update the 3DText near the business's entrance to show other players that it's for sale again
  774. Business_UpdateEntrance(BusID);
  775.  
  776. // Also save the sold business, otherwise the old ownership-data is still there
  777. BusinessFile_Save(BusID);
  778.  
  779. return 1;
  780. }
  781.  
  782. // This function processes the /gobus dialog
  783. Dialog_GoBusiness(playerid, response, listitem)
  784. {
  785. // Just close the dialog if the player clicked "Cancel"
  786. if(!response) return 1;
  787.  
  788. // Setup local variables
  789. new BusIndex, BusID;
  790.  
  791. // The listitem directly indicates the business-index
  792. BusIndex = listitem;
  793. BusID = APlayerData[playerid][Business][BusIndex];
  794.  
  795. // Check if this is a valid business (BusID != 0)
  796. if (BusID != 0)
  797. {
  798. // Get the coordinates of the business's entrance
  799. SetPlayerPos(playerid, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]);
  800. }
  801. else
  802. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You don't have a business in this business-slot");
  803.  
  804. return 1;
  805. }
  806.  
  807.  
  808.  
  809. // ******************************************************************************************************************************
  810. // File functions
  811. // ******************************************************************************************************************************
  812.  
  813. // This function loads the file that holds the current business-time
  814. BusinessTime_Load()
  815. {
  816. // Setup local variables
  817. new File:BFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  818.  
  819. // Try to load the businesstime file
  820. if (fexist(BusinessTimeFile))
  821. {
  822. BFile = fopen(BusinessTimeFile, io_read); // Open the businesstime-file for reading
  823.  
  824. fread(BFile, LineFromFile); // Read the first line of the file
  825.  
  826. // Keep reading until the end of the file is found (no more data)
  827. while (strlen(LineFromFile) > 0)
  828. {
  829. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  830. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  831.  
  832. // Store the proper value in the proper place
  833. if (strcmp(ParameterName, "BusinessTime", false) == 0) // If the parametername is correct ("BusinessTime")
  834. BusinessTransactionTime = strval(ParameterValue); // Store the BusinessTime
  835.  
  836. // Read the next line of the file
  837. fread(BFile, LineFromFile);
  838. }
  839.  
  840. // Close the file
  841. fclose(BFile);
  842.  
  843. // Return if the file was read correctly
  844. return 1;
  845. }
  846. else
  847. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  848. }
  849.  
  850. // This function saves the file that holds the current business-time
  851. BusinessTime_Save()
  852. {
  853. // Setup local variables
  854. new File:BFile, LineForFile[100];
  855.  
  856. BFile = fopen(BusinessTimeFile, io_write); // Open the businesstime-file for writing
  857.  
  858. format(LineForFile, 100, "BusinessTime %i\r\n", BusinessTransactionTime); // Construct the line: "BusinessTime <BusinessTransactionTime>"
  859. fwrite(BFile, LineForFile); // And save it to the file
  860.  
  861. fclose(BFile); // Close the file
  862.  
  863. return 1;
  864. }
  865.  
  866. // This function will load the business's datafile (used when the server is started to load all businesses)
  867. BusinessFile_Load(BusID)
  868. {
  869. // Setup local variables
  870. new file[100], File:BFile, LineFromFile[100], ParameterName[50], ParameterValue[50];
  871.  
  872. // Construct the complete filename for this business-file
  873. format(file, sizeof(file), BusinessFile, BusID);
  874.  
  875. // Check if the business-file exists
  876. if (fexist(file))
  877. {
  878. // Open the businessfile for reading
  879. BFile = fopen(file, io_read);
  880.  
  881. // Read the first line of the file
  882. fread(BFile, LineFromFile);
  883.  
  884. // Keep reading until the end of the file is found (no more data)
  885. while (strlen(LineFromFile) > 0)
  886. {
  887. StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
  888. sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
  889.  
  890. // Check if there is anything in the LineFromFile (skipping empty lines)
  891. if (strlen(LineFromFile) > 0)
  892. {
  893. // Store the proper value in the proper place
  894. if (strcmp(ParameterName, "BusinessName", false) == 0) // If the parametername is correct ("BusinessName")
  895. format(ABusinessData[BusID][BusinessName], 24, ParameterValue); // Store the BusinessName
  896. if (strcmp(ParameterName, "BusinessX", false) == 0) // If the parametername is correct ("BusinessX")
  897. ABusinessData[BusID][BusinessX] = floatstr(ParameterValue); // Store the BusinessX
  898. if (strcmp(ParameterName, "BusinessY", false) == 0) // If the parametername is correct ("BusinessY")
  899. ABusinessData[BusID][BusinessY] = floatstr(ParameterValue); // Store the BusinessY
  900. if (strcmp(ParameterName, "BusinessZ", false) == 0) // If the parametername is correct ("BusinessZ")
  901. ABusinessData[BusID][BusinessZ] = floatstr(ParameterValue); // Store the BusinessZ
  902. if (strcmp(ParameterName, "BusinessType", false) == 0) // If the parametername is correct ("BusinessType")
  903. ABusinessData[BusID][BusinessType] = strval(ParameterValue); // Store the BusinessType
  904. if (strcmp(ParameterName, "BusinessLevel", false) == 0) // If the parametername is correct ("BusinessLevel")
  905. ABusinessData[BusID][BusinessLevel] = strval(ParameterValue); // Store the BusinessLevel
  906. if (strcmp(ParameterName, "LastTransaction", false) == 0) // If the parametername is correct ("LastTransaction")
  907. ABusinessData[BusID][LastTransaction] = strval(ParameterValue); // Store the LastTransaction
  908. if (strcmp(ParameterName, "Owned", false) == 0) // If the parametername is correct ("Owned")
  909. {
  910. if (strcmp(ParameterValue, "Yes", false) == 0) // If the value "Yes" was read
  911. ABusinessData[BusID][Owned] = true; // House is owned
  912. else
  913. ABusinessData[BusID][Owned] = false; // House is not owned
  914. }
  915. if (strcmp(ParameterName, "Owner", false) == 0) // If the parametername is correct ("Owner")
  916. format(ABusinessData[BusID][Owner], 24, ParameterValue);
  917. }
  918.  
  919. // Read the next line of the file
  920. fread(BFile, LineFromFile);
  921. }
  922.  
  923. // Close the file
  924. fclose(BFile);
  925.  
  926. // Create the business-entrance and set data
  927. Business_CreateEntrance(BusID);
  928. // Increase the amount of businesses loaded
  929. TotalBusiness++;
  930.  
  931. // Return if the file was read correctly
  932. return 1;
  933. }
  934. else
  935. return 0; // Return 0 if the file couldn't be read (doesn't exist)
  936. }
  937.  
  938. // This function will save the given business
  939. BusinessFile_Save(BusID)
  940. {
  941. // Setup local variables
  942. new file[100], File:BFile, LineForFile[100];
  943.  
  944. // Construct the complete filename for this business
  945. format(file, sizeof(file), BusinessFile, BusID);
  946.  
  947. // Open the business-file for writing
  948. BFile = fopen(file, io_write);
  949.  
  950. format(LineForFile, 100, "BusinessName %s\r\n", ABusinessData[BusID][BusinessName]); // Construct the line: "BusinessName <BusinessName>"
  951. fwrite(BFile, LineForFile); // And save it to the file
  952. format(LineForFile, 100, "BusinessX %f\r\n", ABusinessData[BusID][BusinessX]); // Construct the line: "BusinessX <BusinessX>"
  953. fwrite(BFile, LineForFile); // And save it to the file
  954. format(LineForFile, 100, "BusinessY %f\r\n", ABusinessData[BusID][BusinessY]); // Construct the line: "BusinessY <BusinessY>"
  955. fwrite(BFile, LineForFile); // And save it to the file
  956. format(LineForFile, 100, "BusinessZ %f\r\n", ABusinessData[BusID][BusinessZ]); // Construct the line: "BusinessZ <BusinessZ>"
  957. fwrite(BFile, LineForFile); // And save it to the file
  958. format(LineForFile, 100, "BusinessType %i\r\n", ABusinessData[BusID][BusinessType]); // Construct the line: "BusinessType <BusinessType>"
  959. fwrite(BFile, LineForFile); // And save it to the file
  960. format(LineForFile, 100, "BusinessLevel %i\r\n", ABusinessData[BusID][BusinessLevel]); // Construct the line: "BusinessLevel <BusinessLevel>"
  961. fwrite(BFile, LineForFile); // And save it to the file
  962. format(LineForFile, 100, "LastTransaction %i\r\n", ABusinessData[BusID][LastTransaction]); // Construct the line: "LastTransaction <LastTransaction>"
  963. fwrite(BFile, LineForFile); // And save it to the file
  964.  
  965. if (ABusinessData[BusID][Owned] == true) // Check if the business is owned
  966. {
  967. format(LineForFile, 100, "Owned Yes\r\n"); // Construct the line: "Owned Yes"
  968. fwrite(BFile, LineForFile); // And save it to the file
  969. }
  970. else
  971. {
  972. format(LineForFile, 100, "Owned No\r\n"); // Construct the line: "Owned No"
  973. fwrite(BFile, LineForFile); // And save it to the file
  974. }
  975.  
  976. format(LineForFile, 100, "Owner %s\r\n", ABusinessData[BusID][Owner]); // Construct the line: "Owner <Owner>"
  977. fwrite(BFile, LineForFile); // And save it to the file
  978.  
  979. fclose(BFile); // Close the file
  980.  
  981. return 1;
  982. }
  983.  
  984.  
  985.  
  986. // ******************************************************************************************************************************
  987. // Business functions
  988. // ******************************************************************************************************************************
  989.  
  990. // This timer increases the variable "BusinessTransactionTime" every minute and saves the businesstime file
  991. forward Business_TransactionTimer();
  992. public Business_TransactionTimer()
  993. {
  994. // Increase the variable by one
  995. BusinessTransactionTime++;
  996.  
  997. // And save it to the file
  998. BusinessTime_Save();
  999. }
  1000.  
  1001. // This function returns the first free business-slot for the given player
  1002. Player_GetFreeBusinessSlot(playerid)
  1003. {
  1004. // Check if the player has room for another business (he hasn't bought the maximum amount of businesses per player yet)
  1005. // and get the slot-id
  1006. for (new BusIndex; BusIndex < MAX_BUSINESSPERPLAYER; BusIndex++) // Loop through all business-slots of the player
  1007. if (APlayerData[playerid][Business][BusIndex] == 0) // Check if this business slot is free
  1008. return BusIndex; // Return the free BusIndex for this player
  1009.  
  1010. // If there were no free business-slots, return "-1"
  1011. return -1;
  1012. }
  1013.  
  1014. // This function sets ownership of the business to the given player
  1015. Business_SetOwner(playerid, BusID)
  1016. {
  1017. // Setup local variables
  1018. new BusSlotFree, Name[24], Msg[128], BusType;
  1019.  
  1020. // Get the first free business-slot from this player
  1021. BusSlotFree = Player_GetFreeBusinessSlot(playerid);
  1022.  
  1023. // Check if the player has a free business-slot
  1024. if (BusSlotFree != -1)
  1025. {
  1026. // Get the player's name
  1027. GetPlayerName(playerid, Name, sizeof(Name));
  1028.  
  1029. // Store the business-id for the player
  1030. APlayerData[playerid][Business][BusSlotFree] = BusID;
  1031. // Get the business-type
  1032. BusType = ABusinessData[BusID][BusinessType];
  1033.  
  1034. // Let the player pay for the business
  1035. INT_GivePlayerMoney(playerid, -ABusinessInteriors[BusType][BusPrice]);
  1036.  
  1037. // Set the business as owned
  1038. ABusinessData[BusID][Owned] = true;
  1039. // Store the owner-name for the business
  1040. format(ABusinessData[BusID][Owner], 24, Name);
  1041. // Set the level to 1
  1042. ABusinessData[BusID][BusinessLevel] = 1;
  1043. // Set the default business-name
  1044. format(ABusinessData[BusID][BusinessName], 100, ABusinessInteriors[BusType][InteriorName]);
  1045. // Store the current transaction-time (this is used so the player can only retrieve cash from the business from the moment he bought it)
  1046. ABusinessData[BusID][LastTransaction] = BusinessTransactionTime;
  1047.  
  1048. // Also, update 3DText of this business
  1049. Business_UpdateEntrance(BusID);
  1050.  
  1051. // Save the business-file
  1052. BusinessFile_Save(BusID);
  1053.  
  1054. // Let the player know he bought the business
  1055. format(Msg, 128, "{00FF00}You've bought the business for {FFFF00}$%i", ABusinessInteriors[BusType][BusPrice]);
  1056. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  1057. }
  1058. else
  1059. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You already own the maximum amount of allowed businesses per player");
  1060.  
  1061. return 1;
  1062. }
  1063.  
  1064. // This function adds a pickup for the given business
  1065. Business_CreateEntrance(BusID)
  1066. {
  1067. // Setup local variables
  1068. new Msg[128], Float:x, Float:y, Float:z, BusType, Icon;
  1069.  
  1070. // Get the coordinates of the house's pickup (usually near the door)
  1071. x = ABusinessData[BusID][BusinessX];
  1072. y = ABusinessData[BusID][BusinessY];
  1073. z = ABusinessData[BusID][BusinessZ];
  1074. // Get the business-type and icon
  1075. BusType = ABusinessData[BusID][BusinessType];
  1076. Icon = ABusinessInteriors[BusType][IconID];
  1077.  
  1078. // Add a dollar-sign to indicate this business
  1079. ABusinessData[BusID][PickupID] = CreateDynamicPickup(1274, 1, x, y, z, 0);
  1080. // Add a map-icon depending on which type the business is
  1081. ABusinessData[BusID][MapIconID] = CreateDynamicMapIcon(x, y, z, Icon, 0, 0, 0, -1, 150.0);
  1082.  
  1083. // Add a new 3DText at the business's location (usually near the door)
  1084. if (ABusinessData[BusID][Owned] == true)
  1085. {
  1086. // Create the 3DText that appears above the business-pickup (displays the businessname, the name of the owner and the current level)
  1087. format(Msg, 128, "%s\nOwned by: %s\nBusiness-level: %i\n/enter", ABusinessData[BusID][BusinessName], ABusinessData[BusID][Owner], ABusinessData[BusID][BusinessLevel]);
  1088. ABusinessData[BusID][DoorText] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
  1089. }
  1090. else
  1091. {
  1092. // Create the 3DText that appears above the business-pickup (displays the price of the business and the earnings)
  1093. format(Msg, 128, "%s\nAvailable for\n$%i\nEarnings: $%i\n/buybus", ABusinessInteriors[BusType][InteriorName], ABusinessInteriors[BusType][BusPrice], ABusinessInteriors[BusType][BusEarnings]);
  1094. ABusinessData[BusID][DoorText] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
  1095. }
  1096. }
  1097.  
  1098. // This function changes the 3DText for the given business (used when buying or selling a business)
  1099. Business_UpdateEntrance(BusID)
  1100. {
  1101. // Setup local variables
  1102. new Msg[128], BusType;
  1103.  
  1104. // Get the business-type
  1105. BusType = ABusinessData[BusID][BusinessType];
  1106.  
  1107. // Update the 3DText at the business's location (usually near the door)
  1108. if (ABusinessData[BusID][Owned] == true)
  1109. {
  1110. // Create the 3DText that appears above the business-pickup (displays the businessname, the name of the owner and the current level)
  1111. format(Msg, 128, "%s\nOwned by: %s\nBusiness-level: %i\n/enter", ABusinessData[BusID][BusinessName], ABusinessData[BusID][Owner], ABusinessData[BusID][BusinessLevel]);
  1112. UpdateDynamic3DTextLabelText(ABusinessData[BusID][DoorText], 0x008080FF, Msg);
  1113. }
  1114. else
  1115. {
  1116. // Create the 3DText that appears above the business-pickup (displays the price of the business and the earnings)
  1117. format(Msg, 128, "%s\nAvailable for\n$%i\nEarnings: $%i\n/buybus", ABusinessInteriors[BusType][InteriorName], ABusinessInteriors[BusType][BusPrice], ABusinessInteriors[BusType][BusEarnings]);
  1118. UpdateDynamic3DTextLabelText(ABusinessData[BusID][DoorText], 0x008080FF, Msg);
  1119. }
  1120. }
  1121.  
  1122. // This function pays the current earnings of the given business to the player
  1123. Business_PayEarnings(playerid, BusID)
  1124. {
  1125. // Setup local variables
  1126. new Msg[128];
  1127.  
  1128. // Get the business-type
  1129. new BusType = ABusinessData[BusID][BusinessType];
  1130.  
  1131. // Calculate the earnings of the business since the last transaction
  1132. // This is calculated by the number of minutes between the current business-time and last business-time, multiplied by the earnings-per-minute and business-level
  1133. new Earnings = (BusinessTransactionTime - ABusinessData[BusID][LastTransaction]) * ABusinessInteriors[BusType][BusEarnings] * ABusinessData[BusID][BusinessLevel];
  1134. // Reset the last transaction time to the current time
  1135. ABusinessData[BusID][LastTransaction] = BusinessTransactionTime;
  1136. // Reward the player with his earnings
  1137. INT_GivePlayerMoney(playerid, Earnings);
  1138. // Inform the player that he has earned money from his business
  1139. format(Msg, 128, "{00FF00}Your business has earned {FFFF00}$%i{00FF00} since your last withdrawl", Earnings);
  1140. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  1141. }
  1142.  
  1143. // This function is used to spawn back at the entrance of your business
  1144. Business_Exit(playerid, BusID)
  1145. {
  1146. // Set the player in the normal world again
  1147. SetPlayerVirtualWorld(playerid, 0);
  1148. SetPlayerInterior(playerid, 0);
  1149. // Set the position of the player at the entrance of his business
  1150. SetPlayerPos(playerid, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]);
  1151. // Also clear the tracking-variable to track in which business the player is
  1152. APlayerData[playerid][CurrentBusiness] = 0;
  1153.  
  1154. // Check if there is a timer-value set for exiting the business (this timer freezes the player while the environment is being loaded)
  1155. if (ExitBusinessTimer > 0)
  1156. {
  1157. // Don't allow the player to fall
  1158. TogglePlayerControllable(playerid, 0);
  1159. // Let the player know he's frozen while the environment loads
  1160. GameTextForPlayer(playerid, "Waiting for the environment to load", ExitBusinessTimer, 4);
  1161. // Start a timer that will allow the player to fall again when the environment has loaded
  1162. SetTimerEx("Business_ExitTimer", ExitBusinessTimer, false, "ii", playerid, BusID);
  1163. }
  1164.  
  1165. return 1;
  1166. }
  1167.  
  1168. forward Business_ExitTimer(playerid, BusID);
  1169. public Business_ExitTimer(playerid, BusID)
  1170. {
  1171. // Allow the player to move again (environment should have been loaded now)
  1172. TogglePlayerControllable(playerid, 1);
  1173.  
  1174. return 1;
  1175. }
  1176.  
  1177.  
  1178.  
  1179. // ******************************************************************************************************************************
  1180. // Support functions
  1181. // ******************************************************************************************************************************
  1182.  
  1183. // This function is copied from the include-file "dutils.inc"
  1184. stock StripNewLine(string[])
  1185. {
  1186. new len = strlen(string); // Get the length of the given string
  1187.  
  1188. if (string[0] == 0) return ; // If the given string is empty, exit the function
  1189. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) // If the string ends with \n or \r
  1190. {
  1191. string[len - 1] = 0; // Replace the \n or \r with a 0 character
  1192. if (string[0]==0) return ; // If the string became empty, exit the function
  1193. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) // Check again if the string ends with \n or \r
  1194. string[len - 2] = 0; // Replace the \n or \r again with a 0 character
  1195. }
  1196. }
  1197.  
  1198.  
  1199.  
  1200. // ******************************************************************************************************************************
  1201. // Special functions that try to access external public functions to retreive or set data from another script
  1202. // ******************************************************************************************************************************
  1203.  
  1204. // This function is used to get the player's money
  1205. INT_GetPlayerMoney(playerid)
  1206. {
  1207. // Setup local variables
  1208. new Money;
  1209.  
  1210. // Try to call the external function to get the player's money (used to get the serversided money for this player)
  1211. Money = CallRemoteFunction("Admin_GetPlayerMoney", "i", playerid);
  1212.  
  1213. // The external function returned "0" (as the player doesn't have any money yet), or the function is not used in another script
  1214. if (Money == 0)
  1215. return GetPlayerMoney(playerid); // Return the normal money of the player
  1216. else
  1217. return Money; // Return the money that was returned by the external function
  1218. }
  1219.  
  1220. // This function is used to set the player's money
  1221. INT_GivePlayerMoney(playerid, Money)
  1222. {
  1223. // Setup local variables
  1224. new Success;
  1225.  
  1226. // Try to call the external function to get the player's money (used to get the serversided money for this player)
  1227. Success = CallRemoteFunction("Admin_GivePlayerMoney", "ii", playerid, Money);
  1228.  
  1229. // The external function returned "0" as the function is not used in another script
  1230. if (Success == 0)
  1231. GivePlayerMoney(playerid, Money); // Use the normal money (client-sided money)
  1232. }
  1233.  
  1234. // This function checks if the admin-level of a player is sufficient
  1235. INT_CheckPlayerAdminLevel(playerid, AdminLevel)
  1236. {
  1237. // Setup local variables
  1238. new Level;
  1239.  
  1240. // Check if the player is an RCON admin
  1241. if (IsPlayerAdmin(playerid))
  1242. return 1; // Return 1 to indicate this player has a sufficient admin-level to use a command
  1243.  
  1244. // If the player is not an RCON admin, try to get his admin-level from an external script using a remote function
  1245. Level = CallRemoteFunction("Admin_GetPlayerAdminLevel", "i", playerid);
  1246. // Check if the player has a sufficient admin-level
  1247. if (Level >= AdminLevel)
  1248. return 1; // Return 1 to indicate this player has a sufficient admin-level
  1249. else
  1250. return 0; // Return 0 to indicate this player has an insufficient admin-level
  1251. }
  1252.  
  1253. // This function checks if the player has logged in properly by entering his password
  1254. INT_IsPlayerLoggedIn(playerid)
  1255. {
  1256. // Setup local variables
  1257. new LoggedIn;
  1258.  
  1259. // Try to determine if the player logged in properly by entering his password in another script
  1260. LoggedIn = CallRemoteFunction("Admin_IsPlayerLoggedIn", "i", playerid);
  1261.  
  1262. // Check if the player has logged in properly
  1263. switch (LoggedIn)
  1264. {
  1265. case 0: return 1; // No admin script present that holds the LoggedIn status of a player, so allow a command to be used
  1266. case 1: return 1; // The player logged in properly by entering his password, allow commands to be used
  1267. case -1: return 0; // There is an admin script present, but the player hasn't entered his password yet, so block all commands
  1268. // This prevents executing the commands using F6 during login with an admin-account before entering a password
  1269. }
  1270.  
  1271. // In any other case, block all commands
  1272. return 0;
  1273. }
  1274.  
  1275. // This function tries to cetermine if the player is in jail
  1276. INT_IsPlayerJailed(playerid)
  1277. {
  1278. // Setup local variables
  1279. new Jailed;
  1280.  
  1281. // Try to determine if the player is jailed
  1282. Jailed = CallRemoteFunction("Admin_IsPlayerJailed", "i", playerid);
  1283.  
  1284. // Check if the player is jailed
  1285. switch (Jailed)
  1286. {
  1287. case 0: return 0; // No admin script present, so there is no jail either, player cannot be jailed in this case
  1288. case 1: return 1; // The player is jailed, so return "1"
  1289. case -1: return 0; // There is an admin script present, but the player isn't jailed
  1290. }
  1291.  
  1292. // In any other case, return "0" (player not jailed)
  1293. return 0;
  1294. }
  1295.  
  1296.  
  1297.  
  1298. // ******************************************************************************************************************************
  1299. // External functions to be used from within other filterscripts or gamemode (these aren't called anywhere inside this script)
  1300. // These functions can be called from other filterscripts or the gamemode to get data from the housing filterscript
  1301. // ******************************************************************************************************************************
  1302.  
  1303.  
  1304.  
  1305. // ******************************************************************************************************************************
  1306. // Functions that need to be placed in the gamemode or filterscript which holds the playerdata
  1307. // Only needed when the server uses server-sided money, otherwise the normal money is used
  1308. // ******************************************************************************************************************************
  1309.  
  1310. /*
  1311. // This function is used to get the player's money
  1312. forward Admin_GetPlayerMoney(playerid);
  1313. public Admin_GetPlayerMoney(playerid)
  1314. {
  1315. return APlayerData[playerid][PlayerMoney];
  1316. }
  1317.  
  1318. // This function is used to get the player's money
  1319. forward Admin_GivePlayerMoney(playerid, Money);
  1320. public Admin_GivePlayerMoney(playerid, Money)
  1321. {
  1322. // Add the given money to the player's account
  1323. APlayerData[playerid][PlayerMoney] = APlayerData[playerid][PlayerMoney] + Money;
  1324.  
  1325. // Return that the function had success
  1326. return 1;
  1327. }
  1328.  
  1329. // This function is used to get the player's admin-level
  1330. forward Admin_GetPlayerAdminLevel(playerid);
  1331. public Admin_GetPlayerAdminLevel(playerid)
  1332. {
  1333. return APlayerData[playerid][AdminLevel];
  1334. }
  1335.  
  1336. // This function is used to determine if the player has logged in (he succesfully entered his password)
  1337. forward Admin_IsPlayerLoggedIn(playerid);
  1338. public Admin_IsPlayerLoggedIn(playerid)
  1339. {
  1340. if (APlayerData[playerid][LoggedIn] == true)
  1341. return 1; // The player has logged in succesfully
  1342. else
  1343. return -1; // The player hasn't logged in (yet)
  1344. }
  1345.  
  1346. // This function is used to determine if a player is jailed
  1347. forward Admin_IsPlayerJailed(playerid);
  1348. public Admin_IsPlayerJailed(playerid)
  1349. {
  1350. // Check if a player has jaimtime left
  1351. if (APlayerData[playerid][PlayerJailed] == true)
  1352. return 1; // The player is still jailed
  1353. else
  1354. return -1; // The player is not jailed
  1355. }
  1356. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement