Paste #23357: Edit of P#23355 Chest (RE)Populator

Date: 2015/12/02 21:23:28 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#####################################
#  Created by NLBlackEagle          #
#  Website: www.craftrealms.org     #
#  TeamSpeak: ts3.craftrealms.org   #
#####################################



Chest100Script:
  type: world
  default constants:
  #The RepopulateCooldown value is in minutes and determines the amount of time before a re-population 
  #should be executed. This causes no server load since the re-population is player-bound. 
  #Change the value "300m" to any number you'd like. 300m equals 5 hours.
    RepopulateCooldown: 300m
  #PopulateAttemts, lower this number to decrease the amount of items in a chest.
    PopulateAttemts: 15
  #PopulateMinimalItems, Minimal items in a chest upon populating. 0 Makes items more rare but not impossibile to populate.
    PopulateMinimalItems: 2
  debug: true
  events:
    on server start:
    - yaml load:loottable.yml id:lootcrates
    on player opens chest:
    - if !<player.has_flag[<context.inventory.location.simple>]> {
      - flag player <context.inventory.location.simple>:true duration:<s@chest100script.constant[RepopulateCooldown]>
      - if <server.flag[chest].as_list.contains[<context.inventory.location.simple>]> {
        - queue clear
      }
      - repeat <s@chest100script.constant[PopulateMinimalItems]> {
        - inventory add d:<context.inventory> o:<yaml[lootcrates].read[loot].random.as_item> slot:<util.random.int[1].to[27]>
      }
      - repeat <s@chest100script.constant[PopulateAttemts]> {
        - if <util.random.int[1].to[5]> == 5 {
          - inventory add d:<context.inventory> o:<yaml[lootcrates].read[loot].random.as_item> slot:<util.random.int[1].to[27]>
        }
      }
    }
    on player places block:
    - if li@chest|trapped_chest contains <context.material.name> {
      - flag server chest:->:<context.location.simple>
    }