- 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: ChestGuard (Bodyguards)


By Mwthorn
Created: 2015/05/24 17:33:30 UTC-07:00 (9 years and 214 days ago)
Edited: 2015/05/27 06:14:19 UTC-07:00 (9 years and 212 days ago)
Likes: 1

Staff pick as of: 2015/05/24 18:39:41 UTC-07:00 (9 years and 214 days ago)
Denizen Version: 0.9.6
Script Version: 1.1
Description:

Written by Mwthorn

Credits for the original Bodyguards goes to Cromis
You can find that script here: http://mcmonkey.org/denizen/repo/entry/34

This version currently only has 1 bodyguard available. But this bodyguard have a "easier" way to give commands to.

Chest Guard is basically a bodyguard system (like the original). The main differences are that you are using a chest-inventory instead of the chat to give commands and orders to either the shop or your bodyguard(s).
This version for now allows you to have infinite bodyguards (which may be a problem for some servers) unless you change the price to a higher value.

REQUIREMENTS:
- All players MUST have the permission: citizens.npc.select
(I'll try to fix this requirement if possible in the future)
(If this permission is not added. No orders will function)

Though my version has its pros and cons... I basically wanted to use chest-inventory instead of using chat to send commands to a bodyguard (same goes with the shop)

Command to setup the shop:
/npc assignment --set ChestGuardMain



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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
36400

# Written by Mwthorn
#
# Credits for the original Bodyguards goes to Cromis
# You can find that script here: http://mcmonkey.org/denizen/repo/entry/34
#
# This version currently only has 1 bodyguard available. But this bodyguard have a "easier" way to give commands to.
#
# Chest Guard is basically a bodyguard system (like the original). The main differences are that you are using a chest-inventory instead of the chat to give commands and orders to either the shop or your bodyguard(s).
# This version for now allows you to have infinite bodyguards (which may be a problem for some servers) unless you change the price to a higher value.
#
# REQUIREMENTS:
# - All players MUST have the permission: citizens.npc.select
# (I'll try to fix this requirement if possible in the future)
# (If this permission is not added. No orders will function)
#
# Though my version has its pros and cons... I basically wanted to use chest-inventory instead of using chat to send commands to a bodyguard (same goes with the shop)
#
# Command to setup the shop:
# /npc assignment --set ChestGuardMain
#
# Version 1.1
ChestGuardEvents:
    type: world
    debug: false
    events:
    
        # Main events
        
        on player join:
            - if <player.has_flag[ChestGuardPlayerLimit]> {
                - narrate "<blue>You currently have <player.flag[ChestGuardPlayerLimit] bodyguards."
              } else {
                - flag player ChestGuardPlayerLimit:0
              }
        on player quit:
            - execute as_server "denizen save"
              
        on server starts:
            - execute as_server "denizen reload -a"
        on reload scripts:
            # How much it cost to buy the weak bodyguard.
            - flag server ChestGuardCost1:5000
            # The amount of Bodyguards allowed per player.
            - flag server ChestGuardLimit:1
            
        # Shop Menu
        
        on player clicks ChestGuardBuy1 in ChestGuardShop:
            - if <player.flag[ChestGuardPlayerLimit].as_int> >= <server.flag[ChestGuardLimit]> {
                - narrate "<red>You have reached the limit of bodyguards. (<server.flag[ChestGuardLimit]>)"
              } else {
                - if <player.money> < <server.flag[ChestGuardCost1]> {
                    - narrate "<red>You do not have enough money."
                    } else {
                    - take money qty:<server.flag[ChestGuardCost1]>
                    - flag player ChestGuardPlayerLimit:++
                    - ^execute as_server "npc create &aBodyGuard --at <player.location.x>:<player.location.y>:<player.location.z>:<player.location.world>"
                    - ^execute as_server "trait sentry"
                    - ^execute as_server "sentry equip STONE_SWORD"
                    - ^execute as_server "sentry equip LEATHER_HELMET"
                    - ^execute as_server "sentry equip LEATHER_CHESTPLATE"
                    - ^execute as_server "sentry equip LEATHER_LEGGINGS"
                    - ^execute as_server "sentry equip LEATHER_BOOTS"
                    - ^execute as_server "sentry respawn 120"
                    - ^execute as_server "sentry follow 3"
                    - ^execute as_server "sentry speed 1.5"
                    - ^execute as_server "sentry healrate 10"
                    - ^execute as_server "sentry health 20"
                    - ^execute as_server "sentry strength 5"
                    - ^execute as_server "sentry range 10"
                    - ^execute as_server "sentry target add entity:monster"
                    - ^execute as_server "sentry target add entity:slime"
                    - ^execute as_server "npc assignment --set ChestGuardBody1"
                    - ^execute as_server "npc owner <player.name>"
                    - ^execute as_server "sentry guard <player.name>"
                    - ^execute as_server "sentry ignore add player:<player.name>"
                    - ^narrate "<green>You have succesfully purchased a bodyguard!"
                    }
                }
            - determine cancelled
                
        on player clicks ChestGuardBuy2 in ChestGuardShop:
            - ^determine cancelled   
            
        on player clicks ChestGuardBuy3 in ChestGuardShop:
            - ^determine cancelled
        
        on player clicks ChestGuardClose in ChestGuardShop:
            - inventory close d:<context.inventory>
            - ^determine cancelled
        
        # Guard Menu
        
        on player clicks ChestGuardFollow in ChestGuardMenu:
            - execute as_player "npc select"
            - ^execute as_server "npc select <player.selected_npc.id>"
            - ^execute as_server "sentry guard <player.name>"
            - ^execute as_server "sentry follow 2"
            - ^execute as_server "sentry speed 1.4"
            - ^execute as_server "npc speed 1.4"
            - ^narrate "<green>The Guard is now following you."
            - ^inventory close d:<context.inventory>
            - ^determine cancelled
            
        on player clicks ChestGuardStand in ChestGuardMenu:
            - execute as_player "npc select"
            - ^execute as_server "npc select <player.selected_npc.id>"
            - ^execute as_server "sentry guard"
            - ^execute as_server "sentry spawn"
            - ^narrate "<green>The Guard will now stay at its current position."
            - ^inventory close d:<context.inventory>
            - ^determine cancelled
            
        on player clicks ChestGuardBow in ChestGuardMenu:
            - execute as_player "npc select"
            - ^execute as_server "npc select <player.selected_npc.id>"
            - ^execute as_server "sentry equip bow"
            - ^execute as_server "sentry attackrate 1.5"
            - ^execute as_server "sentry strength 4"
            - ^execute as_server "sentry range 25"
            - ^narrate "<green>The Guard will now use a bow."
            - ^inventory close d:<context.inventory>
            - ^determine cancelled
            
        on player clicks ChestGuardSword in ChestGuardMenu:
            - execute as_player "npc select"
            - ^execute as_server "npc select <player.selected_npc.id>"
            - ^execute as_server "sentry equip STONE_SWORD"
            - ^execute as_server "sentry strength 5"
            - ^execute as_server "sentry range 10"
            - ^narrate "<green>The Guard will now use a sword."
            - ^inventory close d:<context.inventory>
            - ^determine cancelled
            
        on player clicks ChestGuardRefresh in ChestGuardMenu:
            - execute as_player "npc select"
            - ^execute as_server "npc select <player.selected_npc.id>"
            - ^execute as_server "sentry equip STONE_SWORD"
            - ^execute as_server "sentry equip LEATHER_HELMET"
            - ^execute as_server "sentry equip LEATHER_CHESTPLATE"
            - ^execute as_server "sentry equip LEATHER_LEGGINGS"
            - ^execute as_server "sentry equip LEATHER_BOOTS"
            - ^execute as_server "sentry respawn 120"
            - ^execute as_server "sentry follow 3"
            - ^execute as_server "sentry speed 1.5"
            - ^execute as_server "sentry healrate 10"
            - ^execute as_server "sentry health 20"
            - ^execute as_server "sentry strength 5"
            - ^execute as_server "sentry range 10"
            - ^execute as_server "sentry target add entity:monster"
            - ^execute as_server "sentry target add entity:slime"
            - ^execute as_server "npc assignment --set ChestGuardBody1"
            - ^execute as_server "sentry guard <player.name>"
            - ^execute as_server "sentry ignore add player:<player.name>"
            - ^narrate "<green>Guard succesfully updated!"
            - ^inventory close d:<context.inventory>
            - ^determine cancelled
            
        ## Flag npc ??
           
            # - if <npc.flag[Guarding]> == true {
                # - ^flag player.selected_npc "Guarding:false"
                # - ^execute as_server "sentry guard"
                # - ^execute as_server "sentry spawn"
                # - ^narrate "<green>The Guard will now stay at its current position."
            # } else {
                # - ^flag player.selected_npc "Guarding:true"
                # - ^execute as_server "sentry guard <player.name>"
                # - ^narrate "<green>The Guard is now following you."
            # }
        ##
        
        on player clicks ChestGuardRemove in ChestGuardMenu:
            - inventory close d:<context.inventory>
            - ^inventory open d:in@ChestGuardConfirm1
            - ^determine cancelled
            
        on player clicks ChestGuardClose in ChestGuardMenu:
            - inventory close d:<context.inventory>
            - ^determine cancelled
        
        on player clicks ChestGuardNo in ChestGuardConfirm1:
            - inventory close d:<context.inventory>
            - ^inventory open d:in@ChestGuardMenu
            - ^determine cancelled
            
        # Confirm menu
        
        on player clicks ChestGuardYes in ChestGuardConfirm1:
            - execute as_player "npc select"
            - ^execute as_server "npc select <player.selected_npc.id>"
            - ^execute as_server "npc remove"
            - flag player ChestGuardPlayerLimit:--
            - give money qty:<server.flag[ChestGuardCost1].div[2]>
            - ^narrate "<green>The Guard has been removed and you have been refunded <&ds><server.flag[ChestGuardCost1].div[2]>."
            - ^inventory close d:<context.inventory>
            - ^determine cancelled
            
        on player clicks ChestGuardClose in ChestGuardConfirm1:
            - inventory close d:<context.inventory>
            - ^determine cancelled
            

ChestGuardMain:
    type: assignment
    debug: false
    interact scripts:
    - 10 ChestGuardSales
    
ChestGuardSales:
    type: interact
    steps:
        1:
            click trigger:
                script:
                - ^narrate "<green><npc.name>: Hello <player.name> Welcome to my shop."
                - ^inventory open d:in@ChestGuardShop
                
ChestGuardBody1:
    type: assignment
    debug: false
    interact scripts:
    - 10 ChestGuardOrders
    
ChestGuardOrders:
    type: interact
    steps:
        1:
            click trigger:
                script:
                - ^if <npc.owner> != <player> {
                    - ^narrate "<green>Sorry. I'm not your owner."
                  } else {
                    - ^narrate "<green>What would you like me to do?"
                    - ^inventory open d:in@ChestGuardMenu
                  }
                  
ChestGuardShop: 
  type: inventory 
  inventory: CHEST
  title<red>Bodyguard Shop Menu
  size: 9 
  definitions: 
    Weak: i@ChestGuardBuy1
    Medium: i@ChestGuardBuy2
    Heavy: i@ChestGuardBuy3
    Close: i@ChestGuardClose
  slots: 
    - "[Weak] [Medium] [Heavy] [] [] [] [] [] [Close]" 
    
ChestGuardMenu: 
  type: inventory 
  inventory: CHEST
  title<red>Bodyguard Menu
  size: 9 
  definitions: 
    Follow: i@ChestGuardFollow
    Stand: i@ChestGuardStand
    Close: i@ChestGuardClose
    Sword: i@ChestGuardSword
    Remove: i@ChestGuardRemove
    Update: i@ChestGuardRefresh
    Bow: i@ChestGuardBow
  slots: 
    - "[Follow] [Stand] [Sword] [Bow] [] [] [Update] [Remove] [Close]" 
    
ChestGuardConfirm1: 
  type: inventory 
  inventory: CHEST
  title<red>Remove bodyguard?
  size: 9 
  definitions: 
    Accept: i@ChestGuardYes
    Decline: i@ChestGuardNo
    Close: i@ChestGuardClose
  slots: 
    - "[Accept] [] [] [] [Close] [] [] [] [Decline]" 
    
ChestGuardClose:
    type: item
    material: BARRIER
    display name<green>Close
    lore:
    - <yellow>Closes the menu.
    
ChestGuardBuy1:
    type: item
    material: IRON_INGOT
    display name<green>Weak Bodyguard
    lore:
    - <yellow>Costs <&ds><server.flag[ChestGuardCost1]>
    
ChestGuardBuy2:
    type: item
    material: GOLD_INGOT
    display name<red>Comming Soon
    lore:
    - <yellow>Work in progress...
    
ChestGuardBuy3:
    type: item
    material: DIAMOND
    display name<red>Comming Soon
    lore:
    - <yellow>Work in progress...
    
ChestGuardFollow:
    type: item
    material: WOOD_PLATE
    display name<green>Follow
    lore:
    - <yellow>Makes the guard follow you.

ChestGuardStand:
    type: item
    material: STONE_PLATE
    display name<green>Hold
    lore:
    - <yellow>Makes the guard stand still.
    
ChestGuardBow:
    type: item
    material: BOW
    display name<green>Bow
    lore:
    - <yellow>Makes the guard equip a bow.
    
ChestGuardSword:
    type: item
    material: STONE_SWORD
    display name<green>Sword
    lore:
    - <yellow>Makes the guard equip a sword.
    
ChestGuardRemove:
    type: item
    material: PAPER
    display name<green>Dismiss
    lore:
    - <yellow>Permanently removes the guard.
    - <yellow>Refunds half the price. (<&ds><server.flag[ChestGuardCost1].div[2]>)
    
ChestGuardRefresh:
    type: item
    material: REDSTONE
    display name<green>Refresh
    lore:
    - <yellow>Updates your guard.
    
ChestGuardYes:
    type: item
    material: EYE_OF_ENDER
    display name<green>Yes
    lore:
    - <yellow>Accept
    
ChestGuardNo:
    type: item
    material: ENDER_PEARL
    display name<green>No
    lore:
    - <yellow>Decline






View History