Paste #7179: Untitled Paste

Date: 2014/07/19 22:01:27 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512


Storekeeper:
  type: assignment
  debug: false

  default constants:
    store open hour: 5
    store close hour: 18
    store greetings: li@Welcome to my store!
      |Feel free to look around!
      |Just give me a click if you need something!

  actions:

    # Just some setup of the triggers
    on remove:
    - flag server store:<-:<npc.flag[store]>
    on assignment:
    - trigger name:proximity toggle:true radius:3
    - trigger name:click toggle:true
    - trigger name:chat toggle:true
    - trigger name:damage toggle:true
    on enter proximity:
    - foreach <npc.flag[store].as_cuboid.list_entities> {
      - if !<def[value].has_framed_item> {
        - adjust %value% framed:<npc.flag[storeitems].get[<npc.flag[storeitemlocations].find[<def[value].location>]>]>
        }
      }
    on move proximity:
    - if !<player.flag[greeted]> && <npc.can_see[<player>]> {
      - narrate "<el@val[<npc.constant[store greetings]>].as_list.random>"
      - flag player greeted
      }
    on exit proximity:
    - flag player greeted:!
    on damage:
    - if '!<player.inventory.contains[i@shopping bag]>' && '!<player.inventory.contains[i@item_bag]>' && '!<player.inventory.contains[i@selling bag]>' {
        - animate <npc> arm_swing
        - narrate 'Here, have a complimentary shopping bag!'
        - give <player> 'i@shopping bag'
      } else if <player.item_in_hand> == 'i@shopping bag' {
        - define total_price 0 
        - foreach <in@<player.name>_shopping_bag.list_contents> { 
          - adjust %value% quantity:1 save:item2
          - if <server.flag[<<entry[item2].result>.full.escaped>]> == null { 
            - flag server <<entry[item2].result>.full.escaped>:1.00 
            } 
          - adjust %value% quantity:1 save:item
          - define price <yaml[prices].read[prices.<<entry[item].result>.full.escaped>].mul[2].mul[<server.flag[<entry[item].result>]>].mul[<%value%.qty>]> 
          - define total_price <el@val[%total_price%].add[%price%]> 
          } 
        - narrate "<green>Ready to check out? Just click me with your bag!"
        - narrate "<green>your total price is <red>%total_price%"
      } else if <player.item_in_hand> == 'i@selling bag' {
        - define total_price 0 
        - foreach <in@<player.name>_selling_bag.list_contents> { 
          - adjust %value% quantity:1 save:item
          - define price <yaml[prices].read[prices.<entry[item].result.full.escaped>].mul[<%value%.qty>].as_int> 
          - define total_price <el@val[%total_price%].add[%price%]> 
          } 
        - narrate "<green>Ready to sell items? Just right click me with your bag!"
        - narrate "<green>your total price is <red>%total_price%"
      }

    on chat:
    - if <context.message> == sell {
      - animate <npc> arm_swing
      - narrate 'Here is your item selling bag!'
      - give <player> 'i@selling bag' 
    - if <context.message> == set && <player> == <npc.owner> {
      - narrate "<&b>your store is now open for business!"
      - flag npc storeitems:!
      - foreach <npc.flag[store].as_cuboid.list_entities> {
        - if <def[value].entity_type> == item_frame {
          - flag npc storeitems:->:<def[value].framed_item>
          - flag npc storeitemlocations:->:<def[value].location>
          }
        }
      - determine cancelled
      }
    on click:
    - if <player.item_in_hand> == "i@shopping bag" { 
      - if <in@<player.name>_shopping_bag.qty> == 0 { 
        - narrate "your shopping bag is empty!" 
        } else { 
        - flag player delay duration:3s
        - chat "ok let's total these items up for you then!" 
        - define total_price 0 
        - foreach <in@<player.name>_shopping_bag.list_contents> { 
          - adjust %value% quantity:1 save:item
          - if <server.flag[<entry[item].result.full.escaped>]> == null { 
            - flag server %value%:1.00 
            } 
          - define price <yaml[prices].read[prices.<entry[item].result.full.escaped>].mul[2].mul[<server.flag[%value%]>].mul[<%value%.qty>].as_int> 
          - define total_price <el@val[%total_price%].add[%price%]> 
          } 
        - if <player.money> < %total_price% { 
          - narrate "YOU NEED MONEYS D=" 
          - queue clear 
          } 
        - flag player bagnumber:+:1
        - note "in@player bag" "as:<player.name> <player.flag[bagnumber].as_int>_item_bag"
        - take money qty:%total_price% 
        - run itemgiver delay:1s
        - take 'i@shopping bag'
        - narrate "<green>The shopkeeper takes <red>%total_price% coins"
        - narrate "<gold>You are all checked out. have a great day!"
        - narrate "<red>Do not open your item bag until you are ready to take all the items out"
        - foreach <in@<player.name>_shopping_bag.list_contents> { 
          - adjust %value% quantity:1 save:item
          - flag server <entry[item].result.full.escaped>adjust:+:<def[value].qty>
          - run script:price_adjuster def:<entry[item].result.full.escaped>
          }
        }          
      } else if <player.item_in_hand> == "i@selling bag" { 
      - flag player delay duration:3s
      - if <in@<player.name>_selling_bag.qty> == 0 { 
        - narrate "your selling bag is empty!" 
        } else if <in@<player.name>_selling_bag.contains['i@shopping bag']> {
        - chat "i am sorry but i do not buy back my shopping bags."
        } else {
        - chat "ok let's total these items up for you then!" 
        - define total_price 0 
        - foreach <in@<player.name>_selling_bag.list_contents> { 
          - adjust %value% quantity:1 save:item
          - define price <yaml[prices].read[prices.<entry[item].result.full.escaped>].mul[<%value%.qty>].as_int> 
          - define total_price <el@val[%total_price%].add[%price%]> 
          } 
        - note 'in@player bag' as:<player.name>_selling_bag
        - give money qty:%total_price% 
        - take 'i@selling bag'
        - narrate "<green>The shopkeeper gives you <red>%total_price% coins"
        - foreach <in@<player.name>_shopping_bag.list_contents> { 
          - adjust %value% quantity:1 save:item
          - flag server <entry[item].result.full.escaped>adjust:-:<def[value].qty>
          - run script:price_adjuster def:<entry[item].result.full.escaped>
          } 
        - queue clear
        }
      } else {
      - if in@<player.inventory> contains 'i@shopping bag' || in@<player.inventory> contains 'i@selling bag' {
      } else {
      - chat "Please visit http://youtu.be/2f3Dk4cPCXs for a short tutorial of how to use our stores."
      }
itemgiver:
  type: task
  debug: false
  script:
  - inventory add o:in@<player.name>_shopping_bag 'd:in@<player.name> <player.flag[bagnumber].as_int>_item_bag'
  - ^adjust 'i@item_bag' "lore:<player.name> <player.flag[bagnumber].as_int>" save:playersbag
  - give <entry[playersbag].result.full>
Item Frame Shop:
  type: world
  debug: false
  events:
    on price command:
    - if <player.is_op> {
      - adjust <player.item_in_hand.full> quantity:1 save:item3
      - if !<yaml[prices].contains[prices.<entry[item3].result.full.escaped>]> {
        - flag player setpriceserver:<entry[item3].result.full.escaped>
        - narrate "<dark_purple>what is the base price you want for that item?"
        }
        else {
        - narrate "<dark_purple>That item already has a current price of <green><yaml[prices].read[prices.<entry[item3].result.full.escaped>]>"
        - narrate "<dark_purple>To adjust that items price use the /adjust_price command"
        - determine cancelled
        }
      }
    on adjust_price command:
    - adjust <player.item_in_hand.full> quantity:1 save:item3
    - yaml id:prices set prices.<entry[item3].result.full.escaped>:!
    - flag player setpriceserver:<entry[item3].result.full.escaped>
    - narrate "<dark_purple>what is the base price you want for that item?"
    - determine fulfilled
    on player chats:
    - if <player.is_op> && !<player.flag[setpriceserver]> == null {
      - yaml id:prices set prices.<player.flag[setpriceserver]>:<context.message>
      - yaml savefile:prices.yml id:prices
      - narrate "<dark_purple><<player.flag[setpriceserver].unescaped>.display> price is now set to <green><yaml[prices].read[prices.<player.flag[setpriceserver]>]>"
      - flag setpriceserver:!
      - determine cancelled
      }
    on store_setup command:
    - give <player> i@storekeeperegg
    - determine fulfilled
    on player clicks with i@storekeeperegg:
    - run storelocationstick1 as:<player> delay:1t
    - create player storekeeper <player.location.cursor_on.add[0.5,1,0.5]>
    - execute as_op "npc select"
    - narrate "<&d>please select the bottom and top corners of your cuboid then drop the selector"
    - take i@storekeeperegg
    - lookclose <player.selected_npc> state:true
    on item_frame damaged by entity_explosion:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.entity.location>]> {
        - determine cancelled
        }
      }
    on item_frame damaged by block_explosion:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.entity.location>]> {
        - determine cancelled
        }
      }
    on player right clicks with i@storelocationstick:
    - run storelocationstick2 def:<context.location> as:<player> delay:1t
    - flag player location1:<context.location>
    - narrate "<red>Cuboid location 1 selected"
    on player left clicks with i@storelocationstick:
    - flag player location2:<context.location>
    - run storelocationstick2 def:<context.location> as:<player> delay:1t
    - narrate "<red>Cuboid location 2 selected"
    - determine cancelled
    on player drops i@storelocationstick:
    - execute as_op "npc owner <player.name> --id <player.selected_npc.id>"
    - assignment set npc:<player.selected_npc> script:storekeeper
    - flag global store:->:cu@<player.flag[location1]>|<player.flag[location2]>
    - flag <player.selected_npc> store:cu@<player.flag[location1]>|<player.flag[location2]>
    - flag player location1:!
    - flag player location2:!
    - run storeselectorremover delay:1t
    - narrate "<red>tell the npc <green>'SET' <red>to set the items in the frame"
    - determine cancelled
    on player right clicks e@item_frame:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.location>]> {
        - if <player.is_sneaking> && <player.is_op>
          queue clear
        - if <player.item_in_hand.scriptname> == 'shopping bag' {
          - if <in@<player.name>_shopping_bag.stacks> >= 18 {
            - narrate "<red>Your shopping bag is full!"
            } else {
            - inventory add o:<c.entity.framed_item> d:in@<player.name>_shopping_bag
            - if <c.entity.framed_item.display> != null 
              narrate "You add a <c.entity.framed_item.display> to your shopping bag."
              else 
              narrate "You add <c.entity.framed_item.material.name.replace[_].with[ ]> to your shopping bag."
              - playsound <player> sound:DIG_GRASS
              }
          }
        - determine cancelled
        }
      }


    on player places block:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.location>]> {
        - if <player.is_sneaking> && <player.is_op> {
          - queue clear
          } else {
          - determine cancelled
          }
        }
      }
    on player breaks e@item_frame:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.location>]> {
        - if <player.is_sneaking> && <player.is_op> {
          - queue clear
          } else {
          - if <c.hanging.framed_item.display> != null 
            narrate "It's a <c.hanging.framed_item.display>."
            else 
            narrate "It's <c.hanging.framed_item.material.formatted>."
          - narrate "Right click it with your shopping bag to add it to your transaction."
          - determine cancelled
          }
        }
      }

    on player breaks block:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.location>]> {
        - if <player.is_sneaking> && <player.is_op> {
          - queue clear
          } else {
          - determine cancelled
          }
        - if <player.flag[storekeeper_warned]> == null {
            - narrate '<green>[storekeeper] -> You<&co> <red>Hey! <white>You break it, you buy it! Be careful!'
            - flag <player> storekeeper_warned duration:5s
          } 
        }
      }

    on entity damages e@item_frame:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.entity.location>]> {
        - if <player.is_sneaking> && <player.is_op> {
          - queue clear
          } else {
          - foreach <global.flag[store].escape_contents> {
            - if <def[value].unescaped.as_cuboid.is_within[<context.entity.location>]> {
              - if <server.flag[<context.entity.framed_item.full.escaped>]> == null {
                - flag server <context.entity.framed_item.full.escaped>:1.00
                } else {
                - define price <yaml[prices].read[prices.<context.entity.framed_item.full.escaped>].mul[2].mul[<server.flag[<context.entity.framed_item.material.id>]>].as_int>
                - narrate "%price%"
                - determine cancelled
                }
              }
            }
          }
        }
      }
    on player right clicks entity with i@shopping bag:
    - if <context.entity.as_npc> == <npc> {
      - flag player shopkeeper:<npc>
      }
    on player places item_frame:
    - foreach <global.flag[store].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.location>]> {
        - if <player.is_sneaking> && <player.is_op> {
          - queue clear
          } else {
          - determine cancelled
          }
        }
      }
    on player right clicks with i@shopping bag:  
    - define is_shopping false  
    - foreach <global.flag[store].escape_contents> {  
      - if <player.location.is_within[<def[value].unescaped>]> {  
        - define is_shopping true  
        - foreach stop  
        }  
      }  
    - if <player.inventory.qty[i@shopping bag]> > 1 {
      - take 'i@shopping bag' qty:36
      - note 'in@player bag' as:<player.name>_shopping_bag
      } else if !%is_shopping% {  
      - inventory clear d:in@<player.name>_shopping_bag  
      - take 'i@shopping bag'  
      - narrate 'You are not shopping right now!'  
      }  
      else if <in@<player.name>_shopping_bag||null> == null && %is_shopping% {  
      - note 'in@player bag' as:<player.name>_shopping_bag  
      }   
      else %is_shopping% {  
      - narrate 'You take a look in your shopping bag...'  
      - inventory open d:in@<player.name>_shopping_bag  
      }   
    - determine cancelled  


    on player right clicks with i@selling bag:
    - define is_shopping false  
    - foreach <global.flag[store].escape_contents> {  
      - if <player.location.is_within[<def[value].unescaped>]> {  
        - define is_shopping true  
        - foreach stop  
        }  
      }  
    - if !%is_shopping% {  
      - inventory clear d:in@<player.name>_selling_bag
      - narrate 'You are not in a shop right now!'
      - take 'i@selling bag'
      - determine cancelled
      }  
      else if <in@<player.name>_shopping_bag||null> == null && %is_shopping% {  
      - note 'in@player bag' as:<player.name>_selling_bag
      - inventory open d:in@<player.name>_selling_bag
      - determine cancelled
      }   
      else %is_shopping% {  
      - inventory open d:in@<player.name>_selling_bag
      - determine cancelled
      }   
    - determine cancelled  
    on player right clicks with i@item_bag:
    - foreach <global.flag[playerstore].escape_contents> {
      - if <def[value].unescaped.as_cuboid.is_within[<context.location>]> && <player.location.facing[<player.flag[shopkeeper]>]> {
        } else {
        - narrate '<aqua>You take a look in your shopping bag...'
        - inventory open "d:in@<context.item.lore.as_string.strip_color>_item_bag"
        }
      - determine cancelled   
      }
    on player drops i@shopping bag:
    - narrate 'You ditch your shopping bag.'
    - run bagremovertask delay:1t
    - determine cancelled
    on player drops i@selling bag:
    - narrate 'You ditch your selling bag.'
    - run bagremovertask1 delay:1t
    - determine cancelled
    on player clicks in inventory:
    - if <c.inventory> == 'in@<player.name>_shopping_bag' && <player.item_in_hand> == 'i@shopping bag' {
      - determine passively cancelled
      - inventory update d:<player.inventory>
      }
    - if <c.inventory> == 'in@<player.name>_shopping_bag' && <player.item_in_hand> == 'i@shopping bag' {
      - if <context.is_shift_click> {
        - determine passively cancelled
        - inventory update d:<player.inventory>
        }
      }
    - if <c.inventory> == 'in@<player.name>_selling_bag' {
      - if "li@i@shopping bag|i@selling bag|i@item_bag" contains <context.item> {
        - inventory update
        - determine cancelled
        }
      }
    on player picks up i@shopping bag:
    - if '<player.inventory.contains[i@shopping bag]>' {
        - determine cancelled
      } else {
        - note 'in@player bag' as:<player.name>_shopping_bag
        - narrate "You pick up a brand new shopping bag. It's empty!"
      }
    on player closes inventory:
    - if <player.item_in_hand> == 'i@item_bag' {
      - if <context.inventory> == <player.inventory> {
      } else {
      - foreach <in@<player.name>_shopping_bag.list_contents> {
        - drop %value% <player.location>
        }
      - take i@item_bag
      }

    on server start:
    - yaml load:prices.yml id:prices


'player bag':
  type: inventory
  size: 18

  # It's empty!

'item bag':
  type: inventory
  size: 18

  # It's empty!

'selling bag':
  type: inventory
  size: 18

  # It's empty!


'shopping bag':
  type: item

  material: boat
  display name: shopping bag
  lore:
  - Give this to a shopkeeper to check out.
  - Right click to see the contents.
'item_bag':
  type: item

  material: boat
  display name: item bag
  lore:
  - <red>this bag contains the items you bought
'selling bag':
  type: item

  material: boat
  display name: selling bag
  lore:
  - <green>Right click the shopkeeper with this bag to sell the items in it.
  - <green>Left click the shopkeeper with this bag to see what the 
  - <green>total price of your items will be.

price_adjuster:
  type: task
  debug: false
  script:
  - if <server.flag[%1%adjust]> == 100 {
    - flag server %1%:+:0.01
    - flag server %1%adjust:1
    }
  - if <server.flag[<%1%>adjust]> == 0 {
    - flag server %1%:-:0.01
    - flag server %1%adjust:1
    }
storelocationstick:
  type: item
  material: m@iron_hoe
  display name: store_selector_tool
storeselectorremover:
  type: task
  debug: false
  script:
  - take i@storelocationstick
bagremovertask:
  type: task
  debug: false
  script:
  - take 'i@shopping bag'
bagremovertask1:
  type: task
  debug: false
  script:
  - take 'i@selling bag'
storekeeperegg:
  type: item
  material: m@monster_egg
  display name: shop_keeper
storelocationstick1:
  type: task
  debug: false
  script:
  - give <player> "i@storelocationstick"
storelocationstick2:
  type: task
  script:
  - showfake m@red_wool %1% to:<player> d:30s