Date: 2020/05/15 14:20:51 UTC-07:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
SB_SaveShop_Command:
type: command
debug: false
name: saveshop
description: save the testshop
usage: /saveshop
permission: SkyBread.SaveShop
tab complete:
- if !<player.is_op||<context.server>>:
- stop
script:
- if <context.args.is_empty>:
- narrate "Saving all SkyBread shops..."
#List the Shop Categories, each defined as "Category"
- foreach <script[SkyBread_Shop_Data].list_keys[Item_Data]> as:Category:
#For every item inside that Category
- foreach <script[SkyBread_Shop_Data].list_keys[Item_Data.<[Category]>].alphabetical> as:Item:
#Get the Item_Data (buy/sell prices) of each item in that category
- define Item_Data <script[SkyBread_Shop_Data].yaml_key[Item_Data.<[Category]>.<[Item]>]>
#If "Items" (list of all the items) doesn't exist, or the size (item count) is less than or equal to 45, add the item to the list
##here is the problem
- if !<[Items].exists> || <[Items].size> <= 45:
- define "Items:->:<item[SB_Shop_Item].with[material=<[Item]>;display_name=<&b><[Item].as_material.name.replace[_].with[<&sp>].to_titlecase>;nbt=<list[Shop_Item/<[Item_data]>]>;Lore=<list[<&7>Buy Price: $<&a><[Item_Data].before[/]>|<&7>Sell Price: $<&c><[Item_Data].after[/]>|<empty>|<&a>Left click to buy|<&c>Right click to sell|<&9>MMB to adjust amount]>]>"
#If not, define a new term, "Items2", where the second page of the items belong
- else:
- define "Items2:->:<item[SB_Shop_Item].with[material=<[Item]>;display_name=<&b><[Item].as_material.name.replace[_].with[<&sp>].to_titlecase>;nbt=<list[Shop_Item/<[Item_data]>]>;Lore=<list[<&7>Buy Price: $<&a><[Item_Data].before[/]>|<&7>Sell Price: $<&c><[Item_Data].after[/]>|<empty>|<&a>Left click to buy|<&c>Right click to sell|<&9>MMB to adjust amount]>]>"
#Create the Inventory that includes the first page's contents
- define Inventory "<inventory[generic[size=54;contents=<[Items]>;title=SkyBread Shop » <[Category].to_titlecase>]]>"
#Set the arrow in slot 46, that takes you back to the Shop Categories page
- inventory set d:<[Inventory]> slot:46 o:<item[SB_Shop_Item].with[material=arrow;display_name=<&a><&l>Go<&sp>Back;nbt=<list[Action/Shop]>]>
#This narration is used to debug the item count, which is where I encounter my issue. For example, the ore's item count is 16, but <[Items].size> returns 46
- narrate "<[Category]> = <[Items].size>"
#If the Item count is greather than 45, create the next page that includes the other items
- if <[Items].size> > 45:
#-&& <[Items].size> < 90:
#Store the value of the next page of the Category's inventory
- flag server "SkyBread.Shop.<[Category]>.Page2:<inventory[generic[size=54;contents=<[Items2]>;title=SkyBread Shop » <[Category].to_titlecase>]]>"
#The SkyBread.Shop.ActiveWindow flag determine which category the "Back" arrow of the second page returns to
- flag player SkyBread.Shop.ActiveWindow:<[Category]>
#Place the Back arrow that returns to the first page of the category in slot:46
- inventory set d:<server.flag[SkyBread.Shop.<[Category]>.Page2]> slot:46 o:<item[SB_Shop_Item].with[material=tipped_arrow;display_name=<&a><&l>Back;nbt=<list[Action/<player.flag[SkyBread.Shop.ActiveWindow]>;potion_effects=<list[instant_heal,false,false]>]>]>
#Add a "Next" Arrow on the first page, that redirects the player to the second page of the category
- inventory set d:<[Inventory]> slot:54 o:<item[SB_Shop_Item].with[material=tipped_arrow;display_name=<&a><&l>Next;nbt=<list[Action/<[Category]>_Page2]>;potion_effects=JUMP,0,2400]>
#Remove the ActiveWindow flag
- flag player SkyBread.Shop.ActiveWindow:!
#Save the current inventory (page 1) as server SkyBread.Shop.<[Category]>, so that each time the /shop [category] command won't have to procedurally generate the items again.
- flag server SkyBread.Shop.<[Category]>:<[Inventory]>
- narrate "<&a><&l>Shops saved!"
- else:
- narrate "<&c>Incorrect command usage! Type /saveshop"