Paste #71515: IcecapadeCrateScript

Date: 2020/06/27 23:51:06 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#Script: 1.0.6
#Author: Icecapade
#Date 2020-06-28
IcecapadeCrates_Config:
    type: data
    #Show Tripwires (does not affect existing crates)
    show_tripwire: true
    chests:
        lightChestName: <green>Light
        mediumChestName: <yellow>Medium
        heavyChestName: <red>Heavy
        #In that list diamonds have a chance of 2%, iron_ingots 8% and dirt has a chance of 30%. The remaining 60% have no result.
        #Works also with decimals. Start with the lowest value.
        #Format "<chance>: <item>"
        lightChestItems:
            2: <item[diamond]>
            10: <item[iron_ingot]>
            40: <item[dirt].with[quantity=12]>
        mediumChestItems:
            0.01: <item[diamond_block].with[quantity=64]>
            1.25: <item[beacon]>
            25: <item[iron_ingot].with[quantity=8]>
        heavyChestItems:
            10: "<item[diamond_sword].with[enchantments=sharpness,4|fire_aspect,1;display_name=<aqua>Fire Sword]>"
IcecapadeCrates_Command:
    type: command
    debug: false
    name: crates
    description: Creates Crates
    usage: /crates [Light/Medium/Heavy] (key) <&lt>#<&gt>
    aliases:
    - crate
    permission: icecapade.crates
    permission message: <&3>You need the permission <&b><permission> <&3>to use that command!
    tab complete:
    - choose <context.args.size>:
        - case 0:
            - determine <list[light|medium|heavy]>
        - case 1:
            - if "!<context.raw_args.ends_with[ ]>":
                - determine <list[light|medium|heavy].filter[starts_with[<context.args.first>]]>
            - else:
                - determine key
        - case 2:
            - if "!<context.raw_args.ends_with[ ]>":
                - determine key
    script:
    - choose <context.args.first||null>:
        - case light medium heavy:
            - if <context.args.get[2]||false> == key && <context.args.get[3].is_integer||true>:
                - give IcecapadeCrates_Key<context.args.first> q:<context.args.get[3]||8>
                - narrate "<&3>You received <&b><context.args.get[3]||8>x <context.args.first.to_titlecase> keys"
            - else:
                - give IcecapadeCrates_Chest<context.args.first>
                - narrate "<&3>You received a <&b><context.args.first.to_titlecase> crate<&3>."
        - default:
            - narrate "<&3>Syntax: <&b>/crates [Light/Medium/Heavy] (key) (<&lt>#<&gt>)"
IcecapadeCrates_CrateHandler:
    type: world
    debug: false
    events:
        on player right clicks armor_stand with:IcecapadeCrates_Key*:
        - determine passively cancelled
        - choose <context.entity.flag[crate].first||null>:
            - case light medium heavy:
                - if <context.item.nbt[crate]> == <context.entity.flag[crate].first>:
                    - run IcecapadeCrates_Task def:<context.entity.flag[crate].first>|<context.entity.flag[crate].last>
        on player right clicks ender_chest with:IcecapadeCrates_Key*:
        - determine passively cancelled
        - foreach <list[light|medium|heavy]> as:type:
            - if <server.flag[crates.<[type]>].get_sub_items[1].contains[<context.location>]||false> && <context.item.nbt[crate]> == <[type]>:
                - run IcecapadeCrates_Task def:<[type]>|<context.location>
                - stop
        on player breaks ender_chest:
        - foreach <list[light|medium|heavy]> as:type:
            - if <server.flag[crates.<[type]>].get_sub_items[1].contains[<context.location>]||false>:
                - if <player.has_permission[icecapade.crates]>:
                    - define entry <server.flag[crates.<[type]>].get[<server.flag[crates.<[type]>].find_partial[<context.location>]>]>
                    - flag <[entry].after[/].as_list.first> crate:!
                    - flag <[entry].after[/].as_list.last> crate:!
                    - remove <[entry].after[/]>
                    - flag server crates.<[type]>:<-:<[entry]>
                    - stop
                - else:
                    - determine cancelled
        on player places IcecapadeCrates_Chest* permission:icecapade.crates:
        - define type <context.item_in_hand.nbt[crate].strip_color>
        - spawn armor_stand[gravity=false;visible=false;armor_pose=head|0,0,0] <context.location.add[0.5,-0.7,0.5].with_yaw[<player.location.direction[<context.location>].yaw.round_to_precision[90]>].forward_flat[0.25]> save:<[type]>
        - spawn armor_stand[gravity=false;visible=false;custom_name=<script[IcecapadeCrates_Config].data_key[chests.<[type]>ChestName].parsed>;custom_name_visible=true] <context.location.add[0.5,-0.5,0.5]> save:name
        - if <script[IcecapadeCrates_Config].data_key[show_tripwire]>:
            - equip <entry[<[type]>].spawned_entity> head:<item[tripwire_hook].with[enchantments=durability,1]>
        - flag server crates.<[type]>:->:<context.location>/<entry[<[type]>].spawned_entity>|<entry[name].spawned_entity>
        - flag <entry[<[type]>].spawned_entity> crate:!|:<[type]>|<context.location>
        - flag <entry[name].spawned_entity> crate:!|:<[type]>|<context.location>
IcecapadeCrates_Task:
    type: task
    debug: false
    definitions: type|chest
    script:
    - choose <[type]>:
        - case light medium heavy:
            - define chance <util.random.decimal[0].to[100]>
            - wait 1t
            - take iteminhand
            - define loot <script[IcecapadeCrates_Config].data_key[chests.<[type]>ChestItems].get_subset[<script[IcecapadeCrates_Config].data_key[chests.<[type]>ChestItems].list_keys.numerical>]>
            - foreach <[loot].list_keys>:
                - if <[chance]> <= <[value]>:
                    - repeat 3:
                        - firework <player.location.find.surface_blocks.within[4].random> random primary:<list[green|blue|yellow|aqua|white|orange].random[2]> fade:<list[green|blue|yellow|aqua|white|orange].random[2]> power:1
                    - animatechest <[chest]> sound:false
                    - playsound <player.location> sound:ENTITY_PLAYER_LEVELUP
                    - define item <[loot].list_values.get[<[loop_index]>].parsed>
                    - give <[item]>
                    - narrate "<green>Congrats! <white>You won <gold><[item].quantity>x <&r><[item].display||<blue><[item].material.translated_name>>"
                    - wait 1s
                    - animatechest <[chest]> close sound:false
                    - stop
            - narrate "<red>No Result"
IcecapadeCrates_ChestLight:
    type: item
    material: ender_chest
    display name: <green>Light Crate
    lore:
    - <&r>Place it to create a <green>Light Crate.
    mechanisms:
        nbt:
        - crate/Light
IcecapadeCrates_ChestMedium:
    type: item
    material: ender_chest
    display name: <yellow>Medium Crate
    lore:
    - <&r>Place it to create a <yellow>Medium Crate.
    mechanisms:
        nbt:
        - crate/Medium
IcecapadeCrates_ChestHeavy:
    type: item
    material: ender_chest
    display name: <red>Heavy Crate
    lore:
    - <&r>Place it to create a <red>Heavy Crate.
    mechanisms:
        nbt:
        - crate/Heavy
IcecapadeCrates_KeyLight:
    type: item
    material: tripwire_hook
    display name: <green>Light Key
    lore:
    - <&r>You can open a <green>Light Crate<&r> with it.
    enchantments:
    - durability:1
    mechanisms:
        nbt:
        - crate/light
        hides:
        - ENCHANTS
IcecapadeCrates_KeyMedium:
    type: item
    material: tripwire_hook
    display name: <yellow>Medium Key
    lore:
    - <&r>You can open a <yellow>Medium Crate<&r> with it.
    enchantments:
    - durability:1
    mechanisms:
        nbt:
        - crate/medium
        hides:
        - ENCHANTS
IcecapadeCrates_KeyHeavy:
    type: item
    material: tripwire_hook
    display name: <red>Heavy Key
    lore:
    - <&r>You can open a <red>Heavy Crate<&r> with it.
    enchantments:
    - durability:1
    mechanisms:
        nbt:
        - crate/heavy
        hides:
        - ENCHANTS