Paste #16466: Edit of P#16287 Bodyguard Salesman

Date: 2015/06/14 04:09:27 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778


# This script was written by Cromis.
# This script requires the plug-ins Citizens, Denizen and Sentry.
#
# It is a assignment script for a salesman that sells bodyguards.
# To get this to work on your server put this script into your servers denizen/scripts folder.
# In the section below the world script inside the default constants you will see BGSpawnLocation: <w@world.spawn_location>
# You will want to change "world" to whatever your main world is. Having it at the spawnpoint helps as
# The spawn is always loaded which helps with spawning and despawning of bodyguards.
# Save changes you have made to the script.
# Reload denizen scripts with /denizen reload scripts.
# Then select the npc you wish to sell the bodyguards and give it the assignment BgSalesMan.
# After that you are all set. I would recommend you read through the first little bit of these comments
# Before putting this on your live server.
#
#
# With this script the player is limited to one bodyguard. If you wish to have more you can either edit this script if you know how
# Or wait for me to get around to making a new script for that which I will link  in the description when its complete.
# If you know how feel free to use this script/edit as you wish alls I ask is you give me credit.

# This is the world script that handles the spawning and despawning of bodyguards.
# This helps prevent having a bulk of bodyguards standing in the same area which will be
# Whatever you have the spawnpoint set to which is the world spawn by default.

# This is the format script for the script to use.
# Remove the # on the next 3 lines if you do not have a format code
#F1:
#    type: format
#    format: <green><npc.name><&co> <gold><text>

BodyguardWS:
    type: world
    debug: false
    events:
        on player join:
            # When a player joins the server it checks if the have any of the bodyguard flags.
            - if <player.has_flag[bodyguard]> {
                # If the player has the flag bodyguard1 which is the non respawning bodyguard it will follow this if path.
                - if <player.has_flag[bodyguard1]> {
                    - wait 1s
                    # This is where the npc is spawned back in so it can be used again.
                    - ^spawn <player.flag[BodyGuard]> <s@BodyguardSalesMan.constant[BGSpawnLocation]>
                    # Now to select the npc to give it back everything it needs.
                    - ^execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                    - if <server.selected_npc> != <player.flag[BodyGuard]> {
                        - narrate "<red>ERROR: Npc number does not match selected Npc Please contact an admin."
                        - queue clear
                    } else {
                        # First to give back the sentry trait
                        - if !<server.selected_npc.has_trait[sentry]> {
                            - ^execute as_server "trait sentry"
                        }
                        # Turning off sentry criticals
                        - ^execute as_server "sentry criticals false"
                        # Now to set it so it doesnt resapwn after its death as this bodyguard type does not respawn
                        - ^execute as_server "sentry respawn -1"
                        # Keep that bodyguard from following so close!
                        - ^execute as_server "sentry follow 5"
                        # Sets the speed of the bodyguard while in combat.
                        - ^execute as_server "sentry speed 1.0"
                        # Sets how fast the bodyguard will heal.
                        - ^execute as_server "sentry healrate 10"
                        # Now to tell the bodyguard to attack any monster within its range.
                        - ^execute as_server "sentry target add entity:monster"
                        # Adding pigmen to the ignore list so they don't go aggroing them.
                        - ^execute as_server "sentry ignore add entity:pig_zombie"
                        # If BodyGuardPvp is set to false the bodyguard will be told to ignore players.
                        - if <s@BodyguardSalesMan.constant[BodyGuardPvp]> == false {
                            - ^execute as_server "sentry ignore add entity:player"
                            # If BodyGuardPvp is set to true it will remove players from the ignore list.
                            # If bodyguards do not fight players you might want to check the sentry config.
                        } else {
                            - ^execute as_server "sentry ignore remove entity:player"
                            }
                        # If the player has the flag BGGuarding it will have the sentry guard the player
                        - if <player.has_flag[BGGuarding]> {
                            # Tells the bodyguard to start guarding the player.
                            - ^execute as_server "sentry guard <player.name>"
                        }
                        }
                # If the player has the flag bodyguard2 which is the bodyguard that respawns after 5 minutes it will follow this if path.
                } else if <player.has_flag[Bodyguard2]> {
                    - wait 1s
                    # Spawn in the bodyguard so it can be used.
                    - ^spawn <player.flag[BodyGuard]> <s@BodyguardSalesMan.constant[BGSpawnLocation]>
                    # Selects the bodyguard to apply the changes it needs
                    - ^execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                    - if <server.selected_npc> != <player.flag[BodyGuard]> {
                        - narrate "<red>ERROR: Npc number does not match selected Npc Please contact an admin."
                        - queue clear
                    } else {
                        # First to give back the sentry trait
                        - if !<server.selected_npc.has_trait[sentry]> {
                            - ^execute as_server "trait sentry"
                        }
                        # Turning off sentry criticals
                        - ^execute as_server "sentry criticals false"
                        # Sets the respawn after death to 5 minutes.
                        - ^execute as_server "sentry respawn 300"
                        # Sets the follow distance to 5 so it doesnt follow the player so close.
                        - ^execute as_server "sentry follow 5"
                        # Sets the speed of the bodyguard while in combat.
                        - ^execute as_server "sentry speed 1.0"
                        # Sets how fast the bodyguard will heal.
                        - ^execute as_server "sentry healrate 10"
                        # Now to tell the bodyguard to attack any monster within its range.
                        - ^execute as_server "sentry target add entity:monster"
                        # Adding pigmen to the ignore list so they don't go aggroing them.
                        - ^execute as_server "sentry ignore add entity:pig_zombie"
                        # If BodyGuardPvp is set to false the bodyguard will be told to ignore players.
                        - if <s@BodyguardSalesMan.constant[BodyGuardPvp]> == false {
                            - ^execute as_server "sentry ignore add entity:player"
                            # If BodyGuardPvp is set to true it will remove players from the ignore list.
                            # If bodyguards do not fight players you might want to check the sentry config.
                        } else {
                            - ^execute as_server "sentry ignore remove entity:player"
                            }
                        # If the player has the flag BGGuarding it will have the sentry guard the player
                        - if <player.has_flag[BGGuarding]> {
                            # Tells the bodyguard to start guarding the player.
                            - ^execute as_server "sentry guard <player.name>"
                        }
                        }
                # If the player has the flag bodyguard2 which is the bodyguard that respawns after 5 minutes it will follow this if path.
                } else if <player.has_flag[bodyguard3]> {
                    - wait 1s
                    # Spawns in the bodyguard so it can be used.
                    - ^spawn <player.flag[BodyGuard]> <s@BodyguardSalesMan.constant[BGSpawnLocation]>
                    # Selects the bodyguard so it can be given back its stats/trait
                    - ^execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                    - if <server.selected_npc> != <player.flag[BodyGuard]> {
                        - narrate "<red>ERROR: Npc number does not match selected Npc Please contact an admin."
                        - queue clear
                    } else {
                        # First to give back the sentry trait
                        - if !<server.selected_npc.has_trait[sentry]> {
                            - ^execute as_server "trait sentry"
                        }
                        # Turning off sentry criticals
                        - ^execute as_server "sentry criticals false"
                        # Sets the Bodyguards armor to a base value of 2. Shhhh.
                        - ^execute as_server "sentry armor 2"
                        # Sets the bodyguard to respawn 1 second after its death.
                        - ^execute as_server "sentry respawn 1"
                        # Sets the follow distance to 5 so it dosent follow so close.
                        - ^execute as_server "sentry follow 5"
                        # Sets the speed of the bodyguard while in combat.
                        - ^execute as_server "sentry speed 1.0"
                        # Sets how fast the bodyguard will heal.
                        - ^execute as_server "sentry healrate 5"
                        # Now to tell the bodyguard to attack any monster within its range.
                        - ^execute as_server "sentry target add entity:monster"
                        # Adding pigmen to the ignore list so they don't go aggroing them.
                        - ^execute as_server "sentry ignore add entity:pig_zombie"
                        # If BodyGuardPvp is set to false the bodyguard will be told to ignore players.
                        - if <s@BodyguardSalesMan.constant[BodyGuardPvp]> == false {
                            - ^execute as_server "sentry ignore add entity:player"
                            # If BodyGuardPvp is set to true it will remove players from the ignore list.
                            # If bodyguards do not fight players you might want to check the sentry config.
                        } else {
                            - ^execute as_server "sentry ignore remove entity:player"
                            }
                        # If the player has the flag BGGuarding it will have the sentry guard the player
                        - if <player.has_flag[BGGuarding]> {
                            # Tells the bodyguard to start guarding the player.
                            - ^execute as_server "sentry guard <player.name>"
                        }
                    }
                }
            }
        on player quits:
            # When the player quits if they have they bodyguard flag it will do whats in this if statement
            - if <player.has_flag[bodyguard]> {
                # The Bodyguard will be selected
                - execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                - if <server.selected_npc.has_trait[sentry]> {
                # The sentry trait is removed so it can be despawned
                    - execute as_server "trait sentry"
                }
                # The Bodyguard is despawned
                - execute as_server "npc despawn"
            }

BodyguardSalesMan:
    type: assignment
    debug: false
    # This is where most of the things you would want to change will be.
    default constants:
        # This is the format the npc will take when it talks to you change it to the format script you use.
        # If you don't use a format script I recommend you make one it makes things pretty and so much easier. http://mcmonkey.org/denizen/tuts/format
        # Or you can go through this script and remove every "format:<npc.constant[NpcFormat]>" in this script along with the NpcFormat line below this.
        NpcFormat: F1
        # If you want bodyguards to get involved in pvp set this to true.
        BodyGuardPvp: false
        # This is the location the bodyguard will spawn in.
        # I recommend you put this at the server spawn by changing "world" to your servers world name or change it to <player.location>.
        # If you put it to <player.location> the bodyguards will spawn where the player is standing but I recommend you use the world spawn.
        # If the location is in a unloaded area it can cause issues.
        BGSpawnLocation: <w@world.spawn_location>
        # This is the cost of the bodyguard that does not re-spawn. Change it to whatever price you wish.
        BodyGuardCost: 20
        # This is the cost of the bodyguard that re-spawns after 5 minutes. Change it to whatever price you wish.
        BodyGuardRespawnCost: 2000
        # This is the cost of the bodyguard that re-spawns after 1 second. Change it to whatever price you wish.
        BodyGuardInstant: 20000
        # Below this is the equipment the bodyguards will use.
        # This is the weapon the bodyguards will use a knockback 2 diamond sword change it if you wish.
        BodyGuardWeapon: hand:i@BodyguardSword
        # This is the helmet the bodyguards will use change it to whatever you like.
        BodyGuardHelm: head:i@DIAMOND_HELMET
        # This is the chestplate the bodyguards will use change it to whatever you like.
        BodyGuardChest: chest:i@DIAMOND_CHESTPLATE
        # This is the platelegs the bodyguards will use change it to whatever you like.
        BodyGuardLegs: legs:i@DIAMOND_LEGGINGS
        # This is the boots the bodyguards will use change it to whatever you like.
        BodyGuardBoots: boots:i@DIAMOND_BOOTS
        # I would not recommend changing anything past this point unless you know what you are doing/changing.
    interact scripts:
    - 10 BgSalesMan

# This is The script the npc that sells the bodyguards uses.
BgSalesMan:
    type: interact
    steps:
        1:
            click trigger:
                script:
                # If the player has the bodyguard that respawns after 5 minutes they may want to eventually upgrade
                # Previously players were not able to upgrade the bodyguards with this script, now they can.
                # If the player has the flag for the bodyguard that respawns after 5 minutes it will zap them to the upgrade step
                - if <player.has_flag[Bodyguard2]> {
                    # Tells the player how much it will cost to upgrade the bodyguard. Yay math.
                    - narrate format:<npc.constant[NpcFormat]> "It will cost $<npc.constant[BodyGuardInstant].sub[<npc.constant[BodyGuardRespawnCost]>]> to upgrade your bodyguard."
                    - wait 1
                    - narrate format:<npc.constant[NpcFormat]> "Speak to me again when you are ready to upgrade your bodyguard."
                    - zap step:BGUpgrade
                    # If the player already has a bodyguard they will not be able to get another.
                    } else if <player.has_flag[Bodyguard1]> {
                    - narrate format:<npc.constant[NpcFormat]> "You already have a bodyguard, Come back if he dies."
                    } else if <player.has_flag[Bodyguard3]> {
                    - narrate format:<npc.constant[NpcFormat]> "You already have a bodyguard, Come back if he dies."
                    } else {
                    # If the player does not have a bodyguard already the npc will let the player know what kind of bodyguards he is selling.
                    - narrate format:<npc.constant[NpcFormat]> "Hello <player.name> Welcome to my shop."
                    - wait 1
                    - narrate format:<npc.constant[NpcFormat]> "As of this moment I only have three types of bodyguard available."
                    - wait 1
                    - narrate format:<npc.constant[NpcFormat]> "Would you like to hire a <green>normal<gold> bodyguard for $<npc.constant[BodyGuardCost]>?"
                    - wait 1
                    - narrate format:<npc.constant[NpcFormat]> "Or would you like one that <green>respawns<gold> for $<npc.constant[BodyGuardRespawnCost]> or one that respawns <green>instantly<gold> for $<npc.constant[BodyGuardInstant]>?"
                    }
                    # Now the npc will wait for a little bit for the player to type in chat which guard it wants.
            chat trigger:
                # If the player wants a bodyguard that does not respawn after death they will say "normal" in chat near the salesman.
                1:
                    trigger: <gold>I am interested in purchasing a /normal/ bodyguard.
                    script:
                    # At this point the salesman will let the player know the cost of the bodyguard.
                    - engage
                    - narrate format:<npc.constant[NpcFormat]> "Alright that will be $<npc.constant[BodyGuardCost]>."
                    # Now it checks if the player has enough for the bodyguard.
                    - if <player.money> < <npc.constant[BodyGuardCost]> {
                        # If the player does not have enough money the npc will tell the player to come back when they have enough cash.
                        - narrate format:<npc.constant[NpcFormat]> "You do not have enough money, please come back when you have enough."
                        - disengage
                        } else {
                        # If the player has enough money the salesman will now take that amount from them.
                        - take money qty:<npc.constant[BodyGuardCost]>
                        # The player is now flagged with the Bodyguard1 flag the flag for a non respawning bodyguard.
                        - flag player Bodyguard1
                        # Now to create the npc that will soon be the players bodyguard.
                        - create player BodyGuard save:BodyGuard
                        # Flagging the player with the npc number this helps a lot with selecting the npc later on.
                        - flag player Bodyguard:<entry[BodyGuard].created_npc>
                        # Spawn in the bodyguard at the servers spawn or wherever you changed its spawnpoint to.
                        - ^spawn <player.flag[BodyGuard]> <npc.constant[BGSpawnLocation]>
                        # Going back to what I just said now to select the npc that will be the bodyguard for the player.
                        - ^execute as_server "npc select <player.flag[BodyGuard].replace[n@]>"
                        # Time to give it the sentry trait.
                        # Later on I plan on removing the need for the sentry plug-in just not now.
                        - ^execute as_server "trait sentry"
                        # Time to give it some equipment first the weapon.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardWeapon]>
                        # Now for the helmet.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardHelm]>
                        # Now for the chestplate.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardChest]>
                        # Now for the platelegs.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardLegs]>
                        # And finally the boots.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardBoots]>
                        # Giving the bodyguard a view range of 15 it will attack any target in this range
                        - ^execute as_server "sentry range 15"
                        # Now to tell the bodyguard to attack any monster within its range.
                        - ^execute as_server "sentry target add entity:monster"
                        # Adding pigmen to the ignore list so they don't go aggroing them.
                        - ^execute as_server "sentry ignore add entity:pig_zombie"
                        # If BodyGuardPvp is set to false the bodyguard will be told to ignore players.
                        - if <npc.constant[BodyGuardPvp]> == false {
                            - ^execute as_server "sentry ignore add entity:player"
                            # If BodyGuardPvp is set to true it will remove players from the ignore list.
                            # If bodyguards do not fight players you might want to check the sentry config.
                            } else {
                            - ^execute as_server "sentry ignore remove entity:player"
                            }
                        # Since this bodyguard does not respawn after death we set its respawn timer to -1 so it does not respawn.
                        - ^execute as_server "sentry respawn -1"
                        # Sets the distance the bodyguard will follow the player to 5 that way they do not keep standing in the players face.
                        - ^execute as_server "sentry follow 5"
                        # Sets the speed of the bodyguard while in combat.
                        - ^execute as_server "sentry speed 1.0"
                        # Sets how fast the bodyguard will heal.
                        - ^execute as_server "sentry healrate 10"
                        # This is where the bodyguard is given the assignment that controls it.
                        - ^execute as_server "npc assignment --set BodyguardAssignment"
                        # Giving the player ownership of the npc.
                        - ^execute as_server "npc owner <player.name>"
                        # Now to tell the bodyguard to guard the player.
                        - ^execute as_server "sentry guard <player.name>"
                        # Flagging the player with the BGGuarding flag which will help later on.
                        - ^flag player BGGuarding
                        # Letting the player know that they have given the salesman the cost of the bodyguard
                        - narrate "<red>You give <npc.name> $<npc.constant[BodyGuardCost]>"
                        - wait 2
                        # Now to explain to the player how to use their new bodyguard.
                        - narrate format:<npc.constant[NpcFormat]> "Bodyguards have a few interactions."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "Right click on him to enter order mode."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "He will tell you what interactions he has."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "Type in chat the option you wish to use."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "If you wish to exit order mode simply right click him again."
                        # Letting the player know they now own the bodyguard until its death.
                        - narrate format:<npc.constant[NpcFormat]> "He is yours untill he dies, be safe out there."
                        - disengage
                        }

                2:
                    # If the player wants a bodyguard that respawns after 5 minutes they will say "respawns".
                    trigger: <gold>I am interested in purchasing a bodyguard that /respawns/.
                    script:
                    - engage
                    # Tells the player the price of the bodyguard.
                    - narrate format:<npc.constant[NpcFormat]> "Alright that will be $<npc.constant[BodyguardRespawnCost]>."
                    # If the player does not have enough money the salesman will tell the player to come back when they have the money.
                    - if <player.money> < <npc.constant[BodyguardRespawnCost]> {
                        - narrate format:<npc.constant[NpcFormat]> "You do not have enough money, please come back when you have enough."
                        - disengage
                        # If the player has enough money the salesman will now take the cost of the bodyguard from the player.
                        } else {
                        - take money qty:<npc.constant[BodyguardRespawnCost]>
                        # Gives the player the flag for the bodyguard that repsawns after 5 minutes which helps later on.
                        - flag player Bodyguard2
                        # Now to create the npc that will soon be the players bodyguard.
                        - create player BodyGuard save:BodyGuard
                        # Flags the player with the number of the npc that will soon be the players bodyguard which helps later on.
                        - flag player Bodyguard:<entry[BodyGuard].created_npc>
                        # Spawn in the bodyguard at the servers spawn or wherever you changed its spawnpoint to.
                        - ^spawn <player.flag[BodyGuard]> <npc.constant[BGSpawnLocation]>
                        # Selects the npc that will soon be the players bodyguard.
                        - ^execute as_server "npc select <player.flag[BodyGuard].replace[n@]>"
                        # Time to make the npc into a bodyguard.
                        - ^execute as_server "trait sentry"
                        # Time to give it some equipment first the weapon.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardWeapon]>
                        # Now for the helmet.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardHelm]>
                        # Now for the chestplate.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardChest]>
                        # Now for the platelegs.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardLegs]>
                        # And finally the boots.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardBoots]>
                        # Giving the bodyguard a view range of 15 it will attack any target in this range
                        - ^execute as_server "sentry range 15"
                        # Now to tell the bodyguard to attack any monster within its range.
                        - ^execute as_server "sentry target add entity:monster"
                        # Adding pigmen to the ignore list so they don't go aggroing them.
                        - ^execute as_server "sentry ignore add entity:pig_zombie"
                        # If BodyGuardPvp is set to false the bodyguard will be told to ignore players.
                        - if <npc.constant[BodyGuardPvp]> == false {
                            - ^execute as_server "sentry ignore add entity:player"
                            # If BodyGuardPvp is set to true it will remove players from the ignore list.
                            # If bodyguards do not fight players you might want to check the sentry config.
                            } else {
                            - ^execute as_server "sentry ignore remove entity:player"
                            }
                        # Sets the bodyguards to respawn 5 minutes after its death.
                        - ^execute as_server "sentry respawn 300"
                        # Setting the follow range to 5 so it doesnt follow the player too close.
                        - ^execute as_server "sentry follow 5"
                        # Sets the speed of the bodyguard to 1 while in combat.
                        - ^execute as_server "sentry speed 1.0"
                        # Sets how fast the bodyguard will heal.
                        - ^execute as_server "sentry healrate 10"
                        # Gives the bodyguard the assignment that controls it.
                        - ^execute as_server "npc assignment --set BodyguardAssignment"
                        # Gives ownership of the bodyguard to the player
                        - ^execute as_server "npc owner <player.name>"
                        # Tells the bodyguard to guard the player.
                        - ^execute as_server "sentry guard <player.name>"
                        # Flags the player with the BGGuarding flag which helps later.
                        - ^flag player BGGuarding
                        # Lets the player know that they have given the salesman the price of the bodyguard.
                        - narrate "<red>You give <npc.name> $<npc.constant[BodyguardRespawnCost]>"
                        # Now to explain to the player how to use their new bodyguard.
                        - narrate format:<npc.constant[NpcFormat]> "Bodyguards have a few interactions."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "Right click on him to enter order mode."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "He will tell you what interactions he has."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "Type in chat the option you wish to use."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "If you wish to exit order mode simply right click him again."
                        # Lets the player know the bodyguard will respawn 5 minutes after its death.
                        - narrate format:<npc.constant[NpcFormat]> "Your bodyguard will respawn after 5 minutes if it dies."
                        - disengage
                        }

                3:
                    # If the player wants the bodyguard that respawns instantly the player will say "instantly" in chat.
                    trigger: <gold>I am interested in purchasing a bodyguard that /instantly/ respawns.
                    script:
                    - engage
                    # Tells the player the cost of the bodyguard.
                    - narrate format:<npc.constant[NpcFormat]> "Alright that will be $<npc.constant[BodyGuardInstant]>."
                    # If the player does not have enough money for the bodyguard the salesman will tell the player to come back when they have enough.
                    - if <player.money> < <npc.constant[BodyGuardInstant]> {
                        - narrate format:<npc.constant[NpcFormat]> "You do not have enough money, please come back when you have enough."
                        - disengage
                        # If the player does have enough money the salesman will take the price of the bodyguard from the player.
                        } else {
                        - take money qty:<npc.constant[BodyGuardInstant]>
                        # Gives the player the flag for the bodyguard that respawns instantly which will help out later.
                        - flag player Bodyguard3
                        # Creates the npc that will soon be the players bodyguard.
                        - create player BodyGuard save:BodyGuard
                        # Flags the player with the bodyguards npc number which will help with selecting the bodyguard later on.
                        - flag player Bodyguard:<entry[BodyGuard].created_npc>
                        # Spawn in the bodyguard at the servers spawn or wherever you changed its spawnpoint to.
                        - ^spawn <player.flag[BodyGuard]> <npc.constant[BGSpawnLocation]>
                        # Selects the soon to be bodyguard.
                        - ^execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                        # Gives the bodyguard the sentry trait.
                        - ^execute as_server "trait sentry"
                        # Gives the bodyguard some extra armor shhhhh dont let them know this one is stronger.
                        - ^execute as_server "sentry armor 2"
                        # Time to give it some equipment first the weapon.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardWeapon]>
                        # Now for the helmet.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardHelm]>
                        # Now for the chestplate.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardChest]>
                        # Now for the platelegs.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardLegs]>
                        # And finally the boots.
                        - ^equip <entry[BodyGuard].created_npc> <npc.constant[BodyGuardBoots]>
                        # Giving the bodyguard a view range of 15 it will attack any target in this range
                        - ^execute as_server "sentry range 15"
                        # Now to tell the bodyguard to attack any monster within its range.
                        - ^execute as_server "sentry target add entity:monster"
                        # Adding pigmen to the ignore list so they don't go aggroing them.
                        - ^execute as_server "sentry ignore add entity:pig_zombie"
                        # If BodyGuardPvp is set to false the bodyguard will be told to ignore players.
                        - if <npc.constant[BodyGuardPvp]> == false {
                            - ^execute as_server "sentry ignore add entity:player"
                            # If BodyGuardPvp is set to true it will remove players from the ignore list.
                            # If bodyguards do not fight players you might want to check the sentry config.
                            } else {
                            - ^execute as_server "sentry ignore remove entity:player"
                            }
                        # This is where we make the bodyguard respawn 1 second after its death yeah thats right 1 second.
                        - ^execute as_server "sentry respawn 1"
                        # Sthap following so close!
                        - ^execute as_server "sentry follow 5"
                        # Sets the speed of the bodyguard while its in combat.
                        - ^execute as_server "sentry speed 1.0"
                        # Sets how fast the bodyguard heals.
                        - ^execute as_server "sentry healrate 5"
                        # Gives the bodyguard the assignment that controls it.
                        - ^execute as_server "npc assignment --set BodyguardAssignment"
                        # Sets the player as the owner of the bodyguard.
                        - ^execute as_server "npc owner <player.name>"
                        # Tels the bodyguard to start guarding the player.
                        - ^execute as_server "sentry guard <player.name>"
                        # Flags the player with the BGGuarding flag which helps out later.
                        - ^flag player BGGuarding
                        # Tells the player they have given the salesman the price of the bodyguard.
                        - narrate "<red>You give <npc.name> $<npc.constant[BodyGuardInstant]>"
                        # Now to explain to the player how to use their new bodyguard.
                        - narrate format:<npc.constant[NpcFormat]> "Bodyguards have a few interactions."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "Right click on him to enter order mode."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "He will tell you what interactions he has."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "Type in chat the option you wish to use."
                        - wait 2
                        - narrate format:<npc.constant[NpcFormat]> "If you wish to exit order mode simply right click him again."
                        - wait 2
                        # Lets the player know the bodyguard will respawn right away.
                        - narrate format:<npc.constant[NpcFormat]> "Your bodyguard will respawn right away if it dies."
                        - disengage
                        }

                4:
                    # If the player does not want a bodyguard they will say "no" in chat.
                    trigger: <gold>/No/, I dont want a bodyguard right now
                    script:
                    - engage
                    # The salesman will choose from one of these to tell the player.
                    - random {
                        - narrate format:<npc.constant[NpcFormat]> "Alright come back if you change your mind."
                        - narrate format:<npc.constant[NpcFormat]> "You know where to find me if you get yourself in over your head"
                        }
                    - disengage
        # This part handles the upgrade process between the 5 minute and 1 second respawning bodyguards.
        BGUpgrade:
            click trigger:
                script:
                # Asks the player if they wish to upgrade the bodyguard and tells them the cost.
                - narrate format:<npc.constant[NpcFormat]> "Do you wish to upgrade your bodyguard for $<npc.constant[BodyGuardInstant].sub[<npc.constant[BodyGuardRespawnCost]>]>?"
            chat trigger:
                1:
                    # If the player wants to upgrade the bodyguard they say "yes" in chat near the salesman.
                    trigger: <gold>/Yes/ I would like to upgrade my bodyguard now.
                    script:
                    - engage
                    # Checks if the player has enough money.F
                    - if <player.money> < <npc.constant[BodyGuardInstant].sub[<npc.constant[BodyGuardRespawnCost]>]> {
                        # If they don't it asks them to come back when they have enough money.
                        - ^narrate format:<npc.constant[NpcFormat]> "You do not have enough money please come back when you do."
                        - disengage
                        # If they do have enough money the salesman tells them the cost and the player pays the salesman that amount.
                        } else {
                        - ^narrate format:<npc.constant[NpcFormat]> "Alright that will be $<npc.constant[BodyGuardInstant].sub[<npc.constant[BodyGuardRespawnCost]>]>"
                        - ^take money qty:<npc.constant[BodyGuardInstant].sub[<npc.constant[BodyGuardRespawnCost]>]>
                        # Selects the soon to be bodyguard.
                        - ^execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                        # Remove Bodyguard2 flag from the player.
                        - flag player Bodyguard2:!
                        # Gives the player the bodyguard3 flag.
                        - flag player Bodyguard3
                        # Gives the bodyguard some extra armor shhhhh dont let them know this one is stronger.
                        - ^execute as_server "sentry armor 2"
                        # Giving the bodyguard a view range of 15 it will attack any target in this range
                        - ^execute as_server "sentry range 15"
                        # This is where we make the bodyguard respawn 1 second after its death yeah thats right 1 second.
                        - ^execute as_server "sentry respawn 1"
                        # Sets how fast the bodyguard heals.
                        - ^execute as_server "sentry healrate 5"
                        - disengage
                        }
                2:
                    # If the player does not wish to upgrade the bodyguard yet they say "no" near the salesman.
                    trigger: <gold>/No/ I would not like to upgrade my bodyguard yet.
                    script:
                    - narrate format:<npc.constant[NpcFormat]> "Alright come back if you change your mind."


# This is the assignment script that controls the bodyguards      
BodyguardAssignment:
    type: assignment
    debug: false
    default constants:
        # This is the format the npc will take when it talks to you change it to the format script you use.
        # If you don't use a format script I recommend you make one it makes things pretty and so much easier. http://mcmonkey.org/denizen/tuts/format
        # Or you can go through this script and remove every "format:<npc.constant[NpcFormat]>" in this script along with the NpcFormat line below this.
        NpcFormat: F1
    interact scripts:
    - 10 BgInteractions
    actions:
        on death:
        # If the bodyguard dies the following will happen.
        # Remember the flag for the bodyguard that does not respawn? Time to use it.
        - if <player.has_flag[Bodyguard1]> {
            # Lets the player know the bodyguard has died.
            - narrate "<red> Your bodyguard has died!" targets:<npc.owner>
            # Removes the bodyguard flag so they can purchase another.
            - flag player Bodyguard:!
            # Basicly the same thing as above.
            - flag player Bodyguard1:!
            # Look another flag to remove.
            - flag player BGGuarding:!
            # If the player has the flag for the bodyguard that reaspawns after 5 minutes it will tell the player the bodyguard has died.
            } elseif <player.has_flag[Bodyguard2]> {
            - narrate "<red> Your bodyguard has died!" targets:<npc.owner>
            # Now for the 5 minute wait.
            - wait 300s
            # Lets teleport the bodyguard to the player just incase it hasnt already.
            - teleport npc location:<npc.owner.location>
            # If the player has the bodyguard that respawns instantly it will let the player know the bodyguard has died.
            } else <player.has_flag[Bodyguard3]> {
            - narrate "<red> Your bodyguard has died!" targets:<npc.owner>
            # The long 1 second wait.
            - wait 1s
            # Teleports the bodyguard to the player incase it hasnt already done so.
            - teleport npc location:<npc.owner.location>
            }

# This is the part of the script that handels the interactions for the bodyguard with the player.
BgInteractions:
    type: interact
    steps:
        1:
            click trigger:
                script:
                # If the player does not own the bodyguard and right clicks on them it will let them know it is not their bodyguard.
                - if <npc.owner> != <player> {
                    - narrate format:<npc.constant[NpcFormat]> "Im sorry im not your bodyguard."
                    # If the player does own the bodyguard the bodyguard will ask what the player what they want and enter order mode.
                    } else {
                    - narrate format:<npc.constant[NpcFormat]> "What would you like me to do?"
                    - narrate format:<npc.constant[NpcFormat]> "<red>Stand <gold>Guard, <red>Follow <gold>You, Change <red>Equipment<gold>, <red>Rename<gold> or <red>Reskin<gold>?"
                    - narrate format:<npc.constant[NpcFormat]> "Right click me again to cancel"
                    - narrate "<red>Entering Order Mode."
                    - ^zap step:2
                    }
        2:
            # If the player right clicks them again the bodyguard will exit order mode.
            click trigger:
                script:
                - narrate "<red>Exiting Order Mode."
                - zap step:1
            chat trigger:
                1: 
                    # If the player wants the guard they will say "follow" in chat near the bodyguard.
                    trigger: <gold>/Follow/ me.
                    script:
                    # Remember that BGGuarding flag earlier? Time to use it
                    # If the player has the BGGuarding flag the bodyguard will say they are already following the player.
                    - if <player.has_flag[BGGuarding]> {
                        - random {
                            - narrate format:<npc.constant[NpcFormat]> "Im already following you silly."
                            - narrate format:<npc.constant[NpcFormat]> "I am already following you."
                            - narrate format:<npc.constant[NpcFormat]> "Uhm... Okay."
                            }
                        # Lets the player know order mode has ended
                        - narrate "<red>Exiting Order Mode."
                        - zap step:1
                        # If the bodyguard is not already following the player it will let the player know it is now following them.
                        } else {
                        - random {
                            - narrate format:<npc.constant[NpcFormat]> "Alright I will follow you."
                            - narrate format:<npc.constant[NpcFormat]> "Do i have to?"
                            - narrate format:<npc.constant[NpcFormat]> "Lead the way."
                            - narrate format:<npc.constant[NpcFormat]> "As you wish."
                            }
                        # Selects the bodyguard.
                        - ^execute as_npc "npc sel <npc.id>"
                        # Tells the bodyguard to follow the player.
                        - ^execute as_npc "sentry guard <player.name>"
                        # Gives the player the BGGuarding flag again.
                        - ^flag player BGGuarding
                        # Lets the player know order mode has ended.
                        - narrate "<red>Exiting Order Mode."
                        - zap step:1
                        }
                2:
                    # If the player wants the bodyguard to stand in that spot the player will say "stand" in chat.
                    trigger: <gold>/Stand/ here.
                    script:
                    - if <player.has_flag[BGGuarding]> {
                    # Tells the player that the guard will stand in that spot.
                        - random {
                            - narrate format:<npc.constant[NpcFormat]> "I will guard this spot, talk to me again if you wish for me to follow you again."
                            - narrate format:<npc.constant[NpcFormat]> "I will wait here for you."
                            - narrate format:<npc.constant[NpcFormat]> "Dont forget about me."
                            - narrate format:<npc.constant[NpcFormat]> "Can I atleast get a book to read while i wait?"
                            }
                        # Selects the bodyguard.
                        - ^execute as_npc "npc sel <npc.id>"
                        # Tells the bodyguard to stop following the player.
                        - ^execute as_npc "sentry guard"
                        # Removes the BGGuarding flag from the player.
                        - ^flag player BGGuarding:!
                        # Lets the player know order mode has ended
                        - narrate "<red>Exiting Order Mode."
                        - zap step:1
                        # If the bodyguard is already standing guard they will let the player know.
                        } else {
                        - random {
                            - narrate format:<npc.constant[NpcFormat]> "I am already waiting here."
                            - narrate format:<npc.constant[NpcFormat]> "But I am not following you."
                            - narrate format:<npc.constant[NpcFormat]> "Uhh... Alright."
                            }
                        }
                3:
                    # If the player wishes to rename the bodyguard the player will say "rename" in chat near the bodyguard.
                    trigger: <gold>Id like to /Rename/ you.
                    script:
                    # The bodyguard will ask what the player wishes to rename the bodyguard to.
                    - narrate format:<npc.constant[NpcFormat]> "Alright what would you like to rename me as?"
                    # Lets the player know order mode has ended and rename mode has began.
                    - narrate "<red>Exiting Order Mode and Opening Rename Mode"
                    - zap step:3
                4:
                    # If the player wishes to give the bodyguard a new skin they say "reskin" in chat near the bodyguard.
                    trigger: I want to change your /Reskin/
                    script:
                    # Asks the player what they wish to change the bodyguards skin to.
                    - narrate format:<npc.constant[NpcFormat]> "Alright what would you like to change my skin to?"
                    # Lets the player know that order mode has exited and reskin mode has opened.
                    - narrate "<red>Exiting Order Mode and Opening Reskin Mode"
                    - zap step:4
                5:
                    # If the player wishes to change the bodyguards equipment they say "equipment" in chat near the bodyguard.
                    trigger: <gold> I want to change your /Equipment/.
                    script:
                    # Lets the player know if they have a bodyguard that does not respawn they will lose the equipment if it dies.
                    - narrate format:<npc.constant[NpcFormat]> "Keep in mind if you dont have a respawning bodyguard equipment will be lost on its death"
                    # Selects the npc.
                    - execute as_op "npc sel <player.flag[BodyGuard].replace[n@]>"
                    # Puts the npc into equip mode for 30 seconds.
                    - execute as_op "npc equip"
                    - narrate "<red>Equip Mode will end in 30 seconds."
                    # The 30 second timer.
                    - wait 30
                    # Disables equip mode.
                    - execute as_op "npc equip"
                    - zap step:1
        3:
            chat trigger:
                1:
                    # This is where the renaming happens if they player wishes to change the bodyguards name.
                    trigger: <gold>I want your new name to be /regex:.+/.
                    script:
                    # Selects the bodyguard.
                    - execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                    # Renames the bodyguard.
                    - execute as_server "npc rename <context.message>"
                    # Lets the player know rename mode has ended.
                    - narrate "<red>Exiting Rename Mode."
                    - zap step:1
        4:
            chat trigger:
                1:
                    # This is where the reskin happens if the player whishes to change the bodyguards skin.
                    trigger: <gold> I want you to take the skin of /regex:.+/.
                    script:
                    # Selecting the bodyguard.
                    - execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
                    # Re-skins the bodyguard.
                    - execute as_server "npc skin <context.message>"
                    # Lets the player know reskin mode has ended.
                    - narrate "<red>Exiting Reskin Mode."
                    - zap step:1

# This is the weapon the bodyguards use A diamond sword with knockback 2 enchant.
BodyguardSword:
    type: item
    material: DIAMOND_SWORD
    enchantments:
        - KNOCKBACK:2


# This is the command script used to teleport guards to a player
TeleportBodyGuard:
    type: command
    debug: false
    name: TpGuard
    description: Teleports your bodyguard to you.
    usage: /TpGuard
    script:
        - if !<player.has_flag[bodyguard]> {
            - narrate "<red>Error: You do not have a bodyguard."
            - queue clear
        } else <server.selected_npc> != <player.flag[BodyGuard]> {
            - ^execute as_server "npc sel <player.flag[BodyGuard].replace[n@]>"
            - if <server.selected_npc> != <player.flag[BodyGuard]> {
                - narrate "<red>ERROR: Can not find Bodyguard Please contact a Admin."
                - queue clear
            } else {
            - teleport <player.flag[BodyGuard]> <player.location>
            }
        }