-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJSentry.yml
More file actions
750 lines (720 loc) · 33.3 KB
/
JSentry.yml
File metadata and controls
750 lines (720 loc) · 33.3 KB
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# +---------------
# |
# | J S e n t r y
# |
# | Sentry rescripted in Denizen!
#
# @ Based on dSentry script from mcmonkey, but optimised for use with Bossfight script.
# @ Bugs fixed, and improvements made by Jabelpeeps (many of which have been included in dSentry)
# @date 2014 / 12 / 08
# @version 1.1
#
# Installation:
# Just copy this script to your Denizen/scripts folder, and do '/denizen reload scripts'
#
# Usage:
# Create NPCs as normal, and use the /jsentry commands to upgrade them.
# Example NPC setup path:
# /npc create JoeTheKiller # Create and spawn the NPC
# /jsentry create # Turn it into a jsentry
# /ex equip <npc> hand:bow # Give the jsentry a bow
#
# NB The default JSentry does not have the health trait set, as this is handled in the Bossfight script.
# If you wish to enable it there are sections below that you will need to uncomment.
#
# ---------------------------- END HEADER ----------------------------
# Handles all world events for jsentry
jsentry_world_handler:
type: world
debug: false
events:
on server start:
- inject locally "events.on reload scripts"
on reload scripts:
# loads/create yml save file, and starts main logic loop
- if <yaml.list> !contains jsentry_saves {
- if <server.has_file[jsentry_saves.yml]> {
- yaml load:jsentry_saves.yml id:jsentry_saves
}
else {
- yaml create id:jsentry_saves
}
}
# stops previous jsentry_task_logic task, if it is already running, and starts a new one.
- define queues <queue.list.filter[starts_with[jsentry_task_logic]]>
- foreach %queues% {
- queue %value% stop
}
- wait 5s
- run s@jsentry_task_logic instantly
# # uncomment this section to activate the health trait.
# - foreach <server.get_npcs_flagged[dsentry.is_dsentry]> {
# - if <def[value].is_spawned]> {
# - vulnerable npc:%value%
# - health <def[value].flag[dsentry.health]> npc:%value%
# }
# }
# on npc spawns:
# - if !<npc.has_flag[jsentry.is_jsentry]> queue clear
# - vulnerable
# - health <npc.flag[jsentry.health]>
# - heal <npc>
# # detects PvP and (if listed in jsentry.eventtargets) adds the aggressor to the target list of dSentries in range.
# on player damaged by player:
# - foreach <server.get_npcs_flagged[jsentry.is_jsentry]> {
# - if <def[value].is_spawned> && <def[value].flag[jsentry.target]||null> == null
# && <def[value].flag[jsentry.eventtargets].as_list||li@> contains PvP
# && <def[value].location.distance[<context.damager.location>]> < <def[value].flag[jsentry.range]> {
# - flag <def[value]> jsentry.target:<context.damager>
# }
# }
# # detects PvE and (if listed in jsentry.eventtargets) adds the aggressor to the target list of dSentries in range.
# on entity damaged by player:
# - if <context.entity> matches player queue clear
# - if <context.entity> matches npc queue clear
# - foreach <server.get_npcs_flagged[jsentry.is_jsentry]> {
# - if <def[value].is_spawned> && <def[value].flag[jsentry.target]||null> == null
# && <def[value].flag[jsentry.eventtargets].as_list||li@> contains PvE
# && <def[value].location.distance[<context.damager.location>]> < <def[value].flag[jsentry.range]> {
# - flag <def[value]> jsentry.target:<context.damager>
# }
# }
# adds any player who attacks a jsentry to the the jsentry's target flag.
on npc damaged by player:
- if <npc.has_flag[jsentry.is_jsentry]> flag <context.entity> jsentry.target:<context.damager>
# adjusts damage taken by dSentries according to their armour values (either configured or calculated)
on npc damaged by entity:
- if !<context.entity.has_flag[jsentry.is_jsentry]> queue clear
- if <npc.flag[jsentry.targets].as_list> !contains <context.damager.entity_type> determine cancelled
- define armour <proc[jsentry_proc_calculatearmour]> npc:<context.entity>
- determine <el@val[1].sub[%armour%].mul[<context.damage>].as_int>
# adjusts damage dealt by dSentries to the value in jsentry.damage
on npc damages entity:
- if !<context.damager.has_flag[jsentry.is_jsentry]> queue clear
- determine <proc[jsentry_proc_calculatedamage]> npc:<context.damager.as_npc>
# handles the numerous options for the jsentry command.
jsentry_command:
type: command
debug: false
name: jsentry
description: Base command to allow creation and customisation of JSentries.
usage: /jsentry (create|save|range|followrange|speed|attackrate|damage|add|remove|info|guard|armour|uncreate)
permission: jsentry.command
tab complete:
- determine <li@create|save|range|followrange|speed|attackrate|damage|add|remove|info|guard|armour|uncreate.filter[starts_with[<context.args.last>]]>
script:
# defines %mynpc% according to the context.
- if <context.server> {
- define mynpc <server.selected_npc>
}
else {
- define mynpc <player.selected_npc>
}
# gives error if no npc selected, yet a sub-command is given.
- if %mynpc% == null && <context.args.get[1].length||0> != 0 {
- narrate "<&6>You do not have an NPC selected!"
- queue clear
}
# gives error if a sub-command other than 'create' is given if the npc is not already a jsentry.
- if !<def[mynpc].has_flag[jsentry.is_jsentry]> && <context.args.get[1].length||0> != 0 && !<context.args.get[1].is[==].to[create]||false> {
- narrate "<&6>Your selected NPC is not a jsentry!"
- queue clear
}
# runs appropriate script for each sub-command, or if no-recognised sub-command is given, narrates a list of them.
- define arg1 <c.args.get[1].escaped||null>
- define argList li@create|save|range|followrange|speed|attackrate|damage|add|remove|info|guard|armour|uncreate
- if <def[argList].contains[%arg1%]> inject locally jsentry_command_%arg1%
else {
- narrate "<&6>/jsentry info"
- narrate "<&6>/jsentry create [save-type]"
- narrate "<&6>/jsentry save <<>save-type<>>"
- narrate "<&6>/jsentry range <<>range<>>"
- narrate "<&6>/jsentry followrange <<>range<>>"
- narrate "<&6>/jsentry speed <<>speed<>>"
- narrate "<&6>/jsentry damage <<>damage<>>"
- narrate "<&6>/jsentry attackrate <<>attackrate<>>"
- narrate "<&6>/jsentry armour <<>armour<>>"
- narrate "<&6>/jsentry add <<>target<>>"
- narrate "<&6>/jsentry remove <<>target<>>"
- narrate "<&6>/jsentry guard [player/npc-name]"
- narrate "<&6>/jsentry uncreate <<>npc-name<>>"
- narrate "<&6>Do a sub-command without arguments for further help"
}
# Info command - provides formatted information about a jsentry
jsentry_command_info:
- narrate "<&6>Your selected NPC <&2>is<&6> a JSentry with stats<&co>"
- narrate "<&6>Range<&co> <&b><def[mynpc].flag[jsentry.range]>"
- narrate "<&6>Damage<&co> <&b><def[mynpc].flag[jsentry.damage]>"
- if '<def[mynpc].flag[jsentry.armour]>' >= 0 {
- narrate "<&6>Armour<&co> <&b><def[mynpc].flag[jsentry.armour].mul[100].as_int>% (User defined)"
}
else {
- define ArmourCalc <proc[jsentry_proc_calculatearmour]> npc:%mynpc%
- narrate "<&6>Armour<&co> <&b><def[ArmourCalc].mul[100].as_int>% (Calculated value)"
}
- narrate "<&6>Walk speed<&co> <&b><def[mynpc].flag[jsentry.walkspeed]>"
- narrate "<&6>Attack rate<&co> <&b><def[mynpc].flag[jsentry.attackrate]>"
- if <def[mynpc].flag[jsentry.flagtargets].size||0> == 0 {
- narrate "<&6>Targets<&co> <&b><def[mynpc].flag[jsentry.targets].formatted||None>"
}
else {
- narrate "<&6>Targets<&co> <&b><def[mynpc].flag[jsentry.targets].formatted||None><&6>, or players flagged <&b><def[mynpc].flag[jsentry.flagtargets].formatted||None>"
}
# added a line to show who jsentry is guarding
- if <def[mynpc].has_flag[jsentry.guard_target]> {
- narrate "<&6>Currently Guarding<&co> <&b><def[mynpc].flag[jsentry.guard_target].as_entity.name||null>"
}
# Guard command - gives npc's targets to guard (i.e. they will defend if the target is attacked)
jsentry_command_guard:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&c>Add a Player or NPC name for this jsentry to guard."
- queue clear
}
- if <util.player_is_valid[<context.args.get[2].escaped>]> {
- define player <player[<context.args.get[2].escaped>]||null>
- if %player% == null {
- narrate "<&c>Unknown player or npc."
- queue clear
}
- flag %mynpc% jsentry.guard_target:%player%
- narrate "<&c>Guarding <&b><def[player].name><&c>!"
}
else if <util.npc_is_valid[<context.args.get[2].escaped>]> {
- define npc <npc[<context.args.get[2].escaped>]||null>
- if %npc% == null {
- narrate "<&c>Unknown player or npc."
- queue clear
}
- flag %mynpc% jsentry.guard_target:%npc%
- narrate "<&c>Guarding <&b><def[npc].name><&c>!"
}
else {
- narrate "<&c>Unknown player or npc."
- queue clear
}
# Add command - adds entity types, flags or event perpetrators (PvP or PvE) to a jsentry's list of possible targets.
jsentry_command_add:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry add <<>target<>>"
- narrate "<&6>Target = an entity type, EG creeper or pig"
- narrate "<&6>You can also do flagged:<<>FlagName<>>"
# - narrate "<&6>or event:PvP, or event:PvE"
- queue clear
}
# section deals with adding flag targets
- if <context.args.get[2].starts_with[flagged<&co>]> {
- if <def[mynpc].flag[jsentry.flagtargets].contains[<context.args.get[2].replace[flagged<&co>]>]||false> {
- narrate "<&6>That flag target is already set."
- queue clear
}
- flag %mynpc% jsentry.flagtargets:->:<context.args.get[2].replace[flagged<&co>]>
- narrate "<&6>Flag target added."
- queue clear
}
# # section deals with adding event targets
# - if <context.args.get[2].starts_with[event<&co>]> {
# - if <def[mynpc].flag[jsentry.eventtargets].contains[<context.args.get[2].replace[event<&co>]>]> {
# - narrate "<&6>That event target is already set."
# - queue clear
# }
# - if 'PvP|PvE' !contains <context.args.get[2].replace[event<&co>]> {
# - narrate "<&6>jsentry only accepts PvP or PvE as event targets"
# - queue clear
# }
- flag %mynpc% jsentry.eventtargets:->:<context.args.get[2].replace[event<&co>]>
- narrate "<&6>Event target added."
- queue clear
}
# section deals with adding entity type targets
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That target doesn't look like a proper entity type."
- queue clear
}
- if <def[mynpc].flag[jsentry.targets].contains[<context.args.get[2]>]||false> {
- narrate "<&6>That target is already set."
- queue clear
}
- flag %mynpc% jsentry.targets:->:<context.args.get[2]>
- if <def[mynpc].flag[jsentry.targets].contains[none]> flag %mynpc% jsentry.targets:<-:none
- narrate "<&6>Added target."
# Remove command - removes entity types, flags or event perpetrators (PvP or PvE) from a jsentry's list of targets.
jsentry_command_remove:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry remove <<>target<>>"
- narrate "<&6>Target = an entity type, EG creeper or pig"
- narrate "<&6>You can also do flagged:<<>FlagName<>>"
# - narrate "<&6>or event:PvP, or event:PvE"
- queue clear
}
# section deals with removing flag targets
- if <context.args.get[2].starts_with[flagged<&co>]> {
- if <context.args.get[2].contains[clearall]> {
- flag %mynpc% jsentry.flagtargets:!
- narrate "<&6>All flag targets cleared."
- queue clear
}
- if !<def[mynpc].flag[jsentry.flagtargets].contains[<context.args.get[2].replace[flagged<&co>]>]||false> {
- narrate "<&6>That flag target isn't set."
- queue clear
}
- flag %mynpc% jsentry.flagtargets:<-:<context.args.get[2].replace[flagged<&co>]>
- narrate "<&6>Flag target removed."
- queue clear
}
# # section deals with removing event targets
# - if <context.args.get[2].starts_with[event<&co>]> {
# - if <context.args.get[2].contains[clearall]> {
# - flag %mynpc% jsentry.eventtargets:!
# - narrate "<&6>All event targets cleared."
# - queue clear
# }
# - if !<def[mynpc].flag[jsentry.eventtargets].contains[<context.args.get[2].replace[event<&co>]>]> {
# - narrate "<&6>That event target isn't set."
# - queue clear
# }
# - flag %mynpc% jsentry.eventtargets:<-:<context.args.get[2].replace[event<&co>]>
# - narrate "<&6>Event target removed."
# - queue clear
# }
# section deals with removing entity targets
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That target doesn't look like a proper entity type."
- queue clear
}
- if <context.args.get[2].contains[clearall]> {
- flag %mynpc% jsentry.targets:none
- narrate "<&6>All entity type targets cleared."
- queue clear
}
- if !<def[mynpc].flag[jsentry.targets].contains[<context.args.get[2]>]||false> {
- narrate "<&6>That target isn't set."
- queue clear
}
- flag %mynpc% jsentry.targets:<-:<context.args.get[2]>
- narrate "<&6>Removed target."
# Range command - configures the radius that a jsentry will search for possible targets.
jsentry_command_range:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry range <<>range<>>"
- narrate "<&6>Range = a number representing how far away (in blocks) the jsentry can attack targets at"
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That range value doesn't look like a proper number."
- queue clear
}
- if !<context.args.get[2].is[matches].to[integer]> {
- narrate "<&6>That range value doesn't look like a proper number."
- queue clear
}
- flag %mynpc% jsentry.range:<context.args.get[2]>
- narrate "<&6>Range set."
# Followrange command - only relevant to guard targets; the distance at which the jsentry should follow.
jsentry_command_followrange:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry followrange <<>range<>>"
- narrate "<&6>Range = a number representing how far away (in blocks) the jsentry can follow players at"
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That range value doesn't look like a proper number."
- queue clear
}
- if !<context.args.get[2].is[matches].to[integer]> {
- narrate "<&6>That range value doesn't look like a proper number."
- queue clear
}
- flag %mynpc% jsentry.follow_range:<context.args.get[2]>
- narrate "<&6>Follow range set."
# Damage command - configures how many hearts of damage the npc inflicts on each attack.
jsentry_command_damage:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry damage <<>damage<>>"
- narrate "<&6>Damage = a number representing how many hearts of damage the NPC deals when it attacks"
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That damage value doesn't look like a proper number."
- queue clear
}
- if !<context.args.get[2].is[matches].to[integer]> {
- narrate "<&6>That damage value doesn't look like a proper number."
- queue clear
}
- flag %mynpc% jsentry.damage:<context.args.get[2]>
- narrate "<&6>Damage set."
# Armour command - configures the percentage reduction in damage inflicted on npc's
jsentry_command_armour:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry Armour <<>armour<>>"
- narrate "<&6>Armour = what percentage of damage to take away"
- narrate "<&6>Set to -1 to have Armour calculated from equipped Armour"
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That armour value doesn't look like a proper number."
- queue clear
}
- if !<context.args.get[2].is[matches].to[integer]> {
- narrate "<&6>That armour value doesn't look like a proper number."
- queue clear
}
- flag %mynpc% jsentry.armour:<context.args.get[2].div[100]>
- narrate "<&6>Armour set."
# dsentry_command_health:
# - if <context.args.get[2].is[==].to[null]||true> {
# - narrate "<&6>/dSentry health <<>max-health-amount<>>"
# - queue clear
# }
# - if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
# - narrate "<&6>That health value doesn't look like a proper number."
# - queue clear
# }
# - if !<context.args.get[2].is[matches].to[decimal]> {
# - narrate "<&6>That health value doesn't look like a proper number."
# - queue clear
# }
# - flag %mynpc% dsentry.health:<context.args.get[2].div[100]>
# - narrate "<&6>Health set."
# Speed command - configures how fast the npc walks when attacking
jsentry_command_speed:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry speed <<>speed<>>"
- narrate "<&6>Speed = a number representing how fast the NPC should walk while attacking"
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That speed value doesn't look like a proper number."
- queue clear
}
- if !<context.args.get[2].is[matches].to[integer]> {
- narrate "<&6>That speed value doesn't look like a proper number."
- queue clear
}
- flag %mynpc% jsentry.walkspeed:<context.args.get[2]>
- narrate "<&6>Speed set."
# Attackrate command - configures how often the npc should attack.
jsentry_command_attackrate:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry attackrate <<>attackrate<>>"
- narrate "<&6>AttackRate = a number representing how many ticks should pass between an NPC's attacks"
- narrate "<&6>The minimum is 10. All higher values must be multiples of 10."
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That attackrate value doesn't look like a proper number."
- queue clear
}
- if !<context.args.get[2].is[matches].to[integer]> {
- narrate "<&6>That attackrate value doesn't look like a proper number."
- queue clear
}
- flag %mynpc% jsentry.attackrate:<context.args.get[2]>
- flag %mynpc% jsentry.attackping:0
- narrate "<&6>AttackRate set."
# Save command - saves the configuration of a jsentry in a yaml file for possible future use by create command.
jsentry_command_save:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry save <<>save-name>>"
- narrate "<&6>Save-name = a name that can be used to recreate the jsentry with later"
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That save name looks potentially problematic."
- queue clear
}
- yaml write:jsentry.<context.args.get[2]>.valid value:true id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.range value:<def[mynpc].flag[jsentry.range]> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.follow_range value:<def[mynpc].flag[jsentry.follow_range]> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.guard_target value:<def[mynpc].flag[jsentry.guard_target]||null> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.attackrate value:<def[mynpc].flag[jsentry.attackrate]> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.walkspeed value:<def[mynpc].flag[jsentry.walkspeed]> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.damage value:<def[mynpc].flag[jsentry.damage]> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.armour value:<def[mynpc].flag[jsentry.armour]> id:jsentry_saves
# - yaml write:dsentry.<context.args.get[2]>.health value:<def[mynpc].flag[dsentry.health]> id:dsentry_saves
- yaml write:jsentry.<context.args.get[2]>.targets value:<def[mynpc].flag[jsentry.targets].as_list||li@> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.flagtargets value:<def[mynpc].flag[jsentry.flagtargets].as_list||li@> id:jsentry_saves
# - yaml write:jsentry.<context.args.get[2]>.eventtargets value:<def[mynpc].flag[jsentry.eventtargets].as_list||li@> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.hand value:<def[mynpc].item_in_hand> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.helmet value:<def[mynpc].equipment.helmet> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.chestplate value:<def[mynpc].equipment.chestplate> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.leggings value:<def[mynpc].equipment.leggings> id:jsentry_saves
- yaml write:jsentry.<context.args.get[2]>.boots value:<def[mynpc].equipment.boots> id:jsentry_saves
- yaml savefile:jsentry_saves.yml id:jsentry_saves
- narrate "<&6>jsentry type saved!"
# Create command - converts an npc into a dsentry, either using default config values, or loading them from named savefile.
jsentry_command_create:
- if <context.args.get[2].is[==].to[null]||true> {
- flag %mynpc% jsentry.range:15
- flag %mynpc% jsentry.follow_range:3
- flag %mynpc% jsentry.guard_target:!
- flag %mynpc% jsentry.walkspeed:1
- flag %mynpc% jsentry.attackrate:30
- flag %mynpc% jsentry.attackping:0
- flag %mynpc% jsentry.armour:-1
# - flag %mynpc% dsentry.health:20
- flag %mynpc% jsentry.damage:2
- flag %mynpc% jsentry.targets:!
- flag %mynpc% jsentry.targets:|:zombie|creeper|spider|skeleton|witch
- flag %mynpc% jsentry.flagtargets:!
# - flag %mynpc% jsentry.eventtargets:!
- adjust %mynpc% teleport_on_stuck:true
- flag %mynpc% jsentry.is_jsentry
- flag %mynpc% jsentry.logic_group_<server.get_npcs_flagged[jsentry.is_jsentry].size.mod[10]>
- adjust %mynpc% teleport_on_stuck:false
- narrate "<&6>NPC turned into a default jsentry."
- queue clear
}
- if !<context.args.get[2].is[==].to[<context.args.get[2].escaped>]> {
- narrate "<&6>That save name looks potentially problematic."
- queue clear
}
- define base jsentry.<context.args.get[2]>.
- if !<yaml[jsentry_saves].read[%base%valid]||null> != true {
- narrate "<&6>There are no saves by that name."
- queue clear
}
- equip %mynpc% hand:<yaml[jsentry_saves].read[%base%hand]> head:<yaml[jsentry_saves].read[%base%helmet]> chest:<yaml[jsentry_saves].read[%base%chestplate]>
legs:<yaml[jsentry_saves].read[%base%leggings]> boots:<yaml[jsentry_saves].read[%base%boots]>
- flag %mynpc% jsentry.follow_range:<yaml[jsentry_saves].read[%base%follow_range]>
- flag %mynpc% jsentry.guard_target:<yaml[jsentry_saves].read[%base%guard_target]>
- flag %mynpc% jsentry.range:<yaml[jsentry_saves].read[%base%range]>
- flag %mynpc% jsentry.walkspeed:<yaml[jsentry_saves].read[%base%walkspeed]>
- flag %mynpc% jsentry.attackrate:<yaml[jsentry_saves].read[%base%attackrate]>
- flag %mynpc% jsentry.attackping:0
- flag %mynpc% jsentry.damage:<yaml[jsentry_saves].read[%base%damage]>
- flag %mynpc% jsentry.armour:<yaml[jsentry_saves].read[%base%armour]>
# - flag %mynpc% dsentry.health:<yaml[dsentry_saves].read[%base%health]>
- flag %mynpc% jsentry.targets:!
- flag %mynpc% jsentry.targets:|:<yaml[jsentry_saves].read[%base%targets]>
- flag %mynpc% jsentry.flagtargets:!
- flag %mynpc% jsentry.flagtargets:|:<yaml[jsentry_saves].read[%base%flagtargets]>
# - flag %mynpc% jsentry.eventtargets:!
# - flag %mynpc% jsentry.eventtargets:|:<yaml[jsentry_saves].read[%base%eventtargets]>
- flag %mynpc% jsentry.is_jsentry
- flag %mynpc% jsentry.logic_group_<server.get_npcs_flagged[jsentry.is_jsentry].size.mod[10]>
- narrate "<&6>NPC turned into a custom jsentry."
# uncreate command - removes all jsentry flags from an npc; converting it back to a standard npc.
jsentry_command_uncreate:
- if <context.args.get[2].is[==].to[null]||true> {
- narrate "<&6>/jsentry uncreate<<>target<>>"
- narrate "<&6>Removes all jsentry attributes from selected NPC"
- narrate "<&6>For safety, you must have the NPC selected, "
- narrate "<&6>AND enter their name as 2nd argument."
- queue clear
}
- if !<def[mynpc].name.equals_with_case[<context.args.get[2]>]> {
- narrate "<&6>The supplied name does not match the selected NPC"
- narrate "<&6>NB the match is case-sensitve"
- queue clear
}
- flag %mynpc% jsentry:!
}
- narrate "<&6>jsentry uncreated."
# Runs repeatedly as the jsentry logic loop
jsentry_task_logic:
type: task
debug: false
script:
- while true {
- wait 1t
- foreach <server.get_spawned_npcs_flagged[jsentry.logic_group_<def[loop_index].mod[10]>]> {
- run jsentry_task_attack npc:<def[value]> instantly
- if <def[value].flag[jsentry.target]||null> == null {
- resume waypoints npc:%value%
}
}
}
# Chooses a nearby target
jsentry_proc_picktarget:
type: procedure
debug: false
script:
- if <npc.flag[jsentry.target]||null> != null {
- if <npc.flag[jsentry.target].as_entity.is_spawned||false> {
- if <npc.location.distance[<npc.flag[jsentry.target].as_entity.location>]> < <npc.flag[jsentry.range]> {
- if <npc.can_see[<npc.flag[dsentry.target]||null>]||false> {
- determine <npc.flag[jsentry.target]>
}
}
}
}
# - if <npc.flag[jsentry.targets].size||0> == 0 {
# - announce to_console "<&6>NPC <npc.id> is marked as a jsentry but does not have a targets list!"
# - queue clear
# }
- define entities <npc.location.find.entities[<npc.flag[jsentry.targets].as_list||li@>|player].within[<npc.flag[jsentry.range]>].exclude[<npc>]>
- define entity null
- foreach %entities% {
- if %value% matches npc {
- define entities <def[entities].exclude[%value%]>
}
}
- foreach %entities% {
- if %value% matches player {
- define playrar %value%
- define TEMP_PLAYER_PASS <npc.flag[jsentry.targets].contains[player]||false>
- foreach <npc.flag[jsentry.flagtargets].as_list||li@> {
- if <def[playrar].flag[%value%]||null> != null {
- define TEMP_PLAYER_PASS true
}
}
# - if <def[playrar].gamemode> == CREATIVE {
# - define TEMP_PLAYER_PASS false
# }
- if !%TEMP_PLAYER_PASS% {
- define entities <def[entities].exclude[%playrar%]>
}
}
}
- foreach %entities% {
- if <npc.can_see[%value%]> {
- define entity %value%
- foreach stop
}
}
- if %entity% != null {
- determine %entity%
}
- determine null
# Makes a jsentry NPC attack the target
jsentry_task_attack:
type: task
debug: false
script:
# this section adds 10 to jsentry.attackping every time it is called by jsentry_task_logic (every 10 ticks).
- flag npc jsentry.attackping:<npc.flag[jsentry.attackping].add[10].as_int||0>
- if <npc.flag[jsentry.attackping]> >= <npc.flag[jsentry.attackrate]> {
- flag npc jsentry.attackping:0
}
else {
- queue clear
}
- flag npc jsentry.target:<proc[jsentry_proc_picktarget]>
# # call jsentry_proc_picktarget if there is no current target; or if the current target is not spawned, is out of sight, or is out of range.
# - if <npc.flag[jsentry.target]||null> == null {
# - flag npc jsentry.target:<proc[jsentry_proc_picktarget]>
# }
# else {
# - if !<util.entity_is_spawned[<npc.flag[jsentry.target]>]||false>
# || !<npc.can_see[<npc.flag[jsentry.target]>]||false>
# || <npc.location.distance[<npc.flag[jsentry.target].as_entity.location>]> < <npc.flag[jsentry.range]>
# {
# - flag npc jsentry.target:<proc[jsentry_proc_picktarget]>
# }
# }
# section handles the follow guard_target behaviour of JSentries who are guarding
- if <npc.flag[jsentry.guard_target]||null> matches npc {
- if <npc.flag[jsentry.guard_target].as_npc.is_spawned||false> {
- inject locally Move_to_guard_target
}
}
else if <npc.flag[jsentry.guard_target]||null> matches player {
- if <npc.flag[jsentry.guard_target].as_player.is_online||false> {
- inject locally Move_to_guard_target
}
}
# end of guarding specific code
- if <npc.flag[jsentry.target]||null> == null {
- if <npc.entity_type> == player animate <npc> animation:stop_use_item
- queue clear
}
- if <npc.item_in_hand.material.name> != bow {
- pause waypoints
}
- define loc <npc.flag[jsentry.target].as_entity.location.add[0,1.33,0]>
- look %loc%
- if <npc.item_in_hand.material.name> == bow {
# TODO: should critical=true be enabled in some cases? (corrupts damage calc)
- define settings knockback=1
- if <npc.item_in_hand.enchantments||li@> contains ARROW_FIRE {
- define settings %settings%;fire_time=1m
}
- if <npc.entity_type> == player animate <npc> animation:stop_use_item
- shoot arrow[%settings%] origin:<npc> destination:%loc% speed:50 lead:<npc.flag[jsentry.target].as_entity.velocity> script:jsentry_task_removearrow
- wait 1t
- if <npc.entity_type> == player animate <npc> animation:start_use_item
}
else if <npc.location.distance[%loc%]> > 3 {
- walk %loc% speed:<npc.flag[jsentry.walkspeed]>
}
else {
- if <npc.entity_type> == player animate <npc> animation:arm_swing
- hurt <npc.flag[jsentry.target]> <proc[jsentry_proc_calculatedamage]>
- if <npc.item_in_hand> != i@air {
- if <npc.item_in_hand.enchantments||li@> contains FIRE_ASPECT {
- adjust <npc.flag[jsentry.target]> fire_time:10s
}
}
}
Move_to_guard_target:
- if <npc.location.distance[<npc.flag[jsentry.guard_target].as_entity.location>]> > 100 {
- teleport <npc> <npc.flag[jsentry.guard_target].as_entity.location>
}
- if <npc.flag[jsentry.target]||null> == null || <npc.item_in_hand.material.name> == bow {
- if <npc.location.distance[<npc.flag[jsentry.guard_target].as_entity.location>]> > <npc.flag[jsentry.follow_range]> {
- walk <npc> <npc.flag[jsentry.guard_target].as_entity.location> auto_range radius:<npc.flag[jsentry.follow_range]>
}
}
jsentry_task_removearrow:
type: task
debug: false
script:
- if %hit_entities% == li@ remove %shot_entities%
jsentry_proc_calculatearmour:
type: procedure
debug: false
script:
# flag npc armour '-1' to use calculated armour, otherwise, trust the flag value, which is a static % reduction. (0 = no armour)
- if <npc.flag[jsentry.armour]> >= 0 {
- determine <npc.flag[jsentry.armour]>
}
# section to calculate % damage reduction according to the material of worn armour.
- foreach helmet|chestplate|leggings|boots {
- define material <npc.equipment.%value%.material.name.replace[_%value%]||air>
- define TotalArmour <def[TotalArmour].add[<s@jsentry_equipment_values.yaml_key[armour.%material%.%value%]||0>]>
}
- determine <def[TotalArmour]>
jsentry_equipment_values:
type: yaml data
armour:
air:
helmet: 0
chestplate: 0
leggings: 0
boots: 0
leather:
helmet: 0.04
chestplate: 0.12
leggings: 0.08
boots: 0.04
gold:
helmet: 0.08
chestplate: 0.20
leggings: 0.12
boots: 0.04
chainmail:
helmet: 0.08
chestplate: 0.20
leggings: 0.16
boots: 0.04
iron:
helmet: 0.08
chestplate: 0.24
leggings: 0.20
boots: 0.08
diamond:
helmet: 0.12
chestplate: 0.32
leggings: 0.24
boots: 0.12
jsentry_proc_calculatedamage:
type: procedure
debug: false
script:
# flag npc damage '-1' to use calculated damage, otherwise, trust the flag value
- if <npc.flag[jsentry.damage]> >= 0 {
- determine <npc.flag[jsentry.damage]>
}
# TODO: calculate damage based on held item
# TODO: Make the default damage -1