Zeldaboy111

Upgrades-shop Fixed ]|[ Skript #442

Aug 15th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.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. loop {tc.signList.%{_uuid}%::*}:
  42. add {tc.signdata.%loop-value%.income} to {tc.%{_uuid}%.income}
  43.  
  44.  
  45. on enable:
  46. set {_d} to 0
  47. while {tc.loopingBalance} is true:
  48. wait 5 ticks
  49. add 1 to {_d}
  50. if {_d} >= 4:
  51. delete {tc.loopingBalance}
  52. wait 1 ticks
  53. delete {tc.stopped}
  54. sendBalance()
  55.  
  56. on disable:
  57. if {tc.loopingBalance} is true:
  58. set {tc.stopped} to true
  59.  
  60. function setLineData(sign: Location, line: String, firstType: String, secondType: String):
  61. set {_lines::*} to {_line} split at " "
  62. if size of {_lines::*} is not 2:
  63. stop
  64.  
  65. set {_firstValue} to {_lines::1} parsed as an integer
  66. set {_secondValue} to {_lines::2} parsed as an integer
  67. if {_firstValue} is set:
  68. if {_secondValue} is set:
  69. if {_firstValue} > 0:
  70. if {_secondValue} > 0:
  71. set {tc.signdata.%{_sign}%.%{_firstType}%} to {_firstValue}
  72. set {tc.signdata.%{_sign}%.%{_secondType}%} to {_secondValue}
  73.  
  74. function updateSignVariables(sign: Location):
  75. add 1 to {tc.signdata.%{_sign}%.level}
  76. add {tc.signdata.%{_sign}%.costIncrease} to {tc.signdata.%{_sign}%.cost}
  77. add {tc.signdata.%{_sign}%.income} to {tc.signdata.%{_sign}%.income}
  78. if {tc.signdata.%{_sign}%.level} >= {tc.signdata.%{_sign}%.maxLevel}:
  79. set {tc.signdata.%{_sign}%.cost} to -1
  80.  
  81. on sign change:
  82. if line 1 doesn't start with "[T] ":
  83. stop
  84. setLineData(location of event-block, line 4 of event-block, "level", "maxLevel")
  85. setLineData(location of event-block, line 3 of event-block, "cost", "costIncrease")
  86. setLineData(location of event-block, line 2 of event-block, "income", "incomeIncrease")
  87. if {tc.signdata.%location of event-block%.level} >= {tc.signdata.%location of event-block%.maxLevel}:
  88. set {tc.signdata.%location of event-block%.cost} to -1
  89. if {tc.signdata.%location of event-block%.cost} is not set:
  90. stop
  91. set {_l1} to line 1
  92. replace "[T] " in {_l1} with ""
  93. set line 1 to "&6&l%{_l1}%"
  94. set line 2 to ""
  95. if {tc.signdata.%location of event-block%.cost} > -1:
  96. set line 3 to "&eCost&8: &7%{tc.signdata.%location of event-block%.cost}%"
  97. else:
  98. set line 3 to "&eCost&8: &7Max Level"
  99. set line 4 to "&bLevel&8: &7%{tc.signdata.%location of event-block%.level}%"
  100. add location of event-block to {tc.signList.%uuid of player%::*}
  101.  
  102. on right click on sign:
  103. if {tc.signdata.%location of event-block%.cost} is not set:
  104. stop
  105. else if {tc.signdata.%location of event-block%.level} >= {tc.signdata.%location of event-block%.maxLevel}:
  106. play sound "entity.item.break" to player
  107. else if {tc.%uuid of player%.balance} < {tc.signdata.%location of event-block%.cost}:
  108. play sound "entity.item.break" to player
  109. else:
  110. remove {tc.signdata.%location of event-block%.cost} from {tc.%uuid of player%.balance}
  111. updateSignVariables(location of event-block)
  112. add {tc.signdata.%location of event-block%.incomeIncrease} to {tc.%uuid of player%.income}
  113. play sound "entity.player.levelup" to player
  114. if {tc.signdata.%location of event-block%.cost} > -1:
  115. set line 3 to "&eCost&8: &7%{tc.signdata.%location of event-block%.cost}%"
  116. else:
  117. set line 3 to "&eCost&8: &7Max Level"
  118. set line 4 to "&bLevel&8: &7%{tc.signdata.%location of event-block%.level}%"
  119.  
  120. on break of sign:
  121. if {tc.signdata.%location of event-block%.cost} is set:
  122. delete {tc.signdata.%location of event-block%.cost}
  123. delete {tc.signdata.%location of event-block%.costIncrease}
  124. delete {tc.signdata.%location of event-block%.level}
  125. delete {tc.signdata.%location of event-block%.maxLevel}
  126. remove location of event-block from {tc.signList.%uuid of player%::*}
  127.  
  128. command /shop:
  129. trigger:
  130. set {tc.currentInventory.%player%} to true
  131. open chest with 1 rows named "{@shop}" to player
  132. set slot 0 of player's current inventory to {@upgradesItem}
  133. set slot 1 of player's current inventory to {@prestigeUpgradesItem}
  134.  
  135. function openUpgrades(player: Player):
  136. open chest with 1 rows named "{@upgrades}" to {_player}
  137. setUpgradeInGui({_player}, 0, "upgradeItem_multiplierI", {@upgradeItem_multiplierI_locked}, {@upgradeItem_multiplierI_unlocked})
  138. setUpgradeInGui({_player}, 1, "upgradeItem_multiplierII", {@upgradeItem_multiplierII_locked}, {@upgradeItem_multiplierII_unlocked})
  139. setUpgradeInGui({_player}, 2, "upgradeItem_multiplierIII", {@upgradeItem_multiplierIII_locked}, {@upgradeItem_multiplierIII_unlocked})
  140.  
  141. wait 1 ticks
  142. set {tc.currentInventory.%{_player}%} to true
  143.  
  144. function setUpgradeInGui(player: Player, slot: Integer, variableName: String, notBought: Item, bought: Item):
  145. set {_uuid} to uuid of {_player}
  146. if {tc.%{_uuid}%.%{_variableName}%}:
  147. set slot {_slot} of {_player}'s current inventory to {_bought}
  148. else:
  149. set slot {_slot} of {_player}'s current inventory to {_notBought}
  150.  
  151. function openPrestigeUpgrades(player: Player):
  152. open chest with 1 rows named "{@prestigeUpgrades}" to {_player}
  153. wait 1 ticks
  154. set {tc.currentInventory.%{_player}%} to true
  155.  
  156.  
  157. function handleShopInventoryClick(player: Player, clicked: Item):
  158. if {_clicked} is {@upgradesItem}:
  159. openUpgrades({_player})
  160. else if {_clicked} is {@prestigeUpgradesItem}:
  161. openPrestigeUpgrades({_player})
  162. else:
  163. stop
  164. play sound "ui.button.click" to {_player}
  165.  
  166. function tryBuyUpgrade(player: Player, name: String, variableName: String, price: int, prestigeUpgrades: Boolean):
  167. set {_uuid} to uuid of {_player}
  168. if {tc.%{_uuid}%.%{_variableName}%} is true:
  169. send "{@prefix} You already bought &e%{_name}%" to {_player}
  170. play sound "entity.item.break" to {_player}
  171. else:
  172. if {tc.%{_uuid}%.balance} < {_price}:
  173. send "{@prefix} You do not have enough coins to buy &e%{_name}%" to {_player}
  174. play sound "entity.item.break" to {_player}
  175. else:
  176. set {tc.%{_uuid}%.%{_variableName}%} to true
  177. remove {_price} from {tc.%{_uuid}%.balance}
  178. send "{@prefix} You have bought &e%{_name}%" to {_player}
  179. play sound "entity.player.levelup" to {_player}
  180. if {_prestigeUpgrades}:
  181. openPrestigeUpgrades({_player})
  182. else:
  183. openUpgrades({_player})
  184.  
  185. command /breset:
  186. trigger:
  187. set {tc.%uuid of player%.balance} to 0
  188.  
  189. function handleUpgradeInventoryClick(player: Player, clicked: Item):
  190. if {_clicked} is air:
  191. stop
  192. if checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierI_locked}) or checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierI_unlocked}):
  193. tryBuyUpgrade({_player}, "Multiplier I", "upgradeItem_multiplierI", {@upgradeItem_multiplierIPrice}, false)
  194. else if checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierII_locked}) or checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierII_unlocked}):
  195. tryBuyUpgrade({_player}, "Multiplier II", "upgradeItem_multiplierII", {@upgradeItem_multiplierIIPrice}, false)
  196. else if checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierIII_locked}) or checkIfItemIsEqualTo({_clicked}, {@upgradeItem_multiplierIII_unlocked}):
  197. tryBuyUpgrade({_player}, "Multiplier III", "upgradeItem_multiplierIII", {@upgradeItem_multiplierIIIPrice}, false)
  198.  
  199. function checkIfItemIsEqualTo(check: Item, equalTo: Item) :: Boolean:
  200. if type of {_check} is not type of {_equalTo}:
  201. return false
  202. else if item amount of {_check} is not item amount of {_equalTo}:
  203. return false
  204. else if name of {_check} is not name of {_equalTo}:
  205. return false
  206. else if "%lore of {_check}%" is not "%lore of {_equalTo}%":
  207. return false
  208. return true
  209.  
  210. on inventory click:
  211. if "%event-inventory%" is not "inventory of <none>":
  212. stop
  213. if inventory name of clicked inventory is "{@shop}":
  214. cancel event
  215. handleShopInventoryClick(player, event-item)
  216. else if inventory name of clicked inventory is "{@upgrades}":
  217. cancel event
  218. handleUpgradeInventoryClick(player, event-item)
  219. else if inventory name of clicked inventory is "{@prestigeUpgrades}":
  220. cancel event
  221. send "PRESTIGE UPGRADES"
  222.  
  223. on inventory close:
  224. delete {tc.currentInventory.%player%}
  225.  
  226. on inventory drag:
  227. if {tc.currentInventory.%player%} is set:
  228. cancel event
  229.  
  230. on quit:
  231. delete {tc.currentInventory.%player%}
  232.  
Advertisement
Add Comment
Please, Sign In to add comment