- 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: MobSpawn Limit Manager


By Anthony
Created: 2015/02/03 14:49:15 UTC-08:00 (9 years and 92 days ago)
Edited: 2015/02/03 14:49:45 UTC-08:00 (9 years and 92 days ago)
Likes: 2

Staff pick as of: 2015/02/03 18:31:29 UTC-08:00 (9 years and 91 days ago)
Denizen Version: 0.9.4-b1518
Script Version: 1.0
Description:

A system for controlling how many mobs are able to spawn per chunk in each world.


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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
25900

################################################################################
#                                                                              #
#                  M o b S p a w n   L i m i t   M a n a g e r                 #
#                                                                              #
#   Author: |Anthony|                                                          #
#   Version: 0.1                                                               #
#   dScript Version: 0.9.4-b1518                                               #
#                                                                              #
#                                                                              #
# A system for controlling how many mobs are able to spawn per chunk in each   #
# world. Will autogenerate the default config file on first run. Read the help #
# file in game with /mslimit                                                   #
#                                                                              #
# Permission: denizen.mslimit                                                  #
#                                                                              #
# Features a dynamic command handler. Command arguments can be supplied in any #
# order. Syntax checking and error handling included.                          #
#                                                                              #
# Example: Set the ambient mob type limit to 3 in the world named World        #
#   /mslimit -s -w World -t ambient -l 3                                       #
#                                                                              #
################################################################################


'MobSpawnManager_Configurations':
  type: task
  debug: false


  # These are the default values. You can edit them... but it's all
  # configurable from in game so why bother.
  ambient: 5
  animal: 15
  monster: 30
  water_animal: 2


################################################################################
#
# This is the meat and potatoes of this script. You really shouldn't touch 
# ANYTHING beyond this point unless you really know wtf you're doing!
#

'MobSpawnManagerTasks':
  type: task
  debug: false

  script:
    - narrate "HEY! Why does monkeybot give me a warning if I don<&sq>t have a script subscript path!?!"

  config:
    - define readID 'MobSpawnManager'
    - define basePath '<def[readID]>_Configurations'
    - define scriptPath '<script.relative_filename>'
    - yaml 'load:<def[scriptPath]>' 'id:<def[basePath]>'
    - define keylist '<yaml[<def[basePath]>].list_keys[<def[basePath]>].exclude[type|debug|script]>'
    - announce to_console "MobSpawnManager<&co> Generating default config file..."
    - yaml create 'id:%readID%'
    - foreach <server.list_worlds> {
      - define world <def[value]>
      - announce to_console "MobSpawnManager<&co> Found world <def[world].name>"
      - foreach %keylist% {
        - define key %value%
        - define entry '<yaml[%basePath%].read[%basePath%.%key%]>'
        - yaml 'write:%readID%.<def[world].name.to_lowercase>.<def[key].to_lowercase>' 'value:%entry%' 'id:%readID%'
        - adjust <def[world].as_world> %key%_spawn_limit:%entry%
        }
      }
    - yaml 'savefile:%readID%/config.yml' 'id:%readID%'
    - yaml unload 'id:%readID%'
    - announce to_console "MobSpawnManager<&co> Done!"
    - yaml unload 'id:%basePath%'

  load:
    - announce to_console "MobSpawnManager<&co> Loading config file..."
    - define readID 'MobSpawnManager'
    - yaml 'load:%readID%/config.yml' 'id:%readID%'
    - define worlds '<yaml[%readID%].list_keys[%readID%]>'
    - foreach %worlds% {
      - define world %value%
      - define types '<yaml[%readID%].list_keys[%readID%.%world%]>'
      - foreach %types% {
        - define type %value%
        - define limit '<yaml[%readID%].read[%readID%.%world%.%type%]>'
        - adjust <def[world].as_world> %type%_spawn_limit:<def[limit]>
        }
      }
    - announce to_console "MobSpawnManager<&co> Done!"

  set:
    - define worlds <server.list_worlds>
    - if %world% != null {
      - if !<def[worlds].contains[<def[world].as_world>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[world]> <&b>does not exist"
        - queue stop
        }
      }
      else {
      - narrate "<&4><&l>ERROR<&co><&r> <&b>Must specify a world"
      - narrate format:CmdSynFormat "/mslimit -w \<&lt\>world\<&gt\>"
      - queue stop
      }

    - define types 'ambient|animal|monster|water_animal'
    - if %type% != null {
      - if !<def[types].as_list.contains[<def[type]>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[type]> <&b>is not a valid type"
        - queue stop
        }
      }
      else {
      - narrate "<&4><&l>ERROR<&co><&r> <&b>Must specify a type"
      - narrate format:CmdSynFormat "/mslimit -t \<&lt\>type\<&gt\>"
      - queue stop
      }

    - if %limit% != null {
      - if !<def[limit].is[matches].to[integer]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[limit]> <&b>is not a valid number"
        - queue stop
        }
      - define limit <def[limit].abs.as_int>
      }
      else {
      - narrate "<&4><&l>ERROR<&co><&r> <&b>Must specify a limit"
      - narrate format:CmdSynFormat "/mslimit -l \<&lt\>limit\<&gt\>"
      - queue stop
      }

    - define readID 'MobSpawnManager'
    - yaml 'load:%readID%/config.yml' 'id:%readID%'
    - yaml 'write:%readID%.<def[world].to_lowercase>.<def[type].to_lowercase>' 'value:%limit%' 'id:%readID%'
    - adjust <def[world].as_world> %type%_spawn_limit:<def[limit]>
    - yaml 'savefile:%readID%/config.yml' 'id:%readID%'
    - yaml unload 'id:%readID%'
    - narrate "<&b><def[type].to_titlecase> <&a>Spawn Limit set to <&b>%limit%<&a> for <&a><def[world].as_world.name><&b>."

  list:
    - define worlds <server.list_worlds>
    - if %world% != null {
      - if !<def[worlds].contains[<def[world].as_world>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[world]> <&b>does not exist"
        - queue stop
        }
      - define worlds <def[world].as_world>
      }
    - define types 'ambient|animal|monster|water_animal'
    - if %type% != null {
      - if !<def[types].as_list.contains[<def[type]>]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a><def[type]> <&b>is not a valid type"
        - queue stop
        }
      - define types <def[type]>
      }
    - foreach <def[worlds].as_list> {
      - define world %value%
      - narrate ""
      - narrate "<&e><&l><def[world].name><&r><&6> Spawn Limits"
      - foreach <def[types].as_list> {
        - narrate "<&sp><&sp><&sp><&b><def[value].to_titlecase><&co> <&a><def[world].<def[value]>_spawn_limit>"
        }
      }
    - narrate ""

  help:
    - narrate ""
    - narrate "<&b>========== <&a>MobSpawnLimit Help <&b>=========="
    - narrate ""
    - narrate "A system for controlling how many mobs are able to spawn per chunk in each world."
    - narrate ""
    - narrate ""
    - narrate "<&b>Setting Limits"
    - narrate "<&sp>Sets the mobspawn limit. Must specify a valid world, type, and number"
    - narrate "<&sp><&sp><&sp><&e>/mslimit -s"
    - narrate "<&sp><&sp><&sp><&e>/mslimit --set"
    - narrate ""
    - narrate "<&b>Listing Limits"
    - narrate "<&sp>Shows a list of current limits. Can be filtered by world and/or type"
    - narrate "<&sp><&sp><&sp><&e>/mslimit -ls"
    - narrate "<&sp><&sp><&sp><&e>/mslimit --list"
    - narrate ""
    - narrate "<&b>Options"
    - narrate "<&sp><&a>World"
    - narrate "<&sp><&sp><&sp><&e>-w \<worldname\>"
    - narrate "<&sp><&a>Type"
    - narrate "<&sp><&sp><&sp><&e>-t \<type\>"
    - narrate "<&sp><&sp><&sp>Valid types<&co> <&a>ambient animal monster water_animal"
    - narrate "<&sp><&a>Limit"
    - narrate "<&sp><&sp><&sp><&e>-l \<limit\>"
    - narrate "<&sp><&a>Reset<&f> - Reset all worlds to default limits"
    - narrate "<&sp><&sp><&sp><&e>--reset"
    - narrate "<&sp><&a>Reload<&f> - Reloads the config file"
    - narrate "<&sp><&sp><&sp><&e>--reload"
    - narrate ""
    - narrate format:CmdSynFormat "/mslimit <&6>\<&lt\><&e>--set / -s<&6>\<&gt\> \<&lb\><&e>-w worldname -t type -l limit<&6>\<&rb\>"
    - narrate format:CmdSynFormat "/mslimit <&6>\<&lt\><&e>--list / -ls<&6>\<&gt\> \<&lt\><&e>-w worldname -t type -l limit<&6>\<&gt\>"
    - narrate ""

################################################################################
#
# Handles the commands and server start
#

'MobSpawnManagerEvents':
  type: world
  debug: true
  events:

    on mslimit command:
# The command handler. Accepts the command and passes the info to the task scripts
    - if !<player.has_permission[denizen.mslimit]> queue stop
    - determine passively fulfilled
    - define reset '<c.args.contains[--reset] || false>'
    - define reload '<c.args.contains[--reload] || false>'
    - define list '<tern[<context.args.contains[-ls]>]:true||<tern[<context.args.contains[--list]>]:true||false>>'
    - define set '<tern[<context.args.contains[-s]>]:true||<tern[<context.args.contains[--set]>]:true||false>>'
    - define world '<tern[<c.args.find[-w].is[MORE].than[0]>]:<c.args.get[<c.args.find[-w].add[1].as_int>].escaped> || null>'
    - define type '<tern[<c.args.find[-t].is[MORE].than[0]>]:<c.args.get[<c.args.find[-t].add[1].as_int>].escaped> || null>'
    - define limit '<tern[<c.args.find[-l].is[MORE].than[0]>]:<c.args.get[<c.args.find[-l].add[1].as_int>].escaped> || null>'

    - if %list% == true {
      - inject s@MobSpawnManagerTasks p:list
      - queue stop
      }

    - if %set% == true {
      - inject s@MobSpawnManagerTasks p:set
      - queue stop
      }

    - if %reset% == true {
      - inject s@MobSpawnManagerTasks p:config
      - queue stop
      }

    - if %reload% == true {
      - inject s@MobSpawnManagerTasks p:load
      - queue stop
      }

    - if <context.args.is_empty> {
      - inject s@MobSpawnManagerTasks p:help
      - queue stop
      }

    - inject s@MobSpawnManagerTasks p:help


    on server start:
# Checks if the config file exists on server start and reads or generates it.
    - define readID 'MobSpawnManager'
    - if <server.has_file[%readID%/config.yml]> {
      - run s@MobSpawnManagerTasks p:load delay:2s
      }
      else {
      - run s@MobSpawnManagerTasks p:config delay:2s
      }






View History