- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





Staff Pick: Mob Loot


By Anthony
Created: 2015/06/15 11:16:40 UTC-07:00 (8 years and 342 days ago)
Edited: 2015/06/15 11:32:36 UTC-07:00 (8 years and 342 days ago)
Likes: 1

Staff pick as of: 2015/06/17 17:24:52 UTC-07:00 (8 years and 340 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
17400

################################################################################
#
#                              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