(server owned) Item Frame Shop


Author: calico-kid
Created: 2014-07-06T21:07:10-0400
Edited: 2014-08-18T23:42:15-0400
Denizen Version: 1481
Views: 73
Downloads: 1182
Likes: 8


WGET
Description: This is a shop that uses item frames. It adds life to a server and purpose for shop decore. This shop has been made with much help from mcmonkey |anthony| talamar1 morphan1 and many others that have suggested different additions. aufdemrand originally started the idea and part of the script. then handed it to me to complete. so i cant take full credit for this. please like this script if its something you use or like using. and please comment or join us on the denizen dev if you have any issues.


you will also need my prices yaml for this script to work properly! go to: http://scripts.citizensnpcs.co/view/f58jln



For a quick setup tutorial please visit http://youtu.be/LANfvO1DOCE

version 2 this version uses a new type of prices.yml it also makes the players item bag different every time they buy something. added in a new command for pricing of custom items, use /price to set a new price for a custom item.

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!'
        - note 'in@player bag' as:<player.name>_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.full.escaped>]>].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!'
      - note 'in@player bag' as:<player.name>_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[<entry[item].result.full.escaped>]>].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 {
      - if <context.message> matches double {
        - 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
        }
        else {
        - narrate "<dark_red>That is not a valid number"
        }
      }
      
    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.full.escaped>]>].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]>' >= 2 {
      - 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[store].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.item_in_hand.lore.as_string.strip_color>_item_bag.list_contents> {
        - drop %value% <player.location>
        }
      - narrate "<dark_red>your shopping bag ripped"
      - take iteminhand
      }

    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




Comments
2014-07-09 03:20:27 - danton1983:

Custom Items would be a nice feature to have if you could somehow work that out, thanks!
2014-07-09 03:53:36 - danton1983:

Custom Items would be a nice feature to have if you could somehow work that out, thanks!