Advertisement
MasterKyle08

shop

Nov 11th, 2019 (edited)
1,564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.39 KB | None | 0 0
  1. options:
  2.  
  3. Permission-EditShop: shopping.editshop
  4. Shopping-Command-Aliases: shop
  5.  
  6. GUI-Name: "Shopping &7[Page {page}]"
  7. GUI-Info: "&aLeft click to buy items.||&cRight click to sell items.||&8SHIFT + LMB/RMB to buy/sell stacks of items.||||&7Shopping by CreeperOverLord7"
  8.  
  9. CostPrice-Prefix: "&a[LMB] Cost Price: &f"
  10. SellingPrice-Prefix: "&c[RMB] Selling Price: &f"
  11. Lore-NotPurchasable: "&8This item is not purchasable."
  12. Lore-NotSaleable: "&8This item is not saleable."
  13.  
  14. NextPage-Prefix: "&aNext Page: &f"
  15. PreviousPage-Prefix: "&aPrevious Page: &f"
  16. CurrentPage-Prefix: "&8Current Page: &7"
  17.  
  18. Message-Invalid-Page: "&cThe page you are trying to access is invalid and cannot be opened."
  19.  
  20. Message-Not-Enough-Money: "&cYou do not have enough money to purchase this item."
  21. Message-Unpurchasable-Item: "&cYou cannot purchase this item."
  22. Message-Unsaleable-Item: "&cYou cannot sell this item."
  23. Message-No-Space: "&cYou do not have enough space in your inventory to purchase this item."
  24. Message-No-Item-To-Sell: "&cYou do not have the required item to sell."
  25.  
  26. Message-Buy-Item: "&aYou bought &f{item} &afor &f${price}&a."
  27. Message-Sell-Item: "&aYou sold &f{item} &afor &f${price}&a."
  28.  
  29. Ver: 1.0
  30.  
  31. # {shopping.item::*} is a list of all the shop items
  32. # elements of {shopping.items::*} are of type item
  33. #
  34. # {shopping.itemDetails::*} is a list of all details needed for shop
  35. # elements of {shopping.itemDetails::*} are of type string,
  36. # formatted "%costprice%|%sellingprice%"
  37. #
  38. # if cost price or selling price is negative; then the item will not be purchasable/sellable.
  39.  
  40. function shopping_getDetail(detail: string, from: string) :: number:
  41. set {_parser::*} to {_from} parsed as "%number%\|%number%"
  42. if {_detail} = "CostPrice":
  43. return {_parser::1}
  44. else if {_detail} = "SellingPrice":
  45. return {_parser::2}
  46. #return null
  47.  
  48. function shopping_getLore(detail: string, from: item) :: number:
  49. set {_costPricePrefix} to {@CostPrice-Prefix}
  50. set {_sellingPricePrefix} to {@SellingPrice-Prefix}
  51. set {_lore::*} to lore of {_from} split by "||"
  52. loop {_lore::*}:
  53. if {_detail} = "CostPrice":
  54. if first (length of {_costPricePrefix}) characters of loop-value = {_costPricePrefix}:
  55. return (substring of loop-value from (length of {_costPricePrefix} + 1) to (length of loop-value)) parsed as number
  56. else if {_detail} = "SellingPrice":
  57. if first (length of {_sellingPricePrefix}) characters of loop-value = {_sellingPricePrefix}:
  58. return (substring of loop-value from (length of {_sellingPricePrefix} + 1) to (length of loop-value)) parsed as number
  59. else if {_detail} = "Index":
  60. if first (length of "&0i") characters of loop-value = "&0i":
  61. return (substring of loop-value from (length of "&0i" + 1) to (length of loop-value)) parsed as number
  62. #return null
  63.  
  64. function shopping_getItemName(item: item) :: string:
  65. if name of {_item} is set:
  66. return name of {_item}
  67. return "%{_item}%"
  68.  
  69. function shopping_getNextAutoIndex() :: number:
  70. set {_max} to 0
  71. loop {shopping.item::*}:
  72. if (loop-index parsed as number) > {_max}:
  73. set {_max} to loop-index parsed as number
  74. return {_max} + 1
  75.  
  76. function shopping_gui(player: player, page: number):
  77.  
  78. if {_page} <= 0:
  79. send {@Message-Invalid-Page} to {_player}
  80. exit trigger
  81.  
  82. if {_filter} is not set:
  83. set {_filter} to ""
  84.  
  85. set {_guiName} to {@GUI-Name}
  86. replace "{page}" in {_guiName} with "%{_page}%"
  87. set {_chest} to chest inventory with 6 rows named {_guiName}
  88.  
  89. loop 9 times:
  90. set slot (5 * 9 - 1 + loop-number) of {_chest} to stained_glass_pane:8 named "&0"
  91.  
  92. set {_startIndex} to 45 * ({_page} - 1)
  93.  
  94. set {_costPricePrefix} to {@CostPrice-Prefix}
  95. set {_sellingPricePrefix} to {@SellingPrice-Prefix}
  96. set {_notPurchasable} to {@Lore-NotPurchasable}
  97. set {_notSaleable} to {@Lore-NotSaleable}
  98.  
  99. loop 45 times:
  100. set {_index} to {_startIndex} + loop-number
  101. set {_costPrice} to shopping_getDetail("CostPrice", {shopping.itemDetails::%{_index}%})
  102. set {_sellingPrice} to shopping_getDetail("SellingPrice", {shopping.itemDetails::%{_index}%})
  103.  
  104. set {_lore} to lore of {shopping.item::%{_index}%}
  105. set {_lore} to ({_costPrice} >= 0) ? "%{_lore}%||%{_costPricePrefix}%%{_costPrice}%" : "%{_lore}%||%{_notPurchasable}%"
  106. set {_lore} to ({_sellingPrice} >= 0) ? "%{_lore}%||%{_sellingPricePrefix}%%{_sellingPrice}%" : "%{_lore}%||%{_notSaleable}%"
  107. set {_lore} to "%{_lore}%||&0i%{_index}%"
  108. set slot (loop-number - 1) of {_chest} to {shopping.item::%{_index}%} with lore {_lore}
  109.  
  110. set {_nextPagePrefix} to {@NextPage-Prefix}
  111. set {_previousPagePrefix} to {@PreviousPage-Prefix}
  112. set {_currentPagePrefix} to {@CurrentPage-Prefix}
  113.  
  114. set {_temp} to 45 * {_page} + 1
  115. if {shopping.item::%{_temp}%} is set:
  116. set slot (6 * 9 - 1) of {_chest} to arrow named "%{_nextPagePrefix}%%{_page} + 1%" with lore "%{_currentPagePrefix}%%{_page}%"
  117. if {_page} - 1 > 0:
  118. set slot (6 * 9 - 9) of {_chest} to arrow named "%{_previousPagePrefix}%%{_page} - 1%" with lore "%{_currentPagePrefix}%%{_page}%"
  119. set slot (6 * 9 - 5) of {_chest} to sign named "&8---&cINFO&8---" with lore {@GUI-Info}
  120.  
  121. open {_chest} to {_player}
  122.  
  123. on inventory click:
  124.  
  125. cancel event
  126.  
  127. set {_startsWith} to ""
  128. set {_splitString::*} to ({@GUI-Name}) split by ""
  129. loop {_splitString::*}:
  130. if loop-value = "{":
  131. exit loop
  132. set {_startsWith} to "%{_startsWith}%%loop-value%"
  133.  
  134. if first (length of {_startsWith}) characters of (name of current inventory of event-player) != {_startsWith}:
  135. uncancel event
  136. exit trigger
  137. if first (length of {_startsWith}) characters of (name of clicked inventory) != {_startsWith}:
  138. exit trigger
  139.  
  140. if type of clicked item = arrow:
  141. if first (length of {@NextPage-Prefix}) characters of (name of clicked item) = {@NextPage-Prefix}:
  142. set {_nextPageNumber} to (subtext of name of clicked item from (length of {@NextPage-Prefix} + 1) to (length of name of clicked item)) parsed as number
  143. shopping_gui(event-player, {_nextPageNumber})
  144. exit trigger
  145. if first (length of {@PreviousPage-Prefix}) characters of (name of clicked item) = {@PreviousPage-Prefix}:
  146. set {_lastPageNumber} to (subtext of name of clicked item from (length of {@PreviousPage-Prefix} + 1) to (length of name of clicked item)) parsed as number
  147. shopping_gui(event-player, {_lastPageNumber})
  148. exit trigger
  149.  
  150. if type of clicked item = air:
  151. exit trigger
  152. if clicked slot >= 45:
  153. exit trigger
  154.  
  155. set {_index} to shopping_getLore("Index", clicked item)
  156. set {_costPrice} to shopping_getDetail("CostPrice", {shopping.itemDetails::%{_index}%})
  157. set {_sellingPrice} to shopping_getDetail("SellingPrice", {shopping.itemDetails::%{_index}%})
  158.  
  159. if click type = left mouse button or left mouse button with shift:
  160.  
  161. if check [{_costPrice} is not set] or check [{_costPrice} < 0]:
  162. send {@Message-Unpurchasable-Item} to event-player
  163. play sound "entity.villager.no" at event-player for event-player
  164. exit trigger
  165.  
  166. set {_item} to 1 of {shopping.item::%{_index}%}
  167. if click type = left mouse button with shift:
  168. set {_pricefor1} to {_costPrice}
  169. set {_costPrice} to {_costPrice} * 64
  170. set {_item} to 64 of {_item}
  171.  
  172. if !check [event-player has space for {_item}]:
  173. send {@Message-No-Space}
  174. play sound "entity.villager.no" at event-player for event-player
  175. exit trigger
  176. if player's balance < {_costPrice}:
  177. send {@Message-Not-Enough-Money} to event-player
  178. play sound "entity.villager.no" at event-player for event-player
  179. exit trigger
  180. remove {_costPrice} from event-player's balance
  181. give {_item} to event-player
  182. play sound "entity.item.pickup" at event-player for event-player
  183. set {_message} to {@Message-Buy-Item}
  184. replace "{item}" in {_message} with shopping_getItemName({_item})
  185. replace "{price}" in {_message} with "%{_costPrice}%"
  186. send {_message} to event-player
  187. log "%event-player% bought %{_item}% for %{_costPrice}% [$%{_pricefor1}%/item]"
  188.  
  189. else if click type = right mouse button or right mouse button with shift:
  190.  
  191. if check [{_sellingPrice} is not set] or check [{_sellingPrice} < 0]:
  192. send {@Message-Unsaleable-Item} to event-player
  193. play sound "entity.villager.no" at event-player for event-player
  194. exit trigger
  195.  
  196. set {_item} to 1 of {shopping.item::%{_index}%}
  197. if click type = right mouse button with shift:
  198. set {_pricefor1} to {_sellingPrice}
  199. set {_sellingPrice} to {_sellingPrice} * 64
  200. set {_item} to 64 of {_item}
  201.  
  202. if !check [player has {_item}'s item amount of {_item}]:
  203. send {@Message-No-Item-To-Sell} to event-player
  204. play sound "entity.villager.no" at event-player for event-player
  205. exit trigger
  206. add {_sellingPrice} to event-player's balance
  207. remove {_item} from event-player's inventory
  208. play sound "entity.item.pickup" at event-player for event-player
  209. set {_message} to {@Message-Sell-Item}
  210. replace "{item}" in {_message} with shopping_getItemName({_item})
  211. replace "{price}" in {_message} with "%{_sellingPrice}%"
  212. send {_message} to event-player
  213. log "%event-player% sold %{_item}% for %{_sellingPrice}% [$%{_pricefor1}%/item]" to "shopping-purchase"
  214.  
  215. command /shopping [<text>] [<text>] [<number>] [<number>]:
  216. aliases: shop
  217. usage: /shopping help
  218. trigger:
  219.  
  220. if check [executor does not have permission "{@Permission-EditShop}"] or check [arg-1 is not set]:
  221. shopping_gui(executor, 1)
  222. play sound "block.note.pling" at executor for executor
  223. exit trigger
  224.  
  225. if arg-1 = "setitem":
  226.  
  227. set {_arg2} to arg-2 parsed as integer
  228. if check [arg-2 is not set] or check [{_arg2} <= 0]:
  229. send "&cUsage: /shopping %arg-1% <id> [costprice] [sellingprice]" to executor
  230. send "&c(ID must be an integer greater than 0 or 'auto')" to executor
  231. exit trigger
  232.  
  233. if check [{_arg2} is not set] -> [arg-2 != "auto"]:
  234. send "&cUsage: /shopping %arg-1% <id> [costprice] [sellingprice]" to executor
  235. send "&c(ID must be an integer greater than 0 or 'auto')" to executor
  236. exit trigger
  237.  
  238. if player's tool = air:
  239. send "&cCan't add air to shop." to executor
  240. exit trigger
  241.  
  242. set {_index} to {_arg2}
  243. if arg-2 = "auto":
  244. set {_index} to shopping_getNextAutoIndex()
  245.  
  246. set {_arg3} to check [arg-3 is set] ? arg-3 : -1
  247. set {_arg4} to check [arg-4 is set] ? arg-4 : -1
  248.  
  249. set {shopping.item::%{_index}%} to 1 of executor's tool
  250. set {shopping.itemDetails::%{_index}%} to "%{_arg3}%|%{_arg4}%"
  251. send "&2[SHOPPING] &f%executor% &aset item index &f%{_index}% &ato <show text:&f%shopping_getItemName({shopping.item::%{_index}%})%>&f[HOVER]<reset>&a; <show text:Cost Price: %{_arg3}%, Selling Price: %{_arg4}%>&f[PRICE]&a." to all players where [player input has permission "{@Permission-EditShop}"]
  252. log "%executor% set item index %{_index}% to %shopping_getItemName({shopping.item::%{_index}%})%; cost price: %{_arg3}%, selling price: %{_arg4}%" to "shopping-edit"
  253.  
  254. else if arg-1 = "setcost" or "setcostprice":
  255.  
  256. set {_arg2} to arg-2 parsed as integer
  257. if check [arg-2 is not set] or check [{_arg2} <= 0]:
  258. send "&cUsage: /shopping %arg-1% <id> <costprice>" to executor
  259. send "&c(ID must be an integer greater than 0)" to executor
  260. exit trigger
  261. if {_arg2} is not set:
  262. send "&cUsage: /shopping %arg-1% <id> <costprice>" to executor
  263. send "&c(ID must be an integer greater than 0)" to executor
  264. exit trigger
  265. if arg-3 is not set:
  266. send "&cUsage: /shopping %arg-1% %arg-2% <costprice>" to executor
  267. exit trigger
  268.  
  269. if {shopping.itemDetails::%arg-2%} is not set:
  270. set {shopping.itemDetails::%arg-2%} to "-1|-1"
  271. set {_split::*} to {shopping.itemDetails::%arg-2%} split by "|"
  272. set {_split::1} to "%arg-3%"
  273. set {_str} to ""
  274. loop {_split::*}:
  275. set {_str} to "%{_str}%%loop-value%|"
  276. set {_str} to substring of {_str} from 1 to (length of {_str} - 1)
  277. set {shopping.itemDetails::%arg-2%} to {_str}
  278.  
  279. send "&2[SHOPPING] &f%executor% &aset cost price of item index &f%arg-2% <show text:&f%shopping_getItemName({shopping.item::%arg-2%})%>&7[HOVER]<reset> &ato &f%arg-3%&a." to all players where [player input has permission "{@Permission-EditShop}"]
  280. log "%executor% set cost price of item index %arg-2% [%shopping_getItemName({shopping.item::%arg-2%})%] to %arg-3%" to "shopping-edit"
  281.  
  282. else if arg-1 = "setsell" or "setsellingprice":
  283.  
  284. set {_arg2} to arg-2 parsed as integer
  285. if check [arg-2 is not set] or check [{_arg2} <= 0]:
  286. send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
  287. send "&c(ID must be an integer greater than 0)" to executor
  288. exit trigger
  289. if {_arg2} is not set:
  290. send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
  291. send "&c(ID must be an integer greater than 0)" to executor
  292. exit trigger
  293. if arg-3 is not set:
  294. send "&cUsage: /shopping %arg-1% %arg-2% <sellingprice>" to executor
  295. exit trigger
  296.  
  297. if {shopping.itemDetails::%arg-2%} is not set:
  298. set {shopping.itemDetails::%arg-2%} to "-1|-1"
  299. set {_split::*} to {shopping.itemDetails::%arg-2%} split by "|"
  300. set {_split::2} to "%arg-3%"
  301. set {_str} to ""
  302. loop {_split::*}:
  303. set {_str} to "%{_str}%%loop-value%|"
  304. set {_str} to substring of {_str} from 1 to (length of {_str} - 1)
  305. set {shopping.itemDetails::%arg-2%} to {_str}
  306.  
  307. send "&2[SHOPPING] &f%executor% &aset selling price of item index &f%arg-2% <show text:&f%shopping_getItemName({shopping.item::%arg-2%})%>&7[HOVER]<reset> &ato &f%arg-3%&a." to all players where [player input has permission "{@Permission-EditShop}"]
  308. log "%executor% set selling price of item index %arg-2% [%shopping_getItemName({shopping.item::%arg-2%})%] to %arg-3%" to "shopping-edit"
  309.  
  310. else if arg-1 = "removeitem" or "clearitem":
  311.  
  312. set {_arg2} to arg-2 parsed as integer
  313. if check [arg-2 is not set] or check [{_arg2} <= 0]:
  314. send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
  315. send "&c(ID must be an integer greater than 0)" to executor
  316. exit trigger
  317. if {_arg2} is not set:
  318. send "&cUsage: /shopping %arg-1% <id> <sellingprice>" to executor
  319. send "&c(ID must be an integer greater than 0)" to executor
  320. exit trigger
  321.  
  322. set {_item} to {shopping.item::%arg-2%}
  323. delete {shopping.item::%arg-2%}
  324. delete {shopping.itemDetails::%arg-2%}
  325.  
  326. send "&2[SHOPPING] &f%executor% &adeleted item index &f%arg-2% <show text:&f%shopping_getItemName({_item})%>&7[HOVER]<reset>&a."
  327. log "%executor% deleted item index %arg-2% [%shopping_getItemName({_item})%]."
  328.  
  329. else if arg-1 = "help":
  330.  
  331. send "" to executor
  332. send "&2SHOPPING &aVersion &f{@Ver} by &fCreeperOverLord7" to executor
  333. send "&7Hover over commands to view use." to executor
  334. send "<suggest command:/shop><show text:&fOpens the shop menu.>&b/shop<reset>" to executor
  335. send "<suggest command:/shop setitem <id>><show text:&fSets the item at position ID in the shop.>&b/shop setitem <id> [costprice] [sellingprice]<reset>" to executor
  336. send "<suggest command:/shop <setcost|setcostprice> <id> <costprice>><show text:&fSets the cost price of the item at position ID in the shop.>&b/shop <setcost|setcostprice> <id> <costprice><reset>" to executor
  337. send "<suggest command:/shop <setsell|setsellingprice> <id> <sellingprice>><show text:&fSets the selling price of the item at position ID in the shop.>&b/shop <setsell|setsellingprice> <id> <sellingprice><reset>" to executor
  338. send "" to executor
  339. play sound "entity.villager.yes" at executor for executor
  340.  
  341. else:
  342. send "&cUsage: /shop help" to executor
  343.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement