-market_assignment:
+/
- type: assignment
- debug: false
- actions:
- on click:
- - if <player.is_sneaking.not> {
- - inventory open d:in@market_interface
- } else {
- - run market_get_offers instantly
- }
-market_event_handlers:
- type: world
- debug: false
- events:
- on player joins:
- - wait 7s
- - if <player.has_flag[give_market_update]> {
- - flag give_market_update:!
- - narrate "<&2>One of your global market offers updated."
- - playsound sound:level_up %value% pitch:0.6
- }
- on player clicks in market_offer_listing:
- - determine cancelled passively
- - if <context.item||i@air> == i@air queue clear
- - foreach <li@11|13|15|17|29|31|33|35.reverse> {
- - if !<yaml[MARKETSAVES].contains[live_offers.<player>.%value%]||false> {
- - define slot %value%
- }
- }
- - playsound sound:click pitch:0.9 <player>
- - if <def[slot].exists.not> {
- - narrate "<&c>You have no offer slots available."
- - queue clear
- }
- - narrate "<&2>Building your offer."
- - flag market_slot_used:%slot%
- - define path <player.flag[market_auto_offer_data_<context.raw_slot>]||none>
- - if <yaml[MARKETSAVES].read[live_offers.%path%.type]||none> == sell {
- - run market_set_offer_item_buying instantly def:<yaml[MARKETSAVES].read[live_offers.%path%.item]||none>
- - run market_set_offer_price_buying instantly def:<yaml[MARKETSAVES].read[live_offers.%path%.price]||0>
- - run market_set_offer_quantity_buying instantly def:<yaml[MARKETSAVES].read[live_offers.%path%.quantity].as_int.sub[<yaml[MARKETSAVES].read[live_offers.%path%.progress].as_int>].as_int||0>
- } else {
- - adjust <yaml[MARKETSAVES].read[live_offers.%path%.item]||none> quantity:1 save:item
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.item:<entry[item].result>
- - run market_set_offer_item_selling instantly def:<yaml[MARKETSAVES].read[live_offers.%path%.item]||none>
- - run market_set_offer_price_selling instantly def:<yaml[MARKETSAVES].read[live_offers.%path%.price]||0>
- }
- on player clicks in market_interface:
- - if <context.raw_slot> < 46 {
- - determine cancelled passively
- }
- - wait 1t
- - if li@11|13|15|17|29|31|33|35 contains <context.raw_slot> {
- - playsound sound:click pitch:0.9 <player>
- - if <yaml[MARKETSAVES].contains[live_offers.<player>.<context.raw_slot>]||false> {
- - if <context.action> == move_to_other_inventory {
- - inject locally path:market_abort
- } else {
- - inject locally path:market_collect
- }
- } else {
- - if <context.cursor_item||i@air> == i@air {
- - inject locally path:make_buy_offer
- } else {
- - inject locally path:make_sell_offer
- }
- }
- }
- on player clicks in market_selling_interface:
- - if <context.raw_slot> < 10 {
- - determine cancelled passively
- }
- - playsound sound:click pitch:0.9 <player>
- - if <context.raw_slot> == 9 {
- - inject locally path:cancel_offer
- } else if <context.raw_slot> == 1 {
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.type:sell
- - inject locally path:confirm_offer
- } else if <context.raw_slot> == 7 {
- - inject locally path:change_selling_offer_quantity
- } else if <context.raw_slot> == 3 {
- - inject locally path:change_selling_offer_price
- }
- on player clicks in market_buying_interface:
- - if <context.raw_slot> < 10 {
- - determine cancelled passively
- }
- - playsound sound:click pitch:0.9 <player>
- - if <context.raw_slot> == 9 {
- - inject locally path:cancel_offer
- } else if <context.raw_slot> == 1 {
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.type:buy
- - inject locally path:confirm_offer
- } else if <context.raw_slot> == 7 {
- - inject locally path:change_buying_offer_quantity
- } else if <context.raw_slot> == 5 {
- - inject locally path:change_buying_offer_item
- } else if <context.raw_slot> == 3 {
- - inject locally path:change_buying_offer_price
- }
- on player drops item:
- - if <player.has_flag[market_sell_item_drop]> determine cancelled
- market_collect:
- - if <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.type]> == buy {
- - if <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress]||0> > <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0> {
- - give <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.item]||0> qty:<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress].sub[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0>]||0>
- - narrate "<&A>You collected <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress].sub[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0>].as_int||0> of <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.item].display||<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.item].as_item.formatted||0>>."
- - yaml id:MARKETSAVES set live_offers.<player>.<context.raw_slot>.collected:<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress]||0>
- } else {
- - narrate "<&c>Nothing left to collect."
- }
- } else {
- - if <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress]||0> > <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0> {
- - give money qty:<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress].sub[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0>].mul[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.price]||0>].add[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.excess]||0>]||0>
- - narrate "<&A>You collected <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress].sub[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0>].mul[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.price]||0>].add[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.excess]||0>].as_int||0> gold coins."
- - yaml id:MARKETSAVES set live_offers.<player>.<context.raw_slot>.collected:<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress]||0>
- - yaml id:MARKETSAVES set live_offers.<player>.<context.raw_slot>.excess:0
- } else {
- - narrate "<&c>Nothing left to collect."
- }
- }
- - if <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.collected]||0> >= <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.quantity]||0> {
- - yaml id:MARKETSAVES set live_offers.<player>.<context.raw_slot>:!
- }
- - flag <player> market_sell_item_drop duration:5t
- - inventory open d:in@market_interface
- market_abort:
- - inject locally path:market_collect
- - if <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.type]> == sell {
- - give <yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.item]||0> qty:<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.quantity].sub[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress]||0>]||0>
- - yaml id:MARKETSAVES set live_offers.<player>.<context.raw_slot>:!
- } else {
- - give money qty:<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.quantity].mul[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.price]||0>].sub[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.progress].mul[<yaml[MARKETSAVES].read[live_offers.<player>.<context.raw_slot>.price]||0>]>]||0>
- - yaml id:MARKETSAVES set live_offers.<player>.<context.raw_slot>:!
- }
- - narrate "<&c>You aborted the rest of your offer."
- - flag <player> market_sell_item_drop duration:5t
- - inventory open d:in@market_interface
- confirm_offer:
- - if <yaml[MARKETSAVES].contains[offer_constructor.<player>.<player.flag[market_slot_used]>.item].not> {
- - narrate "<&c>Specify a valid item!"
- - queue clear
- }
- - if <yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.type]> == sell {
- - if <player.inventory.contains[<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.item]>].quantity[<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]||1>]> {
- - take <yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.item]> qty:<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]||1>
- } else {
- - narrate "<&c>You don't have this many items!"
- - queue clear
- }
- } else {
- - if <player.money> >= <yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.price].mul[<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]>]||0> {
- - take money qty:<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.price].mul[<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]>]||0>
- } else {
- - narrate "<&c>You don't have this much money!"
- - queue clear
- }
- }
- - flag <player> market_sell_item_drop duration:5t
- - inventory open d:in@market_interface
- - narrate "<&2>Offer confirmed."
- - if !<yaml[MARKETSAVES].contains[offer_constructor.<player>.<player.flag[market_slot_used]>.price]> {
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.price:1
- }
- - if !<yaml[MARKETSAVES].contains[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]> {
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.quantity:1
- }
- - foreach <yaml[MARKETSAVES].list_keys[offer_constructor.<player>.<player.flag[market_slot_used]>]> {
- - yaml id:MARKETSAVES set live_offers.<player>.<player.flag[market_slot_used]>.%value%:<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.%value%]>
- }
- - inventory open d:in@market_interface
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>:!
- - run market_offer_completer delay:2s
- cancel_offer:
- - flag <player> market_sell_item_drop duration:5t
- - inventory open d:in@market_interface
- - narrate "<&c>Offer cancelled."
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>:!
- make_buy_offer:
- - narrate "<&a>Making a buy offer."
- - flag <player> market_sell_item_drop duration:5t
- - flag <player> market_slot_used:<context.raw_slot>
- - inventory open d:in@market_buying_interface
- make_sell_offer:
- - define item <context.cursor_item>
- - if <def[item].durability||0> != 0 {
- - narrate "<&c>You can't sell damaged goods!"
- - flag <player> market_sell_item_drop duration:5t
- - inventory open d:in@market_interface
- - queue clear
- }
- - adjust %item% quantity:1 save:item
- - narrate "<&a>Making a sell offer."
- - flag <player> market_slot_used:<context.raw_slot>
- - yaml id:MARKETSAVES set offer_constructor.<player>.<context.raw_slot>.item:<entry[item].result>
- - yaml id:MARKETSAVES set offer_constructor.<player>.<context.raw_slot>.quantity:<player.inventory.quantity[<entry[item].result>].add[<context.cursor_item.quantity>].as_int||1>
- - if <yaml[MARKETSAVES].contains[statistics.averages.<entry[item].result>]> {
- - define average <yaml[MARKETSAVES].read[statistics.averages.<entry[item].result>.value].div[<yaml[MARKETSAVES].read[statistics.averages.<entry[item].result>.amount]>].as_int||1>
- - yaml id:MARKETSAVES set offer_constructor.<player>.<context.raw_slot>.price:<def[average].as_int>
- }
- - flag <player> market_sell_item_drop duration:5t
- - inventory open d:in@market_selling_interface
- change_selling_offer_quantity:
- - narrate "<&a>Write down your new quantity."
- - run open_sign_input def:market_set_offer_quantity_selling instantly
- change_selling_offer_price:
- - narrate "<&a>Write down your new price."
- - run open_sign_input def:market_set_offer_price_selling instantly
- change_buying_offer_quantity:
- - narrate "<&a>Write down your new quantity."
- - run open_sign_input def:market_set_offer_quantity_buying instantly
- change_buying_offer_price:
- - narrate "<&a>Write down your new price."
- - run open_sign_input def:market_set_offer_price_buying instantly
- change_buying_offer_item:
- - narrate "<&a>Write down your item of choice."
- - run open_sign_input def:market_set_offer_item_buying instantly
-#
-#
-# SIGN INPUT RETURNS
-#
-market_set_offer_quantity_selling:
- type: task
- debug: false
- speed: 1t
- script:
- - if <def[1].is[matches].to[number].not> {
- - narrate "<&c>Please specify a valid quantity."
- - queue clear
- }
- - narrate "<&a>Set new quantity to %1%"
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.quantity:%1%
- - inventory open d:in@market_selling_interface
-market_set_offer_price_selling:
- type: task
- debug: false
- speed: 1t
- script:
- - if <def[1].is[matches].to[number].not> {
- - narrate "<&c>Please specify a valid price."
- - queue clear
- }
- - narrate "<&a>Set new price to %1%"
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.price:%1%
- - inventory open d:in@market_selling_interface
-market_set_offer_quantity_buying:
- type: task
- debug: false
- speed: 1t
- script:
- - if <def[1].is[matches].to[number].not> {
- - narrate "<&c>Please specify a valid quantity."
- - queue clear
- }
- - narrate "<&a>Set new quantity to %1%"
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.quantity:%1%
- - inventory open d:in@market_buying_interface
-market_set_offer_price_buying:
- type: task
- debug: false
- speed: 1t
- script:
- - if <def[1].is[matches].to[number].not> {
- - narrate "<&c>Please specify a valid price."
- - queue clear
- }
- - narrate "<&a>Set new price to %1%"
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.price:%1%
- - inventory open d:in@market_buying_interface
-market_set_offer_item_buying:
- type: task
- debug: false
- speed: 1t
- script:
- - if <def[1].as_item||none> == none {
- - narrate "<&c>Please specify a valid item."
- - queue clear
- }
- - if <yaml[MARKETSAVES].contains[statistics.averages.<def[1].as_item>]> {
- - define average <yaml[MARKETSAVES].read[statistics.averages.<def[1].as_item>.value].div[<yaml[MARKETSAVES].read[statistics.averages.<def[1].as_item>.amount]>].as_int||1>
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.price:<def[average].as_int>
- } else {
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.price:1
- }
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.quantity:1
- - narrate "<&a>Set new item to %1%"
- - yaml id:MARKETSAVES set offer_constructor.<player>.<player.flag[market_slot_used]>.item:<def[1].as_item>
- - inventory open d:in@market_buying_interface
-#
-#
-#
-# MAIN INTERFACE
-#
-market_interface:
- debug: false
- type: inventory
- inventory: CHEST
- title: <&2>Your Offers
- size: 45
- definitions:
- div: i@black_stained_glass_pane[display_name=<&0><&sp>]
- slots:
- - "[div] [div] [div] [div] [div] [div] [div] [div] [div]"
- - "[div] [<proc[market_interface_slot].context[11]>] [div] [<proc[market_interface_slot].context[13]>] [div] [<proc[market_interface_slot].context[15]>] [div] [<proc[market_interface_slot].context[17]>] [div]"
- - "[div] [div] [div] [div] [div] [div] [div] [div] [div]"
- - "[div] [<proc[market_interface_slot].context[29]>] [div] [<proc[market_interface_slot].context[31]>] [div] [<proc[market_interface_slot].context[33]>] [div] [<proc[market_interface_slot].context[35]>] [div]"
- - "[div] [div] [div] [div] [div] [div] [div] [div] [div]"
-market_interface_slot:
- type: procedure
- debug: false
- script:
- - if <yaml[MARKETSAVES].contains[live_offers.<player>.%1%]> {
- - define item <yaml[MARKETSAVES].read[live_offers.<player>.%1%.item]>
- - define percentage <yaml[MARKETSAVES].read[live_offers.<player>.%1%.progress].div[<yaml[MARKETSAVES].read[live_offers.<player>.%1%.quantity]>].mul[12].as_int||0>
- - if %percentage% == 12 {
- - define col a
- } else {
- - define col e
- }
- - define progressbar "<&%col%><el@============.substring[1,%percentage%]><&8><el@============.substring[<def[percentage].add[1]>,12]>"
- - adjust %item% "lore:li@<&b><yaml[MARKETSAVES].read[live_offers.<player>.%1%.type].to_uppercase>ING|<&f>|<&2>Quantity<&co><&a> <yaml[MARKETSAVES].read[live_offers.<player>.%1%.quantity]>|<&2>Price per<&co><&a> <yaml[MARKETSAVES].read[live_offers.<player>.%1%.price]>|<&f>|<&6>Completed<&co> <yaml[MARKETSAVES].read[live_offers.<player>.%1%.progress].as_int||0>/<yaml[MARKETSAVES].read[live_offers.<player>.%1%.quantity].as_int||0>|%progressbar%|<&f>|<&7>Click to collect.|<&7>Sneak click to abort." save:item
- - determine "<entry[item].result>"
- } else {
- - determine "i@chest[display_name=<&a>Make an offer!;lore=li@<&7>Click to make a buy offer.|<&7>Click an item on here to make a sell offer.]"
- }
-#
-#
-# BUY OFFER INTERFACE
-#
-market_buying_interface:
- debug: false
- type: inventory
- inventory: CHEST
- title: <&2>Buying Interface
- size: 9
- definitions:
- div: i@black_stained_glass_pane[display_name=<&0><&sp>]
- offer: <proc[market_Buying_interface_offer]>
- price: <proc[market_Buying_interface_price]>
- quantity: <proc[market_Buying_interface_quantity]>
- slots:
- - "[i@lime_dye[display_name=<&a>Confirm]] [div] [price] [div] [offer] [div] [quantity] [div] [i@barrier[display_name=<&c>Cancel]]"
-market_Buying_interface_offer:
- type: procedure
- debug: false
- script:
- - if <yaml[MARKETSAVES].contains[offer_constructor.<player>.<player.flag[market_slot_used]>.item]> {
- - define item <yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.item]>
- - adjust %item% "display_name:<&2>Click to change item." save:item
- - determine "<entry[item].result>"
- } else {
- - determine "i@item_frame[display_name=<&2>Click to change item.]"
- }
-market_Buying_interface_price:
- type: procedure
- debug: false
- script:
- - determine "i@sign[display_name=<&6>Change Price;lore=li@<&2>Current price<&co> <&a><yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.price]||1>]"
-market_Buying_interface_quantity:
- type: procedure
- debug: false
- script:
- - determine "i@sign[display_name=<&6>Change Quantity;lore=li@<&2>Current quantity<&co> <&a><yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]||1>]"
-
-#
-#
-# SELL OFFER INTERFACE
-#
-market_selling_interface:
- debug: false
- type: inventory
- inventory: CHEST
- title: <&2>Selling Interface
- size: 9
- definitions:
- div: i@black_stained_glass_pane[display_name=<&0><&sp>]
- offer: <proc[market_selling_interface_offer]>
- price: <proc[market_selling_interface_price]>
- quantity: <proc[market_selling_interface_quantity]>
- slots:
- - "[i@lime_dye[display_name=<&a>Confirm]] [div] [price] [div] [offer] [div] [quantity] [div] [i@barrier[display_name=<&c>Cancel]]"
-market_selling_interface_offer:
- type: procedure
- debug: false
- script:
- - determine "<yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.item]||i@barrier[display_name=<&4>Error.;lore=li@<&c>Something went wrong.]>"
-market_selling_interface_price:
- type: procedure
- debug: false
- script:
- - determine "i@sign[display_name=<&6>Change Price;lore=li@<&2>Current price<&co> <&a><yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.price]||1>]"
-market_selling_interface_quantity:
- type: procedure
- debug: false
- script:
- - determine "i@sign[display_name=<&6>Change Quantity;lore=li@<&2>Current quantity<&co> <&a><yaml[MARKETSAVES].read[offer_constructor.<player>.<player.flag[market_slot_used]>.quantity]||1>]"
-#
-#
-# MARKET OFFERS LISTING
-#
-#
-market_get_offers:
- type: task
- debug: false
- script:
- - define items li@
- - foreach <yaml[MARKETSAVES].list_keys[live_offers]||none> {
- - define player %value%
- - if <yaml[MARKETSAVES].list_keys[live_offers.%player%].size||0> > 0 {
- - foreach <yaml[MARKETSAVES].list_keys[live_offers.%player%]> {
- - define offer_id %value%
- - define amount <yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.quantity].sub[<yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.progress]||0>]>
- - if %amount% > 0 {
- - define item <yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.item]>
- - adjust %item% "lore:li@<&b><yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.type].to_uppercase||none>ING|<&2>Amount<&co> <&a><def[amount].as_int>|<&2>Price per<&co> <&a><yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.price]||none>|<&7>By <def[player].name>" save:item
- - flag market_auto_offer_data_<def[items].size.add[1].as_int>:%player%.%offer_id%
- - define items "%items%<entry[item].result>|"
- }
- }
- }
- }
- - note "in@generic[size=99;title=<&2>Market Offer Listing;contents=<def[items]>]" as:market_offer_listing
- - inventory open d:in@market_offer_listing
-#
-#
-#
-# CHECK FOR MATCHING OFFERS
-#
-#
-market_offer_completer_initiator:
- type: world
- debug: false
- events:
- on system time minutely:
- - if <context.minute.mod[15]> != 0 queue clear
- - announce to_console "<&7>force running market offer completer"
- - run market_offer_completer delay:2s
-market_offer_completer:
- type: task
- speed: 2t
- debug: false
- script:
- - foreach <yaml[MARKETSAVES].list_keys[live_offers].random[9999]||none> {
- - wait 2t
- - define player %value%
- - foreach <yaml[MARKETSAVES].list_keys[live_offers.%player%]||none> {
- - define offer_ID %value%
- - if <yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.type]||none> == sell {
- - foreach <yaml[MARKETSAVES].list_keys[live_offers].random[9999]||none> {
- - wait 2t
- - define player2 %value%
- - foreach <yaml[MARKETSAVES].list_keys[live_offers.%player2%]||none> {
- - define offer_ID2 %value%
- - if <yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.type]||none> == buy {
- - if <yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.item]||none> == <yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.item]||none2> {
- - if <yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.price]||none> <= <yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.price]||none> {
- - define transfer_amount <yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.quantity].sub[<yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.progress]||0>].min[<yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.quantity].sub[<yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.progress]||0>]>]>
- - if %transfer_amount% > 0 {
- - yaml id:MARKETSAVES set live_offers.%player%.%offer_ID%.progress:+:%transfer_amount%
- - yaml id:MARKETSAVES set live_offers.%player2%.%offer_ID2%.progress:+:%transfer_amount%
- - define excess <yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.price].sub[<yaml[MARKETSAVES].read[live_offers.%player%.%offer_ID%.price]>]||0>
- - if %excess% > 0 {
- - yaml id:MARKETSAVES set live_offers.%player%.%offer_ID%.excess:+:<def[excess].mul[%transfer_amount%]>
- }
- - define item <yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.item]>
- - yaml id:MARKETSAVES set statistics.averages.%item%.amount:+:%transfer_amount%
- - yaml id:MARKETSAVES set statistics.averages.%item%.value:+:<yaml[MARKETSAVES].read[live_offers.%player2%.%offer_ID2%.price].mul[%transfer_amount%]>
- - foreach li@%player%|%player2% {
- - if <def[value].is_online> {
- - narrate "<&2>One of your global market offers updated." target:%value%
- - playsound sound:level_up %value% pitch:0.6
- - if <def[value].open_inventory.title||none> == "<&2>Your Offers" {
- - flag %value% market_sell_item_drop duration:5t
- - inventory open d:in@market_interface player:%value%
- } else {
- - flag %value% give_market_update
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-#
-#
-#
-# YAML SAVES HANDLING
-#
-#
-market_saves_yaml_handler:
- type: world
- debug: false
- events:
- on server start:
- - if <server.has_file[/MARKET_SAVES/marketsaves.yml]> {
- - yaml "load:/MARKET_SAVES/marketsaves.yml" id:marketsaves
- } else {
- - yaml create id:marketsaves
- - yaml "savefile:/MARKET_SAVES/marketsaves.yml" id:marketsaves
- }
- on shutdown:
- - yaml "savefile:/MARKET_SAVES/marketsaves.yml" id:marketsaves
- on system time minutely:
- - if <context.minute.mod[10]> == 0 run marketsaves_autosave
-marketsaves_autosave:
- type: task
- debug: false
- script:
- - yaml "savefile:/MARKET_SAVES/marketsaves.yml" id:marketsaves
- - announce to_ops "<&7>Saving market data."