Zeldaboy111

Upgrades ]|[ Skript #443

Aug 20th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.10 KB | None | 0 0
  1. options:
  2. prefix: &6Tycoon&8:&7
  3. shop: Shop
  4. upgrades: Upgrades
  5. prestigeUpgrades: Prestige Upgrades
  6. upgradesItem: gold nugget named "&eUpgrades"
  7. prestigeUpgradesItem: ghast tear named "&fPrestige Upgrades"
  8. upgradeItem_multiplierIPrice: 100
  9. upgradeItem_multiplierIIPrice: 200
  10. upgradeItem_multiplierIIIPrice: 400
  11. upgradeItem_multiplierI_locked: gold ingot named "&eMultiplier" with lore " &8Used to multiply", " &8your income.", "&6 ", " &7Multiplier&8: &e2.0x", " &7Price&8: &e100", and " &7Status&8: &eLocked"
  12. upgradeItem_multiplierI_unlocked: gold ingot named "&eMultiplier" with lore " &8Used to multiply", " &8your income.", "&6 ", " &7Multiplier&8: &e2.0x", " &7Price&8: &e100", and " &7Status&8: &eUnlocked"
  13. upgradeItem_multiplierII_locked: 2 gold ingot named "&eMultiplier" with lore " &8Used to multiply", " &8your income.", "&6 ", " &7Multiplier&8: &e2.5x", " &7Price&8: &e200", and " &7Status&8: &eLocked"
  14. upgradeItem_multiplierII_unlocked: 2 gold ingot named "&eMultiplier" with lore " &8Used to multiply", " &8your income.", "&6 ", " &7Multiplier&8: &e2.5x", " &7Price&8: &e200", and " &7Status&8: &eUnlocked"
  15. upgradeItem_multiplierIII_locked: 3 gold ingot named "&eMultiplier" with lore " &8Used to multiply", " &8your income.", "&6 ", " &7Multiplier&8: &e3.0x", " &7Price&8: &e400", and " &7Status&8: &eLocked"
  16. upgradeItem_multiplierIII_unlocked: 3 gold ingot named "&eMultiplier" with lore " &8Used to multiply", " &8your income.", "&6 ", " &7Multiplier&8: &e3.0x", " &7Price&8: &e400", and " &7Status&8: &eUnlocked"
  17.  
  18. function sendBalance():
  19. if {tc.loopingBalance} is true:
  20. stop
  21. set {tc.loopingBalance} to true
  22. while {tc.loopingBalance} is true:
  23. if {tc.stopped} is true:
  24. delete {tc.loopingBalance}
  25. else if size of online players is 0:
  26. delete {tc.loopingBalance}
  27. else:
  28. loop all players:
  29. add {tc.%uuid of loop-player%.income} to {tc.%uuid of loop-player%.balance}
  30. send actionbar "&6Coins&8: &e%{tc.%uuid of loop-player%.balance}%" to loop-player
  31. wait 20 ticks
  32. on join:
  33. if {tc.%uuid of player%.balance} is not set:
  34. set {tc.%uuid of player%.balance} to 0
  35. initializePlayerIncome(player)
  36. sendBalance()
  37.  
  38. function initializePlayerIncome(player: Player):
  39. set {_uuid} to uuid of {_player}
  40. set {tc.%{_uuid}%.income} to 1
  41. broadcast "%{tc.%{_uuid}%.income}%"
  42. loop {tc.signList.%{_uuid}%::*}:
  43. broadcast "%{tc.signdata.%loop-value%.income}%"
  44. add {tc.signdata.%loop-value%.income} to {tc.%{_uuid}%.income}
  45. set {_multipliers::*} to "I", "II" and "III"
  46. set {_multiplierValues::*} to 2.0, 2.5 and 3.0
  47. broadcast "%{tc.%{_uuid}%.income}%"
  48. loop {_multipliers::*}:
  49. if {tc.%{_uuid}%.upgradeItem_multiplier%loop-value%} is true:
  50. set {tc.%{_uuid}%.income} to {tc.%{_uuid}%.income}*{_multiplierValues::%loop-index%}
  51. #delete {tc.%uuid of player%.upgradeItem_multiplierI}
  52. #delete {tc.%uuid of player%.upgradeItem_multiplierII}
  53. #delete {tc.%uuid of player%.upgradeItem_multiplierIII}
  54.  
  55. on enable:
  56. set {_d} to 0
  57. while {tc.loopingBalance} is true:
  58. wait 5 ticks
  59. add 1 to {_d}
  60. if {_d} >= 4:
  61. delete {tc.loopingBalance}
  62. wait 1 ticks
  63. delete {tc.stopped}
  64. sendBalance()
  65.  
  66. on disable:
  67. if {tc.loopingBalance} is true:
  68. set {tc.stopped} to true
  69.  
  70. function setLineData(sign: Location, line: String, firstType: String, secondType: String):
  71. set {_lines::*} to {_line} split at " "
  72. if size of {_lines::*} is not 2:
  73. stop
  74.  
  75. set {_firstValue} to {_lines::1} parsed as an integer
  76. set {_secondValue} to {_lines::2} parsed as an integer
  77. if {_firstValue} is set:
  78. if {_secondValue} is set:
  79. if {_firstValue} > 0:
  80. if {_secondValue} > 0:
  81. set {tc.signdata.%{_sign}%.%{_firstType}%} to {_firstValue}
  82. set {tc.signdata.%{_sign}%.%{_secondType}%} to {_secondValue}
  83.  
  84. function updateSignVariables(sign: Location):
  85. add 1 to {tc.signdata.%{_sign}%.level}
  86. add {tc.signdata.%{_sign}%.costIncrease} to {tc.signdata.%{_sign}%.cost}
  87. add {tc.signdata.%{_sign}%.income} to {tc.signdata.%{_sign}%.income}
  88. if {tc.signdata.%{_sign}%.level} >= {tc.signdata.%{_sign}%.maxLevel}:
  89. set {tc.signdata.%{_sign}%.cost} to -1
  90.  
  91. on sign change:
  92. if line 1 doesn't start with "[T] ":
  93. stop
  94. setLineData(location of event-block, line 4 of event-block, "level", "maxLevel")
  95. setLineData(location of event-block, line 3 of event-block, "cost", "costIncrease")
  96. setLineData(location of event-block, line 2 of event-block, "income", "incomeIncrease")
  97. if {tc.signdata.%location of event-block%.level} >= {tc.signdata.%location of event-block%.maxLevel}:
  98. set {tc.signdata.%location of event-block%.cost} to -1
  99. if {tc.signdata.%location of event-block%.cost} is not set:
  100. stop
  101. set {_l1} to line 1
  102. replace "[T] " in {_l1} with ""
  103. set line 1 to "&6&l%{_l1}%"
  104. set line 2 to ""
  105. if {tc.signdata.%location of event-block%.cost} > -1:
  106. set line 3 to "&eCost&8: &7%{tc.signdata.%location of event-block%.cost}%"
  107. else:
  108. set line 3 to "&eCost&8: &7Max Level"
  109. set line 4 to "&bLevel&8: &7%{tc.signdata.%location of event-block%.level}%"
  110. add location of event-block to {tc.signList.%uuid of player%::*}
  111.  
  112. on right click on sign:
  113. if {tc.signdata.%location of event-block%.cost} is not set:
  114. stop
  115. else if {tc.signdata.%location of event-block%.level} >= {tc.signdata.%location of event-block%.maxLevel}:
  116. play sound "entity.item.break" to player
  117. else if {tc.%uuid of player%.balance} < {tc.signdata.%location of event-block%.cost}:
  118. play sound "entity.item.break" to player
  119. else:
  120. # Does not update the income correctly (does not add properly).
  121. remove {tc.signdata.%location of event-block%.cost} from {tc.%uuid of player%.balance}
  122. updateSignVariables(location of event-block)
  123. add {tc.signdata.%location of event-block%.incomeIncrease} to {tc.%uuid of player%.income}
  124. play sound "entity.player.levelup" to player
  125. if {tc.signdata.%location of event-block%.cost} > -1:
  126. set line 3 to "&eCost&8: &7%{tc.signdata.%location of event-block%.cost}%"
  127. else:
  128. set line 3 to "&eCost&8: &7Max Level"
  129. set line 4 to "&bLevel&8: &7%{tc.signdata.%location of event-block%.level}%"
  130.  
  131. on break of sign:
  132. if {tc.signdata.%location of event-block%.cost} is set:
  133. if {tc.signList.%uuid of player%::*} does not contain location of event-block:
  134. cancel event
  135. stop
  136. delete {tc.signdata.%location of event-block%.cost}
  137. delete {tc.signdata.%location of event-block%.costIncrease}
  138. delete {tc.signdata.%location of event-block%.level}
  139. delete {tc.signdata.%location of event-block%.maxLevel}
  140. remove location of event-block from {tc.signList.%uuid of player%::*}
  141.  
  142. command /shop:
  143. trigger:
  144. set {tc.currentInventory.%player%} to true
  145. open chest with 1 rows named "{@shop}" to player
  146. set slot 0 of player's current inventory to {@upgradesItem}
  147. set slot 1 of player's current inventory to {@prestigeUpgradesItem}
  148.  
  149. function openUpgrades(player: Player):
  150. open chest with 1 rows named "{@upgrades}" to {_player}
  151. setUpgradeInGui({_player}, 0, "upgradeItem_multiplierI", {@upgradeItem_multiplierI_locked}, {@upgradeItem_multiplierI_unlocked})
  152. setUpgradeInGui({_player}, 1, "upgradeItem_multiplierII", {@upgradeItem_multiplierII_locked}, {@upgradeItem_multiplierII_unlocked})
  153. setUpgradeInGui({_player}, 2, "upgradeItem_multiplierIII", {@upgradeItem_multiplierIII_locked}, {@upgradeItem_multiplierIII_unlocked})
  154.  
  155. wait 1 ticks
  156. set {tc.currentInventory.%{_player}%} to true
  157.  
  158. function setUpgradeInGui(player: Player, slot: Integer, variableName: String, notBought: Item, bought: Item):
  159. set {_uuid} to uuid of {_player}
  160. if {tc.%{_uuid}%.%{_variableName}%}:
  161. set slot {_slot} of {_player}'s current inventory to {_bought}
  162. else:
  163. set slot {_slot} of {_player}'s current inventory to {_notBought}
  164.  
  165. function openPrestigeUpgrades(player: Player):
  166. open chest with 1 rows named "{@prestigeUpgrades}" to {_player}
  167. wait 1 ticks
  168. set {tc.currentInventory.%{_player}%} to true
  169.  
  170.  
  171. function handleShopInventoryClick(player: Player, clicked: Item):
  172. if {_clicked} is {@upgradesItem}:
  173. openUpgrades({_player})
  174. else if {_clicked} is {@prestigeUpgradesItem}:
  175. openPrestigeUpgrades({_player})
  176. else:
  177. stop
  178. play sound "ui.button.click" to {_player}
  179.  
  180. function tryBuyUpgrade(player: Player, name: String, variableName: String, price: int, prestigeUpgrades: Boolean):
  181. set {_uuid} to uuid of {_player}
  182. if {tc.%{_uuid}%.%{_variableName}%} is true:
  183. send "{@prefix} You already bought &e%{_name}%" to {_player}
  184. play sound "entity.item.break" to {_player}
  185. else:
  186. if {tc.%{_uuid}%.balance} < {_price}:
  187. send "{@prefix} You do not have enough coins to buy &e%{_name}%" to {_player}
  188. play sound "entity.item.break" to {_player}
  189. else:
  190. set {tc.%{_uuid}%.%{_variableName}%} to true
  191. remove {_price} from {tc.%{_uuid}%.balance}
  192. send "{@prefix} You have bought &e%{_name}%" to {_player}
  193. play sound "entity.player.levelup" to {_player}
  194. initializePlayerIncome({_player})
  195. if {_prestigeUpgrades}:
  196. openPrestigeUpgrades({_player})
  197. else:
  198. openUpgrades({_player})
  199.  
  200. command /breset:
  201. trigger:
  202. set {tc.%uuid of player%.balance} to 0
  203.  
  204. command /ureset:
  205. trigger:
  206. delete {tc.%uuid of player%.upgradeItem_multiplierI}
  207. delete {tc.%uuid of player%.upgradeItem_multiplierII}
  208. delete {tc.%uuid of player%.upgradeItem_multiplierIII}
  209. initializePlayerIncome(player)
  210.  
  211.  
  212. function handleUpgradeInventoryClick(player: Player, clicked: Item):
  213. if {_clicked} is air:
  214. stop
  215. if checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierI_locked}) or checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierI_unlocked}):
  216. tryBuyUpgrade({_player}, "Multiplier I", "upgradeItem_multiplierI", {@upgradeItem_multiplierIPrice}, false)
  217. else if checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierII_locked}) or checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierII_unlocked}):
  218. tryBuyUpgrade({_player}, "Multiplier II", "upgradeItem_multiplierII", {@upgradeItem_multiplierIIPrice}, false)
  219. else if checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierIII_locked}) or checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierIII_unlocked}):
  220. tryBuyUpgrade({_player}, "Multiplier III", "upgradeItem_multiplierIII", {@upgradeItem_multiplierIIIPrice}, false)
  221.  
  222. function checkIfItemIsEqualTo(check: Item, equalTo: Item) :: Boolean:
  223. if type of {_check} is not type of {_equalTo}:
  224. return false
  225. else if item amount of {_check} is not item amount of {_equalTo}:
  226. return false
  227. else if name of {_check} is not name of {_equalTo}:
  228. return false
  229. else if "%lore of {_check}%" is not "%lore of {_equalTo}%":
  230. return false
  231. return true
  232.  
  233. on inventory click:
  234. if "%event-inventory%" is not "inventory of <none>":
  235. stop
  236. if inventory name of clicked inventory is "{@shop}":
  237. cancel event
  238. handleShopInventoryClick(player, event-item)
  239. else if inventory name of clicked inventory is "{@upgrades}":
  240. cancel event
  241. handleUpgradeInventoryClick(player, event-item)
  242. else if inventory name of clicked inventory is "{@prestigeUpgrades}":
  243. cancel event
  244. send "PRESTIGE UPGRADES"
  245.  
  246. on inventory close:
  247. delete {tc.currentInventory.%player%}
  248.  
  249. on inventory drag:
  250. if {tc.currentInventory.%player%} is set:
  251. cancel event
  252.  
  253. on quit:
  254. delete {tc.currentInventory.%player%}
  255.  
Advertisement
Add Comment
Please, Sign In to add comment