1
0

PPC_Business.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // This timer increases the variable "BusinessTransactionTime" every hour
  2. forward Business_TransactionTimer();
  3. public Business_TransactionTimer()
  4. {
  5. // Increase the variable by one
  6. BusinessTransactionTime++;
  7. // And save it to the file
  8. BusinessTime_Save();
  9. }
  10. // This function returns the first free business-slot for the given player
  11. Player_GetFreeBusinessSlot(playerid)
  12. {
  13. // Check if the player has room for another business (he hasn't bought the maximum amount of businesses per player yet)
  14. // and get the slot-id
  15. for (new BusIndex; BusIndex < MAX_BUSINESSPERPLAYER; BusIndex++) // Loop through all business-slots of the player
  16. if (APlayerData[playerid][Business][BusIndex] == 0) // Check if this business slot is free
  17. return BusIndex; // Return the free BusIndex for this player
  18. // If there were no free business-slots, return "-1"
  19. return -1;
  20. }
  21. // This function sets ownership to the given player
  22. Business_SetOwner(playerid, BusID)
  23. {
  24. // Setup local variables
  25. new BusSlotFree, Name[24], Msg[128], BusType;
  26. // Get the first free business-slot from this player
  27. BusSlotFree = Player_GetFreeBusinessSlot(playerid);
  28. // Check if the player has a free business-slot
  29. if (BusSlotFree != -1)
  30. {
  31. // Get the player's name
  32. GetPlayerName(playerid, Name, sizeof(Name));
  33. // Store the business-id for the player
  34. APlayerData[playerid][Business][BusSlotFree] = BusID;
  35. // Get the business-type
  36. BusType = ABusinessData[BusID][BusinessType];
  37. // Let the player pay for the business
  38. RewardPlayer(playerid, -ABusinessInteriors[BusType][BusPrice], 0);
  39. // Set the business as owned
  40. ABusinessData[BusID][Owned] = true;
  41. // Store the owner-name for the business
  42. format(ABusinessData[BusID][Owner], 24, Name);
  43. // Set the level to 1
  44. ABusinessData[BusID][BusinessLevel] = 1;
  45. // Set the default business-name
  46. format(ABusinessData[BusID][BusinessName], 100, ABusinessInteriors[BusType][InteriorName]);
  47. // Store the current transaction-time (this is used so the player can only retrieve cash from the business from the moment he bought it)
  48. ABusinessData[BusID][LastTransaction] = BusinessTransactionTime;
  49. // Also, update 3DText of this business
  50. Business_UpdateEntrance(BusID);
  51. // Save the player-file (and also his houses/businesses)
  52. PlayerFile_Save(playerid);
  53. // Let the player know he bought the business
  54. format(Msg, 128, TXT_PlayerBoughtBusiness, ABusinessInteriors[BusType][BusPrice]);
  55. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  56. }
  57. else
  58. SendClientMessage(playerid, 0xFFFFFFFF, TXT_PlayerOwnsMaxBusinesses);
  59. return 1;
  60. }
  61. // This function is used to spawn back at the entrance of your business
  62. Business_Exit(playerid, BusID)
  63. {
  64. // Set the player in the normal world again
  65. SetPlayerVirtualWorld(playerid, 0);
  66. SetPlayerInterior(playerid, 0);
  67. // Set the position of the player at the entrance of his business
  68. SetPlayerPos(playerid, ABusinessData[BusID][BusinessX], ABusinessData[BusID][BusinessY], ABusinessData[BusID][BusinessZ]);
  69. // Also clear the tracking-variable to track in which business the player is
  70. APlayerData[playerid][CurrentBusiness] = 0;
  71. // Check if there is a timer-value set for exiting the business (this timer freezes the player while the environment is being loaded)
  72. if (ExitBusinessTimer > 0)
  73. {
  74. // Don't allow the player to fall
  75. TogglePlayerControllable(playerid, 0);
  76. // Let the player know he's frozen for 5 seconds
  77. GameTextForPlayer(playerid, TXT_ExitHouseReloadEnv, ExitBusinessTimer, 4);
  78. // Start a timer that will allow the player to fall again when the environment has loaded
  79. SetTimerEx("Business_ExitTimer", ExitBusinessTimer, false, "ii", playerid, BusID);
  80. }
  81. return 1;
  82. }
  83. forward Business_ExitTimer(playerid, BusID);
  84. public Business_ExitTimer(playerid, BusID)
  85. {
  86. // Allow the player to move again (environment should have been loaded now)
  87. TogglePlayerControllable(playerid, 1);
  88. return 1;
  89. }
  90. // This function adds a pickup for the given business
  91. Business_CreateEntrance(BusID)
  92. {
  93. // Setup local variables
  94. new Msg[128], Float:x, Float:y, Float:z, BusType, Icon;
  95. // Get the coordinates of the house's pickup (usually near the door)
  96. x = ABusinessData[BusID][BusinessX];
  97. y = ABusinessData[BusID][BusinessY];
  98. z = ABusinessData[BusID][BusinessZ];
  99. // Get the business-type and icon
  100. BusType = ABusinessData[BusID][BusinessType];
  101. Icon = ABusinessInteriors[BusType][IconID];
  102. // Add a dollar-sign to indicate this business
  103. ABusinessData[BusID][PickupID] = CreateDynamicPickup(1274, 1, x, y, z, 0);
  104. // Add a map-icon depending on which type the business is
  105. ABusinessData[BusID][MapIconID] = CreateDynamicMapIcon(x, y, z, Icon, 0, 0, 0, -1, 150.0);
  106. // Add a new 3DText at the business's location (usually near the door)
  107. if (ABusinessData[BusID][Owned] == true)
  108. {
  109. // Create the 3DText that appears above the business-pickup (displays the businessname, the name of the owner and the current level)
  110. format(Msg, 128, TXT_PickupBusinessOwned, ABusinessData[BusID][BusinessName], ABusinessData[BusID][Owner], ABusinessData[BusID][BusinessLevel]);
  111. ABusinessData[BusID][DoorText] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
  112. }
  113. else
  114. {
  115. // Create the 3DText that appears above the business-pickup (displays the price of the business and the earnings)
  116. format(Msg, 128, TXT_PickupBusinessForSale, ABusinessInteriors[BusType][InteriorName], ABusinessInteriors[BusType][BusPrice], ABusinessInteriors[BusType][BusEarnings]);
  117. ABusinessData[BusID][DoorText] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
  118. }
  119. }
  120. // This function changes the 3DText for the given business (used when buying or selling a business)
  121. Business_UpdateEntrance(BusID)
  122. {
  123. // Setup local variables
  124. new Msg[128], BusType;
  125. // Get the business-type
  126. BusType = ABusinessData[BusID][BusinessType];
  127. // Update the 3DText at the business's location (usually near the door)
  128. if (ABusinessData[BusID][Owned] == true)
  129. {
  130. // Create the 3DText that appears above the business-pickup (displays the businessname, the name of the owner and the current level)
  131. format(Msg, 128, TXT_PickupBusinessOwned, ABusinessData[BusID][BusinessName], ABusinessData[BusID][Owner], ABusinessData[BusID][BusinessLevel]);
  132. UpdateDynamic3DTextLabelText(ABusinessData[BusID][DoorText], 0x008080FF, Msg);
  133. }
  134. else
  135. {
  136. // Create the 3DText that appears above the business-pickup (displays the price of the business and the earnings)
  137. format(Msg, 128, TXT_PickupBusinessForSale, ABusinessInteriors[BusType][InteriorName], ABusinessInteriors[BusType][BusPrice], ABusinessInteriors[BusType][BusEarnings]);
  138. UpdateDynamic3DTextLabelText(ABusinessData[BusID][DoorText], 0x008080FF, Msg);
  139. }
  140. }
  141. // This function pays the current earnings of the given business to the player
  142. Business_PayEarnings(playerid, BusID)
  143. {
  144. // Setup local variables
  145. new Msg[128];
  146. // Get the business-type
  147. new BusType = ABusinessData[BusID][BusinessType];
  148. // Calculate the earnings of the business since the last transaction
  149. // 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
  150. new Earnings = (BusinessTransactionTime - ABusinessData[BusID][LastTransaction]) * ABusinessInteriors[BusType][BusEarnings] * ABusinessData[BusID][BusinessLevel];
  151. // Reset the last transaction time to the current time
  152. ABusinessData[BusID][LastTransaction] = BusinessTransactionTime;
  153. // Reward the player with his earnings
  154. RewardPlayer(playerid, Earnings, 0);
  155. // Inform the player that he has earned money from his business
  156. format(Msg, 128, "{00FF00}Your business has earned {FFFF00}$%i{00FF00} since your last withdrawl", Earnings);
  157. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  158. }