Staff Pick: Mob Loot
By
AnthonyCreated: 2015/06/15 11:16:40 UTC-07:00 (9 years and 192 days ago)
Edited: 2015/06/15 11:32:36 UTC-07:00 (9 years and 192 days ago)
Likes: 1
Staff pick as of: 2015/06/17 17:24:52 UTC-07:00 (9 years and 190 days ago)
Denizen Version: 0.9.6
Script Version: 0.1
Description:
Customize how your players are rewarded for killing mobs! A simple config file allows you to specify how much XP, money, and items each mob will drop when a player kills it. Copy the existing examples to customize all the mobs!
To install, simply copy the script and save it in your denizen scripts folder then /denizen reload scripts
Download script |
View raw script################################################################################
#
# M o b L o o t
# Reward players for killing mobs
#
#
# Authors: |Anthony| anthony@mineconomy.org
# Version: 0.1
# dScript Version: 0.9.6
#
#
################################################################################
MobLoot_World:
type: world
debug: false
# Edit these config options to your liking. DO NOT REMOVE THEM!
# You can copy these as a guideline when adding other mobs.
config:
# Bukkit entity name
zombie:
rewards:
# Type of reward. Can be 'all' or 'single'
# All - Rewards players with each of the reward types listed
# Single - Rewards players with just one of the reward types listed
# Uses a weighted random choice generator. The reward given is
# Based on a weight assignment exemplified below.
type: all
# Used to define the types of rewards given. Can include any reward types
# If using 'all' list each of the reward types.
# If using 'single' write the weight and the reward type.
# Single format: weight/type - 10/money
types:
- money
- item
- xp
# Range of money to reward a player
money: 10/20
# Range of xp to reward a player
xp: 1/4
# List of items to reward a player. Use the denizen item names.
items:
bread:
# Reward is determined randomly based on a weight assignment. The higher
# the weight, the more likely it is that that item will be the reward.
weight: 10
# The quantity of drops for this item is randomly determined between the range specified.
range: 10/20
cooked_beef:
weight: 20
range: 2/8
rotten_flesh:
weight: 40
range: 1/3
skeleton:
rewards:
type: single
types:
- 10/money
- 50/item
- 10/xp
money: 10/20
xp: 1/4
items:
bread:
weight: 10
range: 10/20
cooked_beef:
weight: 20
range: 2/8
rotten_flesh:
weight: 40
range: 1/3
events:
#
#--------------------------------------
#
# Kill Event Handlers
#
on entity dies:
- if !<c.damager.is_player||false> queue clear
- if !<script.list_keys[config].contains[<c.entity.entity_type>]> queue clear
- determine passively "NO_DROPS_OR_XP"
- run player:<c.damager> s@MobLoot_World p:ProcessEvent delay:1t 'def:<c.entity.entity_type.to_lowercase>|<c.entity.location>'
#
# END Kill Event Handlers
#
#--------------------------------------
#
# Event Processors
#
ProcessEvent:
- ^narrate "killing"
- ^define rewardType '<script.yaml_key[config.%1%.rewards.type]>'
- ^inject locally ProcessReward_%rewardType%
ProcessReward_all:
- ^foreach <script.yaml_key[config.%1%.rewards.types]> {
- ^inject locally 'reward_%value%'
}
ProcessReward_single:
- ^inject locally 'reward_<proc[MobLoot_WeightedChoice].context[<script.yaml_key[config.%1%.rewards.types].replace[li@]>]>'
#
# END Event Processors
#
#--------------------------------------
#
# Reward Functions
#
reward_money:
- ^define range '<script.yaml_key[config.%1%.rewards.money].split[/]>'
- ^define money '<util.random.decimal[<def[range].get[1]>].to[<def[range].get[2]>].as_money>'
- ^give money 'qty:%money%'
reward_xp:
- ^define range '<script.yaml_key[config.%1%.rewards.xp].split[/]>'
- ^define xp '<util.random.int[<def[range].get[1]>].to[<def[range].get[2]>]>'
- ^drop xp %2% 'qty:%xp%'
reward_item:
- ^define itemList 'li@'
- ^foreach <script.list_keys[config.%1%.rewards.items]> {
- define itemList '<def[itemList].include[<script.yaml_key[config.%1%.rewards.items.%value%.weight]>/%value%]>'
}
- ^define item '<proc[MobLoot_WeightedChoice].context[%itemList%]>'
- ^define range '<script.yaml_key[config.%1%.rewards.items.%item%.range].split[/]>'
- ^drop i@%item% %2% 'qty:<util.random.int[<def[range].get[1]>].to[<def[range].get[2]>]>'
#
# END Reward Functions
#
#--------------------------------------
################################################################################
#
# Weighted Random Choice Generator
#
# Supply a list of weight/return values and have one of the values returned to
# you randomly based on weight.
#
# - Usage: <proc[MobLoot_WeightedChoice].context[weight/return|...]>
#
# Weight: A numeric weight value
# Return: The value the procedure should return if this weight is chosen
#
MobLoot_WeightedChoice:
type: procedure
debug: true
script:
- define list 'li@'
- foreach <queue.definitions.exclude[list]> {
- define list '<def[list].include[<def[%value%]>]>'
}
- define weight '0'
- foreach <def[list].parse[split[/].get[1]]> {
- define weight '<def[weight].add[%value%]>'
}
- define number '<util.random.int[1].to[%weight%]>'
- define highValue '0'
- foreach %list% {
- define oldValue '%highValue%'
- define lowValue '<def[oldValue].add[1]>'
- define highValue '<def[oldValue].add[<def[value].split[/].get[1]>]>'
- if %number% >= %lowValue% && %number% <= %highValue% {
- determine '<def[value].split[/].get[2]>'
}
}
#
View History