Date: 2015/01/24 10:37:56 UTC-08:00
Type: Denizen 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
365
366
367
368
369
370
371
372
373
374
375
# +----------------------------------
# | Lock Pick
# +----------------------------------
Lock_Pick:
type: item
material: LEVER
display name: <blue>Lock Pick<&r>
no_id: false
recipe:
- i@air|i@tripwire_hook|i@air
- i@air|i@iron_ingot|i@air
- i@air|i@air|i@air
Key:
type: item
material: LEVER
display name: <gold>Key<&r>
lore:
- <black>K<util.random.uuid><&r>
no_id: false
recipe:
- i@air|i@tripwire_hook|i@air
- i@air|i@gold_ingot|i@air
- i@air|i@air|i@air
# +----------------------------------
# | Locks
# +----------------------------------
Basic_Lock:
type: item
material: NAME_TAG:1
display name: <green>Basic Lock <dark_red>(No Key)
no_id: true
recipe:
- i@air|i@air|i@air
- i@air|i@iron_block|i@iron_ingot
- i@air|i@air|i@air
Advanced_Lock:
type: item
material: NAME_TAG:2
display name: <aqua>Advanced Lock <dark_red>(No Key)
no_id: true
recipe:
- i@air|i@air|i@air
- i@iron_ingot|i@iron_block|i@iron_ingot
- i@air|i@air|i@air
Strong_Lock:
type: item
material: NAME_TAG:3
display name: <&5>Strong Lock <dark_red>(No Key)
#no_id: true
recipe:
- i@air|i@iron_ingot|i@air
- i@iron_ingot|i@iron_block|i@iron_ingot
- i@air|i@air|i@air
Tough_Lock:
type: item
material: NAME_TAG:4
display name: <gold>Tough Lock <dark_red>(No Key)
no_id: true
recipe:
- i@air|i@iron_ingot|i@air
- i@iron_ingot|i@iron_block|i@iron_ingot
- i@air|i@iron_ingot|i@air
Fine_Lock:
type: item
material: NAME_TAG:5
display name: <&2>Tough Lock <dark_red>(No Key)
no_id: true
recipe:
- i@iron_ingot|i@iron_ingot|i@iron_ingot
- i@iron_ingot|i@iron_block|i@iron_ingot
- i@air|i@iron_ingot|i@air
Master_Lock:
type: item
material: NAME_TAG:6
display name: <&4>Master Lock <dark_red>(No Key)
no_id: true
lore:
- <&7>Unpickable<&r>
- <&7>Can only be opened<&r>
- <&7>with the right key<&r>
recipe:
- i@gold_ingot|i@gold_ingot|i@gold_ingot
- i@gold_ingot|i@gold_block|i@gold_ingot
- i@gold_ingot|i@gold_ingot|i@gold_ingot
Load_Locks:
type: task
Script:
- if <server.has_file[Lock_Data.yml]> {
- yaml "load:/Data/Lock_Data.yml" id:Lock_D
- narrate "<dark_green>Loading <gold>Lock Data"
} else {
- yaml create id:Lock_D
- narrate "<red>Couldn't find Data file."
- narrate "<dark_green>Creating new <gold>Lock Data <dark_green>file"
- yaml id:Lock_D set Statistics.Locks.Picked:0
- yaml id:Lock_D set Statistics.Locks.Chest:0
- yaml id:Lock_D set Statistics.Locks.Doors:0
- wait 10s
- yaml "savefile:/Data/Lock_Data.yml" id:Lock_D
}
Save_Locks:
type: task
Script:
- yaml "savefile:/Data/Lock_Data.yml" id:Lock_D
- narrate "<dark_green>Saving <gold>Lock Data"
- run Save_Sarah delay:10m
# +----------------------------------
# | Lock System
# +----------------------------------
Lock_System:
type: world
events:
on player opens inventory:
- if <context.inventory.slot[1].display.contains[Lock]> {
- if <context.inventory.slot[1].display.contains[(Locked)]> && <context.inventory.slot[1].material> == m@name_tag,1 && <player.item_in_hand> != i@Key && <player.item_in_hand> != i@Lock_Pick {
- narrate "<red>This chest is locked."
- determine cancelled
}
- if <player.item_in_hand> == i@Key {
# Check if it's unlocked
- if <context.inventory.slot[1].display.contains[(Unlocked)]> && <context.inventory.slot[1].material> == m@name_tag,1 {
# Check if key matches
- if <context.inventory.slot[1].contains[<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>]> {
- determine passively cancelled
- if <context.inventory.slot[1].contains[Basic]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Basic<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Advanced]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Advanced<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Strong]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Strong<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Tough]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Tough<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Fine]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Fine<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Master]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Master<&sp>Lock<&sp><red>(Locked)" save:Lock_Item
- inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
- wait 1t
- give <entry[Lock_Item].result> to:<context.inventory> slot:1
- narrate "<red>Locked Chest"
} else {
- narrate "<dark_red>This key doesn't fit."
- determine cancelled
}
} else if <context.inventory.slot[1].display.contains[(Locked)]> && <context.inventory.slot[1].material> == m@name_tag,1 {
# Check if key matches
- if <context.inventory.slot[1].contains[<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>]> {
- if <context.inventory.slot[1].contains[Basic]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Basic<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Advanced]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Advanced<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Strong]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Strong<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Tough]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Tough<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Fine]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Fine<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Master]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Master<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
- wait 1t
- give <entry[Lock_Item].result> to:<context.inventory> slot:1
- narrate "<green>Unlocked Chest"
} else {
- narrate "<dark_red>This key doesn't fit."
- determine cancelled
}
} else if <context.inventory.slot[1].contains[(No<&sp>Key)]> && <context.inventory.slot[1].material> == m@name_tag,1 {
- determine passively cancelled
- if <context.inventory.slot[1].contains[Basic]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Basic<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Advanced]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Advanced<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Strong]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Strong<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Tough]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Tough<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Fine]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Fine<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- if <context.inventory.slot[1].contains[Master]> adjust <context.inventory.slot[1]> "display_name:<dark_green>Master<&sp>Lock<&sp><green>(Unlocked)" save:Lock_Item
- inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
- wait 1t
- give <entry[Lock_Item].result> to:<context.inventory> slot:1
- adjust <context.inventory.slot[1]> "lore:<black>L<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>" save:Lock_Item
- inventory exclude d:<context.inventory> o:<context.inventory.slot[1]>
- wait 1t
- give <entry[Lock_Item].result> to:<context.inventory> slot:1
- narrate "<green>Key succesfully binded."
}
}
# end of checking for a lock
}
on player right clicks block:
- define loc <context.location.block>
- if <def[loc].material.name.ends_with[door]> {
- narrate "<red>Door Clicked"
- if <player.item_in_hand> == i@key || <player.item_in_hand> == i@Lock_Pick || <player.item_in_hand.contains[Lock]> {
# Check if it's a lock
- if <player.item_in_hand.contains[Lock]> && <player.item_in_hand.material.contains[name_tag]> {
- determine passively cancelled
# Check if the door already has a lock
- if <context.cuboids.formatted.contains[Lock]> {
- narrate "<red>This door already has a lock."
- queue clear
} else {
- if <player.item_in_hand.display.contains[Basic]> define Lock_Type Basic_Lock
- if <player.item_in_hand.display.contains[Advanced]> define Lock_Type Advanced_Lock
- if <player.item_in_hand.display.contains[Strong]> define Lock_Type Strong_Lock
- if <player.item_in_hand.display.contains[Tough]> define Lock_Type Tough_Lock
- if <player.item_in_hand.display.contains[Fine]> define Lock_Type Fine_Lock
- if <player.item_in_hand.display.contains[Master]> define Lock_Type Master_Lock
- if <player.item_in_hand.display.contains[(No<&sp>Key)]> define Lock_state No_Key
- if <player.item_in_hand.display.contains[(Unlocked)]> define Lock_state Unlocked
- if <player.item_in_hand.display.contains[(Locked)]> define Lock_state Locked
- define ID <yaml[Lock_D].read[Statistics.Locks.Doors]>
# Check if they clicked the bottom or top part of the door.
- if <player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]> != null define UUID <player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>
- if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
- if %LockState% == No_Key {
- note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(%Lock_state%)
} else {
- note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(%Lock_state%)_L%UUID%
}
} else {
- if %LockState% == No_Key {
- note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(%Lock_state%)
} else {
- note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(%Lock_state%)_L%UUID%
}
}
- narrate "<dark_green>Lock succesfully installed"
- yaml id:Lock_D set Statistics.Locks.Doors:++
- take <player.item_in_hand>
- queue clear
}
}
- if <player.item_in_hand> == i@key {
- narrate "Using a key"
- define UUID <player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>
# Check if there's a cuboid that contains the word "lock"
- if <context.cuboids.formatted.contains[Lock]> {
# Check if the cuboid has a UUID
- if <context.cuboids.formatted.contains[L<player.item_in_hand.lore.regex[.*(K)([a-zA-Z-\d+]+).*].group[2]>]> {
# Check if it's locked
- if <context.cuboids.formatted.contains[(Locked)]> {
# Check all cuboids (so we can find the one we want to change)
- foreach <context.cuboids> {
# finding the one that has lock in it
- if <def[%value%].contains[lock]> {
# removing it
- note remove as:%value%
# checking where on the door they clicked, to correctly make a new cuboid with a diferent lock_state
- if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
# making the new cuboid
- note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
} else {
- note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
}
}
- narrate "<dark_green>Unlocked Door"
- queue clear
}
# If it's not locked and it has the UUID of our key it must be unlocked, so we change it to a locked state
# same procedure as above, just locking instead of unlocking.
} else {
- foreach <context.cuboids> {
- if <def[%value%].contains[lock]> {
- note remove as:%value%
- if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
- note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(Locked)_L%UUID%
} else {
- note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(Locked)_L%UUID%
}
}
- narrate "<dark_red>Locked Door"
- queue clear
}
}
# If it doesn't have a UUID it must be a lock with no key attached.
} else {
- foreach <context.cuboids> {
- if <def[%value%].contains[lock]> {
- note remove as:%value%
- if <context.location.block.add[0,1,0].material.name.ends_with[door]> {
- note cu@<context.location.block>|<context.location.block.add[0,2,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
} else {
- note cu@<context.location.block.sub[0,-1,0]>|<context.location.block.add[0,1,0]> as:%ID%_%Lock_Type%_(Unlocked)_L%UUID%
}
}
}
- narrate "BIND LOCK HERE"
}
} else {
- queue clear
}
}
} else {
- queue clear
}
}
Lore_Test:
type: command
name: dlore
description: Denizen lore
usage: /lore test
script:
# Checking that they have exactly 1 argument (hopefully a playername.)
- adjust <player.item_in_hand> "lore:Advanced Item" save:myitem
- take iteminhand
- wait 1s
- give <entry[myitem].result>