Date: 2020/09/25 14:56: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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
##Core Script##
##Inventory for the shop creator menu##
ShopCreatorInv:
type: inventory
title: Shop Editor
size: 54
inventory: CHEST
slots:
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] [SaveShopIt]"
- "[ClearCostIt] [CostMinus1It] [CostMinus10It] [CostMinus100It] [CostMinus1000It] [CostPlus1It] [CostPlus10It] [CostPlus100It] [CostPlus1000It]"
Procedural Items:
- if <player.has_flag[EditShop]> && <player.has_flag[AdjustedCost].not>:
- determine <yaml[<player.flag[EditShop].get[1]>].read[<player.flag[EditShop].get[2]>]>
- stop
- if <player.has_flag[AdjustedCost]>:
- determine <player.flag[AdjustedCost]>
##World script to handle Shop Creator Inventory##
ShopCreatorHandler:
type: world
debug: true
events:
on player drags in ShopCreatorInv:
- determine cancelled
after player clicks in ShopCreatorInv:
- if <context.inventory> == <context.clicked_inventory>:
- if <context.cursor_item.has_nbt[ShopMenuItem].not> && <context.cursor_item.contains[air].not>:
- if <context.cursor_item.has_nbt[Cost].not>:
- define adjustedcost <context.cursor_item.with[nbt=Cost/0]>
- if <context.cursor_item.lore.size||0> == 0:
- if <player.has_flag[SellShop]>:
- adjust def:adjustedcost "lore:Click Here to Sell! Offer: $<[adjustedcost].nbt[Cost]>"
- else:
- adjust def:adjustedcost "lore:Click Here to Buy! For: $<[adjustedcost].nbt[Cost]>"
- else:
- adjust def:adjustedcost "lore:<[adjustedcost].lore.include[Click Here to Buy! Cost: $<[adjustedcost].nbt[Cost]>]>"
- inventory set destination:<context.inventory> origin:<[adjustedcost]> slot:<context.slot>
- adjust <player> item_on_cursor:air
- stop
on player clicks in ShopCreatorInv:
##Prevent players from placing Shop Menu items in other slots of the menu##
- if <context.cursor_item.has_nbt[ShopMenuItem]>:
- determine passively cancelled
##Prevent players from placing Cost Adjustment items into their inventory##
- if <context.cursor_item.has_nbt[Cost]> && <context.raw_slot.is[==].to[-998]>:
- determine passively cancelled
- stop
- if <context.raw_slot> > 54:
- if <context.cursor_item.has_nbt[ShopMenuItem]>:
- determine passively cancelled
- narrate "You can't use that there!"
- stop
##Prevent a player from placing an adjusted item into their inventory##
- if <context.cursor_item.has_nbt[Cost]>:
- determine passively cancelled
- narrate "Click on ClearCost to reset an item!."
- stop
- else:
- stop
##Prevent replacing items with Shop Creator Items##
- if <context.cursor_item.has_nbt[ShopMenuItem].not> && <context.cursor_item.contains[air].not>:
- if <context.item.has_nbt[ShopMenuItem]>:
- determine passively cancelled
- stop
##Add Cost Item To Cursor##
- if <context.item.nbt[ShopMenuItem]||0> > 0 || <context.item.nbt[ShopMenuItem]||0> < 0:
- determine passively cancelled
- if <context.cursor_item.simple> == <context.item.simple>:
- if <player.item_on_cursor.quantity> == 64:
- stop
- else:
- adjust <context.cursor_item> quantity:<context.cursor_item.quantity.add[1]> save:AdjustCost
- adjust <player> item_on_cursor:<entry[AdjustCost].result>
- stop
- else:
- if <context.item.nbt[ShopMenuItem]> != Save && <context.item.nbt[ShopMenuItem]> != Clear:
- adjust <player> item_on_cursor:<context.item>
##Add/Subtract Cost##
- if <context.raw_slot> > 54 && <context.cursor_item.has_nbt[ShopMenuItem]>:
- determine passively cancelled
- stop
- if <context.item.has_nbt[Cost]> && <context.cursor_item.has_nbt[ShopMenuItem]>:
- if <context.cursor_item.nbt[ShopMenuItem]> == Clear:
- stop
- if <context.item.nbt[Cost].add[<context.cursor_item.nbt[ShopMenuItem].mul[<context.cursor_item.quantity>]>]> < 0:
- determine passively cancelled
- narrate "You cannot have a cost go below 0!"
- stop
- define adjustedcost <context.item.with[nbt=Cost/<context.item.nbt[Cost].add[<context.cursor_item.nbt[ShopMenuItem].mul[<context.cursor_item.quantity>]>]>]>
- adjust def:adjustedcost "lore:<[adjustedcost].lore.set[Click Here to Buy! Cost: $<[adjustedcost].nbt[Cost]>].at[<[adjustedcost].lore.size>]>"
- inventory set destination:<context.inventory> origin:<[adjustedcost]> slot:<context.slot>
- define CursorStack <player.item_on_cursor>
- adjust <player> item_on_cursor:air
##Clear Cost##
on player left clicks ClearCostIt in ShopCreatorInv:
- determine passively cancelled
- if <context.cursor_item.has_nbt[cost]>:
- define ClearCost <context.cursor_item>
- adjust def:ClearCost remove_nbt
- adjust def:ClearCost Lore:<context.cursor_item.lore.remove[<context.cursor_item.lore.size>]>
- adjust <player> item_on_cursor:<[ClearCost]>
- narrate "Cost removed from Item."
- stop
- adjust <player> item_on_cursor:air
on player right clicks ClearCostIt in ShopCreatorInv:
- determine passively cancelled
- adjust <player> item_on_cursor:ClearCostIt
on player clicks in ShopCreatorInv with:ClearCostIt:
- if <context.raw_slot> > 54:
- adjust <player> item_on_cursor:air
- determine cancelled
- stop
- if <context.item.has_nbt[ShopMenuItem]> || <context.item.contains[air]>:
- determine passively cancelled
- stop
- determine passively cancelled
- define adjustedcost <context.item.with[nbt=Cost/0]>
- adjust def:adjustedcost "lore:<[adjustedcost].lore.set[Click Here to Buy! Cost: $<[adjustedcost].nbt[Cost]>].at[<[adjustedcost].lore.size>]>"
- inventory set destination:<context.inventory> origin:<[adjustedcost]> slot:<context.slot>
- define CursorStack <player.item_on_cursor>
- adjust <player> item_on_cursor:air
- adjust <player> item_on_cursor:<[CursorStack]>
##Save and Exit##
on player clicks SaveShopIt in ShopCreatorInv:
- determine passively cancelled
- narrate "Shop Inventory:<player.flag[ShopCreator].get[2]> has been saved to File:<player.flag[ShopCreator].get[1]>.yml!"
- if <player.has_flag[EditShop]>:
- yaml id:<player.flag[ShopCreator].get[1]> set <player.flag[ShopCreator].get[2]>:!
- foreach <player.open_inventory.list_contents.get[1].to[44]>:
- yaml id:<player.flag[ShopCreator].get[1]> set <player.flag[ShopCreator].get[2]>:->:<[value]>
- yaml savefile:/Shops/<player.flag[ShopCreator].get[1]>.yml id:<player.flag[ShopCreator].get[1]>
- yaml unload id:<player.flag[ShopCreator].get[1]>
- flag player SellShop:!
- flag player AdjustedCost:!
- flag player EditShop:!
- flag player ShopCreator:!
- inventory close
ShopCreatorCmd:
type: command
name: createshop
usage: /createshop
description: "Use to create a list for a Denizen shop script. /createshop File:<&lc>FileName<&rc> Shop:<&lc>ShopName<&rc> | add Delete to delete a shop | add Edit to edit an existing shop."
permission: denizen.shopcreator
script:
- if <player.has_flag[EditShop]> || <player.has_flag[ShopCreator]>:
- flag player EditShop:!
- flag player ShopCreator:!
- flag player SellShop:!
##Delete Shop##
- if <context.args.contains[Delete]>:
- if <server.has_file[/Shops/<context.args.map_get[File].split_by[<&co>]>.yml].not>:
- narrate "The File: <context.args.map_get[File].split_by[<&co>]>.yml does not exist! Did you type it in correctly?"
- stop
- yaml load:/Shops/<context.args.map_get[File].split_by[<&co>]>.yml id:<context.args.map_get[File].split_by[<&co>]>
- if <yaml[<context.args.map_get[File].split_by[<&co>]>].contains[<context.args.map_get[Shop].split_by[<&co>]>].not>:
- narrate "The Shop: <context.args.map_get[Shop].split_by[<&co>]> does not exist in File: <context.args.map_get[File].split_by[<&co>]>! Did you type it in correctly?"
- stop
- yaml id:<context.args.map_get[File].split_by[<&co>]> set <context.args.map_get[Shop].split_by[<&co>]>:!
- yaml savefile:/Shops/<context.args.map_get[File].split_by[<&co>]>.yml id:<context.args.map_get[File].split_by[<&co>]>
- narrate "The Shop: <context.args.map_get[Shop].split_by[<&co>]> in File: <context.args.map_get[File].split_by[<&co>]> has been deleted!"
- stop
##Edit Shop##
- if <context.args.contains[Edit]>:
- if <player.has_flag[AdjustedCost]>:
- flag player AdjustedCost:!
- if <server.has_file[/Shops/<context.args.map_get[File].split_by[<&co>]>.yml].not>:
- narrate "The File: <context.args.map_get[File].split_by[<&co>]>.yml does not exist! Did you type it in correctly?"
- stop
- yaml load:/Shops/<context.args.map_get[File].split_by[<&co>]>.yml id:<context.args.map_get[File].split_by[<&co>]>
- if <yaml[<context.args.map_get[File].split_by[<&co>]>].contains[<context.args.map_get[Shop].split_by[<&co>]>].not>:
- narrate "The Shop: <context.args.map_get[Shop].split_by[<&co>]> does not exist in File: <context.args.map_get[File].split_by[<&co>]>! Did you type it in correctly?"
- stop
- flag player EditShop:|:<context.args.map_get[File].split_by[<&co>]>|<context.args.map_get[Shop].split_by[<&co>]>
- flag player ShopCreator:|:<context.args.map_get[File].split_by[<&co>]>|<context.args.map_get[Shop].split_by[<&co>]>
- inventory open d:ShopCreatorInv
- stop
##Create Shop##
- if <server.has_file[/Shops/<context.args.map_get[File].split_by[<&co>]>.yml].not>:
- yaml create id:<context.args.map_get[File].split_by[<&co>]>
- yaml savefile:/Shops/<context.args.map_get[File].split_by[<&co>]>.yml id:<context.args.map_get[File].split_by[<&co>]>
- yaml load:/Shops/<context.args.map_get[File].split_by[<&co>]>.yml id:<context.args.map_get[File].split_by[<&co>]>
- else:
- yaml load:/Shops/<context.args.map_get[File].split_by[<&co>]>.yml id:<context.args.map_get[File].split_by[<&co>]>
- if <yaml[<context.args.map_get[File].split_by[<&co>]>].contains[<context.args.map_get[Shop].split_by[<&co>]>]>:
- yaml unload id:<context.args.map_get[File].split_by[<&co>]>
- narrate "That shop already exists! If you wish to Edit or Delete a Shop, add those arguments when using the /createshop command."
- stop
- flag player ShopCreator:|:<context.args.map_get[File].split_by[<&co>]>|<context.args.map_get[Shop].split_by[<&co>]>
- inventory open d:ShopCreatorInv
- if <context.args.contains[SellShop]>:
- flag player SellShop
##Shop Creator Items##
SaveShopIt:
type: item
display name: Save Shop
material: writable_book[nbt=ShopMenuItem/Save]
lore:
- "Click here to save this shop inventory."
ClearCostIt:
type: item
display name: Clear Cursor
material: barrier[nbt=ShopMenuItem/Clear]
lore:
- "Clicking here with a Cost Editting item"
- "will clear it from your cursor."
- "Right click to pick up this item."
- "Click an item to adjust its cost to $0."
- "With a cost adjusted item on your cursor"
- "click here to reset the item entirely."
CostPlus1It:
type: item
display name: Add $1
material: stone[nbt=ShopMenuItem/1]
lore:
- "Click here to add $1 to the price"
- "of an item. With this item in hand"
- "click on an item. It will add $1"
- "for each item in the held stack."
CostPlus10It:
type: item
display name: Add $10
material: iron_block[nbt=ShopMenuItem/10]
lore:
- "Click here to add $10 to the price"
- "of an item. With this item in hand"
- "click on an item. It will add $10"
- "for each item in the held stack."
CostPlus100It:
type: item
display name: Add $100
material: gold_block[nbt=ShopMenuItem/100]
lore:
- "Click here to add $100 to the price"
- "of an item. With this item in hand"
- "click on an item. It will add $100"
- "for each item in the held stack."
CostPlus1000It:
type: item
display name: Add $1000
material: diamond_block[nbt=ShopMenuItem/1000]
lore:
- "Click here to add $1000 to the price"
- "of an item. With this item in hand"
- "click on an item. It will add $1000"
- "for each item in the held stack."
CostMinus1It:
type: item
display name: Subtract $1
material: coal_ore[nbt=ShopMenuItem/-1]
lore:
- "Click here to subtract $1 to the price"
- "of an item. With this item in hand"
- "click on an item. It will subtract $1"
- "for each item in the held stack."
CostMinus10It:
type: item
display name: Subtract $10
material: iron_ore[nbt=ShopMenuItem/-10]
lore:
- "Click here to subtract $10 to the price"
- "of an item. With this item in hand"
- "click on an item. It will subtract $10"
- "for each item in the held stack."
CostMinus100It:
type: item
display name: Subtract $100
material: gold_ore[nbt=ShopMenuItem/-100]
lore:
- "Click here to subtract $100 to the price"
- "of an item. With this item in hand"
- "click on an item. It will subtract $100"
- "for each item in the held stack."
CostMinus1000It:
type: item
display name: Subtract $1000
material: diamond_ore[nbt=ShopMenuItem/-1000]
lore:
- "Click here to subtract $1000 to the price"
- "of an item. With this item in hand"
- "click on an item. It will subtract $1000"
- "for each item in the held stack."
##Player Shop Creation System##
PlayerShopHandler:
type: world
events:
on player places PlayerShopIt:
- flag player ShopOwner:<context.location>
- flag player ShopCreator:|:PlayerShops|<player.uuid>|<context.location>
- inventory open d:ShopCreatorInv
on player closes ShopCreatorInv:
- foreach <player.inventory.list_contents>:
- if <[value].contains[ClearCostIt]> || <[value].contains[CostMinus1000It]> || <[value].contains[CostMinus100It]> || <[value].contains[CostMinus10It]> || <[value].contains[CostMinus1It]> || <[value].contains[CostPlus1000It]> || <[value].contains[CostPlus100It]> || <[value].contains[CostPlus10It]> || <[value].contains[CostPlus1It]>:
- take <[value]> quantity:<[value].quantity>
##Player Shop Creation Item##
PlayerShopIt:
type: item
material: sign
display name: Shop Post
lore:
- "Congratulations! You're the proud owner"
- "of a Personal Shop Post. Simply place"
- "this sign anywhere you're allowed to"
- "setup your own Personal Shop! Others will"
- "be able to purchase items you place there!"
- "Should you need to restock, simply right"
- "click this sign!"
##Example Shop##
GenericShopInv:
type: inventory
inventory: CHEST
title: Shop Name Here
size: 45
slots:
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
Procedural Items:
- determine <yaml[FileName].read[ShopName]>
NPCAssignment:
type: assignment
debug: true
actions:
on assignment:
- trigger name:click state:true
interact scripts:
- NPCInteract
NPCInteract:
type: interact
debug: true
steps:
1:
click trigger:
script:
- narrate "Greeting Here"
- yaml load:/Shops/FileName.yml id:ShopName
- wait 2
- inventory open d:GenericShopInv
- yaml unload id:ShopName
ShopMenuHandler:
type: world
events:
on player drags in GenericShopInv:
- determine cancelled
on player clicks in GenericShopInv:
- determine passively cancelled
- if <context.item.has_nbt[Cost]>:
- if <player.money.is[MORE].to[<context.item.nbt[Cost]>]>:
- if <player.inventory.empty_slots> == 0:
- narrate "Your inventory has no space!"
- stop
- take money quantity:<context.item.nbt[Cost]>
- define Item <context.item>
- adjust def:Item <context.item> remove_nbt
- adjust def:Item Lore:<context.item.lore.remove[<context.item.lore.size>]>
- give <[Item]>
- narrate "$<context.item.nbt[Cost]> has been removed from your wallet."
- flag player TotalSpent:+:<context.item.nbt[Cost]>
- stop
- else:
- narrate "You don't have enough money! Cost: $<context.item.nbt[Cost]> Your Money: $<player.money>"
- stop