Paste #45248: Untitled Paste

Date: 2017/10/27 14:54:27 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


ShopPrisonShop1_Data:
    type: yaml data
    config:
        materials:
            Melon: 10
            STONE_PICKAXE : 25
            COAL: 8
            IRON_INGOT: 25
            LEATHER: 8




## <s@Shop_Data.yaml_key[config.price.stone]> returns invalid

ShopPrisonShop1_Events:
    type: world
    events:
        on server start: 
        - inject ShopPrisonShop1_Reload

        on reload scripts:
        - inject ShopPrisonShop1_Reload

        on player clicks in ShopPrisonShop1_Menu:
        - determine cancelled passively
        - define item <context.item.material.after[m@]>
        - if <def[item]> == air {
            - queue clear
        }
        - if <s@ShopPrisonShop1_Data.list_keys[config.materials].contains[<def[item]>].not> {
            - narrate format:util_ff "<&c>Det item er har ikke noget værdi."
            - queue clear
        }
        - if <player.inventory.is_full> {
            - narrate format:util_ff "<&c>Din inventory er fuld!"
            - queue clear
        }
        - define brought <s@ShopPrisonShop1_Data.yaml_key[config.materials.<def[item]>]>
        - if <player.money> < <def[brought]> {
            - narrate format:util_ff "<&c>Du har ikke penge nok!"
            - queue clear
        }
        - give <def[item]> qty:1
        - take money quantity:<def[brought]>
        - narrate format:util_ff "<&a>Købte <&b>1 <def[item]> <&a>for <&6>$<def[brought]>"
        - inventory open d:in@ShopPrisonShop1_Menu

        on player drags in ShopPrisonShop1_Menu:
        - determine cancelled

ShopPrisonShop1_Main:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - 10 ShopPrisonShop1_Assign

ShopPrisonShop1_Reload:
    type: task
    script:
    - flag server ShopPrisonShop1_Items:!
    - foreach <s@ShopPrisonShop1_Data.list_keys[config.materials].sort[ShopPrisonShop1_Sort].reverse> {
        - flag server ShopPrisonShop1_Items:->:<def[value]>[lore=<proc[ShopPrisonShop1_Proc].context[2|<def[value]>]>]
    }

ShopPrisonShop1_Sort:
    type: procedure
    definitions: p1|p2
    script:
    - if <s@ShopPrisonShop1_Data.yaml_key[config.materials.<def[p2]>]> > <s@ShopPrisonShop1_Data.yaml_key[config.materials.<def[p1]>]> { 
        - determine 1 
    }
    else if <s@ShopPrisonShop1_Data.yaml_key[config.materials.<def[p1]>]> > <s@ShopPrisonShop1_Data.yaml_key[config.materials.<def[p2]>]> { 
        - determine -1 
    }
    else { 
        - determine 0 
    }

ShopPrisonShop1_Assign:
    type: interact
    steps:
        1:
            click trigger:
                script:
                - run ShopPrisonShop1_Task player:<player> npc:<npc> instantly

ShopPrisonShop1_Task:
    type: task
    script:
    - inventory open d:in@ShopPrisonShop1_Menu
    - random {
        - narrate "<&8>[<&a><npc.name><&8>] <&6>Kig lidt rundt."
        - narrate "<&8>[<&a><npc.name><&8>] <&6>Noget du vil have?"
        - narrate "<&8>[<&a><npc.name><&8>] <&6>Ting sælges for en rimelig pris."
        - narrate "<&8>[<&a><npc.name><&8>] <&6>Tag et kig  hvad jeg har."
        - narrate "<&8>[<&a><npc.name><&8>] <&6>Kan jeg hjælpe dig med noget?"
        - narrate "<&8>[<&a><npc.name><&8>] <&6>Er der noget du vil have?"
    }

ShopPrisonShop1_Menu:
  type: inventory
  inventory: CHEST
  title: <&3>Shop <&8>- <&3>Køb
  size: 18
  definitions:
    Close: i@stone
  slots:
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
  procedural items:
    - determine <server.flag[ShopPrisonShop1_Items].as_list>
    # - flag player CTF_Config_SameClass_kits:!
    # - foreach <yaml[ctf_maps].list_keys[ctf.maps]> {
        # - flag player CTF_Config_SameClass_kits:->:<proc[CTF_LobbyMenu_Menu_MapSelection_Proc].context[1|<def[value]>]>[display_name=<proc[CTF_LobbyMenu_Menu_MapSelection_Proc].context[2|<def[value]>]>;lore=<proc[CTF_LobbyMenu_Menu_MapSelection_Proc].context[3|<def[value]>]>|<proc[CTF_LobbyMenu_Menu_MapSelection_Proc].context[4|<def[value]>]>]
    # }

ShopPrisonShop1_Proc:
    type: procedure
    debug: false
    definitions: line|item
    script:
    - choose "<def[line]>":
        - case "2":
            - determine "<&3>Koster<&co> <&b>$<s@ShopPrisonShop1_Data.yaml_key[config.materials.<def[item]>]>"
        - default:
            - determine "Chosen default in <def[item]>"