Paste #22579: Edit of P#22577 ItemShop

Date: 2015/11/15 22:59:04 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


###################
#****ItemShop*****#
#*****************#
#****by SeqSEE****#
#*****************#
#******v0.3*******#
###################
ItemShop_Config:
  type: yaml data
  Shops:
    Types:
      Health:
        1:
          name: 'Potion of Healing'
          item: 'potion,8197'
          cost: 50
          qty:  1
        2:
          name: 'Potion of Healing II'
          item: 'potion,8229'
          cost: 75
          qty:  1
        3:
          name: 'Splash Potion of Healing'
          item: 'potion,16389'
          cost: 75
          qty:  1
        4:
          name: 'Splash Potion of Healing II'
          item: 'potion,16421'
          cost: 125
          qty:  1
        5:
          name: 'Potion of Regeneration'
          item: 'potion,8193'
          cost: 150
          qty:  1
        6:
          name: 'Potion of Regeneration (extended)'
          item: 'potion,8257'
          cost: 200
          qty:  1
        7:
          name: 'Potion of Regeneration II'
          item: 'potion,8225'
          cost: 225
          qty:  1
        8:
          name: 'Splash Potion of Regeneration'
          item: 'potion,16385'
          cost: 175
          qty:  1
        9:
          name: 'Splash Potion of Regeneration (extended)'
          item: 'potion,16449'
          cost: 200
          qty:  1
        10:
          name: 'Splash Potion of Regeneration II'
          item: 'potion,16417'
          cost: 250
          qty:  1
      Weapons:
        1:
          name: 'Wooden Dagger'
          item: 'wooden_sword'
          cost: 25
          qty:  1
        2:
          name: 'Stone Whip'
          item: 'stone_sword'
          cost: 50
          qty:  1
        3:
          name: 'Crowbar'
          item: 'iron_sword'
          cost: 100
          qty:  1
        4:
          name: 'Golden Axeblade'
          item: 'golden_sword'
          cost: 150
          qty:  1
        5:
          name: 'Diamond Light Saber'
          item: 'diamond_sword'
          cost: 350
          qty:  1
        6:
          name: 'Bow'
          item: 'bow'
          cost: 100
          qty:  1
        7:
          name: 'Arrows (16)'
          item: 'arrow'
          cost: 50
          qty:  16
        8:
          name: 'Arrows (32)'
          item: 'arrow'
          cost: 100
          qty:  32
        9:
          name: 'Arrows (64)'
          item: 'arrow'
          cost: 150
          qty:  64
      Redstone:
        1:
          name: 'Red Matter (32)'
          item: 'redstone'
          cost: 100
          qty:  32
        2:
          name: 'Red Power Torch (16)'
          item: 'redstone_torch'
          cost: 100
          qty:  16
        3:
          name: 'Repeater (2)'
          item: 'repeater'
          cost: 50
          qty:  2
        4:
          name: 'Comparator'
          item: 'comparator'
          cost: 50
          qty:  1
        5:
          name: 'Red Power Block'
          item: 'redstone_block'
          cost: 50
          qty:  1
        6:
          name: 'Piston'
          item: 'piston'
          cost: 50
          qty:  1
        7:
          name: 'Sticky Piston'
          item: 'sticky_piston'
          cost: 100
          qty:  1
      Armor:
        1:
          name: 'Blacksmith Boots'
          item: 'chainmail_boots'
          cost: 175
          qty:  1
        2:
          name: 'Blacksmith Leggings'
          item: 'chainmail_leggings'
          cost: 250
          qty:  1
        3:
          name: 'Blacksmith Chestplate'
          item: 'chainmail_chestplate'
          cost: 300
          qty:  1
        4:
          name: 'Blacksmith Goggles'
          item: 'chainmail_helmet'
          cost: 175
          qty:  1
        5:
          name: 'Iron Boots'
          item: 'iron_boots'
          cost: 100
          qty:  1
        6:
          name: 'Iron Leggings'
          item: 'iron_leggings'
          cost: 150
          qty:  1
        7:
          name: 'Iron Chestplate'
          item: 'iron_chestplate'
          cost: 175
          qty:  1
        8:
          name: 'Iron Helmet'
          item: 'iron_helmet'
          cost: 125
          qty:  1
        9:
          name: 'Gold Boots'
          item: 'gold_boots'
          cost: 150
          qty:  1
        10:
          name: 'Gold Leggings'
          item: 'gold_leggings'
          cost: 300
          qty:  1
        11:
          name: 'Gold Chestplate'
          item: 'gold_chestplate'
          cost: 350
          qty:  1
        12:
          name: 'Gold Helmet'
          item: 'gold_helmet'
          cost: 250
          qty:  1
        13:
          name: 'Diamond Boots'
          item: 'diamond_boots'
          cost: 300
          qty:  1
        14:
          name: 'Diamonds Leggings'
          item: 'diamond_leggings'
          cost: 450
          qty:  1
        15:
          name: 'Diamond Chestplate'
          item: 'diamond_chestplate'
          cost: 525
          qty:  1
        16:
          name: 'Diamond Helmet'
          item: 'diamond_helmet'
          cost: 375
          qty:  1          
ItemShop:
  type: assignment
  debug: true
  actions:
      on assignment:
      - trigger name:click state:true
      - trigger name:chat state:true
      - flag npc ItemShop.HasShop:!
      - flag npc ItemShop.Type:!
      - zap 1 s@Shop_Keeper
  interact scripts:
  - 1 Shop_Keeper
Shop_Keeper:
    type: interact
    debug: true
    steps:
        1:
            click trigger:
                script:
                - if <npc.has_flag[ItemShop.HasShop]> {
                  - zap 2
                  - queue stop
                }
                - narrate "Please choose a shop type."
                - foreach <s@ItemShop_Config.list_keys[Shops.Types]> {
                  - narrate "<&7>%value%"
                  - wait 1t
                  }
                - narrate "<&e>(Shop Type/List)"
            chat trigger:
                1:
                    trigger: /List/
                    script:
                    - narrate "Please choose a shop type."
                    - foreach <s@ItemShop_Config.list_keys[Shops.Types]> {
                      - narrate "<&7>%value%"
                      - wait 1t
                      }
                    - narrate "<&e>(Shop Type/List)"
                2:
                    trigger: /regex:([a-zA-Z])\w+/
                    script:
                    - if <s@ItemShop_Config.list_keys[Shops.Types].contains[<context.message>].not> {
                      - narrate "<npc.name><&co> <&c><context.message> is not a valid shop type!"
                      - queue stop
                      }
                    - flag npc ItemShop.HasShop:1
                    - flag npc ItemShop.Type:<context.message>
                    - execute as_server "denizen save"
                    - narrate "Set shop as <npc.flag[ItemShop.Type]> shop type."
                    - zap 2
        2:
            click trigger:
                script:
                - narrate "<npc.name><&co> Hello! What would you like to buy today?"
                - narrate "<&e>(Cancel/Item Number/List)"
            chat trigger:
                1:
                    trigger: /Cancel/
                    script:
                    - narrate "<npc.name><&co> Okay."
                    - wait 1
                    - narrate "<npc.name><&co> I'll be here still if you change your mind!"
                2: 
                    trigger: /No/
                    script:
                    - narrate "<npc.name><&co> Okay."
                    - wait 1
                    - narrate "<npc.name><&co> I'll be here still if you change your mind!"
                3:
                    trigger: /List/
                    script:
                    - flag npc ItemShop.CurrentNumber:0
                    - narrate ""
                    - foreach <s@ItemShop_Config.list_keys[Shops.Types.<npc.flag[ItemShop.Type]>]> {
                      - flag npc ItemShop.CurrentNumber:++
                      - narrate "<&8><npc.flag[ItemShop.CurrentNumber].as_int> <&7><s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<npc.flag[ItemShop.CurrentNumber].as_int>.name]> <&a>$<s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<npc.flag[ItemShop.CurrentNumber].as_int>.cost]>"
                      - wait 1t
                      }
                    - wait 1t
                    - narrate ""
                    - narrate "<npc.name><&co> See anything you want?"
                    - wait 1t
                    - narrate "<&e>(No/Item Number)"
                4:
                    trigger: /regex:([0-9])+/
                    script:
                    - if <s@ItemShop_Config.list_keys[Shops.Types.<npc.flag[ItemShop.Type]>].contains[<context.message>].not> {
                      - narrate "<npc.name><&co> <&c><context.message> is not a valid item number!"
                      - queue stop
                      }
                    - if <player.money.is[LESS].than[<s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<context.message>.cost]>]||true> {
                      - narrate "<npc.name><&co><&c> Sorry, you don't have enough money."
                      - queue stop
                      }
                    - if <s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<context.message>.item].as_item||null> != null {
                      - take money quantity:<s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<context.message>.cost]>
                      - give <s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<context.message>.item].as_item> quantity:<s@ItemShop_Config.yaml_key[Shops.Types.<npc.flag[ItemShop.Type]>.<context.message>.qty]>
                      - narrate "<npc.name><&co> Thanks for doing business with me!"
                      - queue stop                  
                      }
                    - narrate "<npc.name><&co> <&c>Sorry, that item is currently unavailable."