Paste #13316: Untitled Paste

Date: 2015/01/24 10:37:56 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# +----------------------------------
# |   Lock Pick
# +----------------------------------

Lock_Pick:
  type: item
  material: LEVER
  display name: <blue>Lock Pick<&r>
  no_id: false
  recipe:
  - i@air|i@tripwire_hook|i@air
  - i@air|i@iron_ingot|i@air
  - i@air|i@air|i@air

Key:
  type: item
  material: LEVER
  display name: <gold>Key<&r>
  lore:
  - <black>K<util.random.uuid><&r>
  no_id: false
  recipe:
  - i@air|i@tripwire_hook|i@air
  - i@air|i@gold_ingot|i@air
  - i@air|i@air|i@air


# +----------------------------------
# |   Locks
# +----------------------------------

Basic_Lock:
  type: item
  material: NAME_TAG:1
  display name: <green>Basic Lock <dark_red>(No Key)
  no_id: true
  recipe:
  - i@air|i@air|i@air
  - i@air|i@iron_block|i@iron_ingot
  - i@air|i@air|i@air

Advanced_Lock:
  type: item
  material: NAME_TAG:2
  display name: <aqua>Advanced Lock <dark_red>(No Key)
  no_id: true
  recipe:
  - i@air|i@air|i@air
  - i@iron_ingot|i@iron_block|i@iron_ingot
  - i@air|i@air|i@air

Strong_Lock:
  type: item
  material: NAME_TAG:3
  display name: <&5>Strong Lock <dark_red>(No Key)
  #no_id: true
  recipe:
  - i@air|i@iron_ingot|i@air
  - i@iron_ingot|i@iron_block|i@iron_ingot
  - i@air|i@air|i@air

Tough_Lock:
  type: item
  material: NAME_TAG:4
  display name: <gold>Tough Lock <dark_red>(No Key)
  no_id: true
  recipe:
  - i@air|i@iron_ingot|i@air
  - i@iron_ingot|i@iron_block|i@iron_ingot
  - i@air|i@iron_ingot|i@air

Fine_Lock:
  type: item
  material: NAME_TAG:5
  display name: <&2>Tough Lock <dark_red>(No Key)
  no_id: true
  recipe:
  - i@iron_ingot|i@iron_ingot|i@iron_ingot
  - i@iron_ingot|i@iron_block|i@iron_ingot
  - i@air|i@iron_ingot|i@air

Master_Lock:
  type: item
  material: NAME_TAG:6
  display name: <&4>Master Lock <dark_red>(No Key)
  no_id: true
  lore:
  - <&7>Unpickable<&r>
  - <&7>Can only be opened<&r>
  - <&7>with the right key<&r>
  recipe:
  - i@gold_ingot|i@gold_ingot|i@gold_ingot
  - i@gold_ingot|i@gold_block|i@gold_ingot
  - i@gold_ingot|i@gold_ingot|i@gold_ingot


Load_Locks:
  type: task
  Script:
    - if <server.has_file[Lock_Data.yml]> {
      - yaml "load:/Data/Lock_Data.yml" id:Lock_D
      - narrate "<dark_green>Loading <gold>Lock Data"
      } else {
      - yaml create id:Lock_D
      - narrate "<red>Couldn't find Data file."
      - narrate "<dark_green>Creating new <gold>Lock Data <dark_green>file"
      - yaml id:Lock_D set Statistics.Locks.Picked:0
      - yaml id:Lock_D set Statistics.Locks.Chest:0
      - yaml id:Lock_D set Statistics.Locks.Doors:0
      - wait 10s
      - yaml "savefile:/Data/Lock_Data.yml" id:Lock_D
      }

Save_Locks:
  type: task
  Script:
    - yaml "savefile:/Data/Lock_Data.yml" id:Lock_D
    - narrate "<dark_green>Saving <gold>Lock Data"
    - run Save_Sarah delay:10m

# +----------------------------------
# |   Lock System
# +----------------------------------
Lock_System:
  type: world
  events:
      on player opens inventory:
      - if <context.inventory.slot[1].display.contains[Lock]> {
        - if <context.inventory.slot[1].display.contains[(Locked)]> && <context.inventory.slot[1].material> == m@name_tag,1 && <player.item_in_hand> != i@Key && <player.item_in_hand> != i@Lock_Pick {
          - narrate "<red>This chest is locked."
          - determine cancelled
          }
        - if <player.item_in_hand> == i@Key {
          # Check if it's unlocked
          - if <context.inventory.slot[1].display.contains[(Unlocked)]> && <context.inventory.slot[1].material> == m@name_tag,1 {
            # Check if key matches
            - if <context.inventory.slot[1].contains[<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>]> {
              - determine passively cancelled
              - if <context.inventory.slot[1].contains[Basic]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Basic<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Advanced]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Advanced<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Strong]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Strong<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Tough]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Tough<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Fine]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Fine<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Master]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Master<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
              - inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
              - wait 1t
              - give <entry[Lock_Item].result> to:<context.inventory> slot:1
              - narrate "<red>Locked Chest"
              } else {
              - narrate "<dark_red>This key doesn't fit."
              - determine cancelled
              }
            } else if <context.inventory.slot[1].display.contains[(Locked)]> && <context.inventory.slot[1].material> == m@name_tag,1 {
            # Check if key matches
            - if <context.inventory.slot[1].contains[<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>]> {
              - if <context.inventory.slot[1].contains[Basic]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Basic<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Advanced]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Advanced<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Strong]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Strong<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Tough]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Tough<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Fine]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Fine<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
              - if <context.inventory.slot[1].contains[Master]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Master<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
              - inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
              - wait 1t
              - give <entry[Lock_Item].result> to:<context.inventory> slot:1
              - narrate "<green>Unlocked Chest"
              } else {
              - narrate "<dark_red>This key doesn't fit."
              - determine cancelled
              }
            } else if <context.inventory.slot[1].contains[(No<&sp>Key)]> && <context.inventory.slot[1].material> == m@name_tag,1 {
            - determine passively cancelled
            - if <context.inventory.slot[1].contains[Basic]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Basic<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
            - if <context.inventory.slot[1].contains[Advanced]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Advanced<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
            - if <context.inventory.slot[1].contains[Strong]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Strong<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
            - if <context.inventory.slot[1].contains[Tough]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Tough<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
            - if <context.inventory.slot[1].contains[Fine]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Fine<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
            - if <context.inventory.slot[1].contains[Master]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Master<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
            - inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
            - wait 1t
            - give <entry[Lock_Item].result> to:<context.inventory> slot:1
            - adjust <context.inventory.slot[1]> "lore:<black>L<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>" save:Lock_Item
            - inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
            - wait 1t
            - give <entry[Lock_Item].result> to:<context.inventory> slot:1
            - narrate "<green>Key succesfully binded."
            }
          }
        # end of checking for a lock
        }










      on player right clicks block:
      - define loc <context.location.block> 
      - if <def[loc].material.name.ends_with[door]> {
        - narrate "<red>Door Clicked"

        - if <player.item_in_hand> == i@key || <player.item_in_hand> == i@Lock_Pick || <player.item_in_hand.contains[Lock]> {
          # Check if it's a lock
          - if <player.item_in_hand.contains[Lock]> && <player.item_in_hand.material.contains[name_tag]> {
            - determine passively cancelled
            # Check if the door already has a lock
            - if <context.cuboids.formatted.contains[Lock]> {
              - narrate "<red>This door already has a lock."
              - queue clear
              } else {
              - if <player.item_in_hand.display.contains[Basic]> define Lock_Type Basic_Lock
              - if <player.item_in_hand.display.contains[Advanced]> define Lock_Type Advanced_Lock
              - if <player.item_in_hand.display.contains[Strong]> define Lock_Type Strong_Lock
              - if <player.item_in_hand.display.contains[Tough]> define Lock_Type Tough_Lock
              - if <player.item_in_hand.display.contains[Fine]> define Lock_Type Fine_Lock
              - if <player.item_in_hand.display.contains[Master]> define Lock_Type Master_Lock

              - if <player.item_in_hand.display.contains[(No<&sp>Key)]> define Lock_state No_Key
              - if <player.item_in_hand.display.contains[(Unlocked)]> define Lock_state Unlocked
              - if <player.item_in_hand.display.contains[(Locked)]> define Lock_state Locked

              - define ID <yaml[Lock_D].read[Statistics.Locks.Doors]>
              # Check if they clicked the bottom or top part of the door.
              - if <player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]> != null define UUID <player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>
              - if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
                - if %LockState% == No_Key {
                  - note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(%Lock_state%)
                  } else {
                  - note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(%Lock_state%)_L%UUID%
                  }
                } else {
                - if %LockState% == No_Key {
                  - note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(%Lock_state%)
                  } else {
                  - note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(%Lock_state%)_L%UUID%
                  }
                }
              - narrate "<dark_green>Lock succesfully installed"
              - yaml id:Lock_D set Statistics.Locks.Doors:++
              - take <player.item_in_hand>
              - queue clear
              }
            }























          - if <player.item_in_hand> == i@key {
            - narrate "Using a key"
            - define UUID <player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>
            # Check if there's a cuboid that contains the word "lock"
            - if <context.cuboids.formatted.contains[Lock]> {
              # Check if the cuboid has a UUID
              - if <context.cuboids.formatted.contains[L<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>]> {
                # Check if it's locked
                - if <context.cuboids.formatted.contains[(Locked)]> {
                  # Check all cuboids (so we can find the one we want to change)
                  - foreach <context.cuboids> {
                    # finding the one that has lock in it
                    - if <def[%value%].contains[lock]> {
                      # removing it
                      - note remove as:%value%
                      # checking where on the door they clicked, to correctly make a new cuboid with a diferent lock_state
                      - if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
                        # making the new cuboid
                        - note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
                        } else {
                        - note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
                        }
                      }
                    - narrate "<dark_green>Unlocked Door"
                    - queue clear
                    }
                  # If it's not locked and it has the UUID of our key it must be unlocked, so we change it to a locked state
                  # same procedure as above, just locking instead of unlocking.
                  } else {
                  - foreach <context.cuboids> {
                    - if <def[%value%].contains[lock]> {
                      - note remove as:%value%
                      - if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
                        - note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(Locked)_L%UUID%
                        } else {
                        - note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(Locked)_L%UUID%
                        }
                      }
                    - narrate "<dark_red>Locked Door"
                    - queue clear
                    }
                  }
                # If it doesn't have a UUID it must be a lock with no key attached.
                } else {
                - foreach <context.cuboids> {
                  - if <def[%value%].contains[lock]> {
                    - note remove as:%value%
                    - if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
                      - note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
                      } else {
                      - note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
                      }
                    }
                  }
                - narrate "BIND LOCK HERE"
                }
              } else {
              - queue clear
              }
            }

          } else {
          - queue clear
          }
        }






























Lore_Test:
    type: command
    name: dlore
    description: Denizen lore
    usage: /lore test
    script:
# Checking that they have exactly 1 argument (hopefully a playername.)
      - adjust <player.item_in_hand> "lore:Advanced Item" save:myitem 
      - take iteminhand
      - wait 1s
      - give <entry[myitem].result>