Sentry Helper Script


Author: Wolf
Created: 2013-04-20T20:20:59-0400
Edited: 2013-06-14T05:37:56-0400
Denizen Version: .8.8.0
Views: 75
Downloads: 952
Likes: 1


WGET
Description: This is a mostly done version of my Sentry Helper Script. This means the npc must be sentry (/trait sentry) AND have this script for it to work.

It's purpose is to make it so you can do everything you need to do with a sentry, without using commands or having the right permissions (minus equipment editor, need permissions for that). You can order your sentry though an easy to follow dialogue and tell him to Follow you, Guard the location (he will move from the location if there is an enemy), Patrol across waypoints (custommade script so its all dialogue ), Equip, Attack enemies of type xxxx on sight, remove attack enemies of type xxxx on sight, or you can even ask him for help if a player is confused.


DO NOT mess with StopPatrolling task unless you know what youre doing. Its a loop and if you make it an infinite loop on accident your server WILL Crash.

Really appreciate any comments if there are bugs, thanks :D

NOTE: When you first assign the npc as a SentryHelper, give him the trait sentry as well.

NOT WORKING:
Towns, Nations, PvP in attack orders and removal

EDIT: 4/28/13:
Added necessary check for if the npc despawns/spawns due to player login or logout.
Fixed waypoints, whoops :(

EDIT: 6/14/13:
Totally uploaded wrong version, the only issue now is when you log out sometimes the npc goes into a temporary glitch mode if he was on a path. You can fix this just by messing with him a bit. I'm going to revisit this script soon and I'll redo it :D

"SentryHelper":
   type: assignment
 
    #used for patrolling
   interact scripts:
   - 10 Helper
   - 20 Patroller

   actions:
     on assignment:
     - trigger name:chat toggle:true 
     - trigger name:proximity toggle:true radius:4
     - ^Flag npc spawned:1
     
     on enter proximity:
     - runtask "PatrolCheck"
     
     on spawn:
     - ^Flag npc spawned:1
     - runtask "WaypointCheck"
     
     on despawn:
     - ^Flag npc spawned:0
 
 
 
 
 
     #used for patrolling
     on complete navigation:
     - runtask "script:PatrolClock"
'Helper':
   Requirements:
       Mode: All
       List:
       - owner
   type: interact

   steps:
       'NotActivated*':
           click trigger:
               script:
               - chat 'What do you want me to do sir?'
               - ^narrate '/Follow/, /Guard/, /Patrol/, /Equip/, /Attack/, /Stop Attacking/, /H/elp, /C/ancel'
               - ^zap 'step:Activated'
        #Main menu script after npc has been activated       
       'Activated':                                                                    
           click trigger:
               script:
               - narrate '<&4>Sentry is in order mode.'
               - ^narrate '/Follow/, /Guard/, /Patrol/, /Equip/, /Attack/, /Stop Attacking/, /H/elp, /C/ancel'
           chat trigger: #All different orders 
              'OrderFollow':
                  trigger: '/Follow/ me.'
                  script:
                  - chat 'Yes sir'
                  - ^execute AS_SERVER "sentry <npc.id> guard <player.name>"
                  - ^zap 'step:NotActivated'
                  
              'OrderGuard':
                  trigger: '/Guard/ this area.'
                  script:
                  - chat 'Yes sir'
                  - ^execute AS_SERVER "sentry <npc.id> guard"  
                  - ^zap 'step:NotActivated'
                  
              'OrderPatrol':
                  trigger: '/Patrol/ these points.'
                  script:
                  - runtask "step:Patrol"
              
              'OrderEquip':
                  trigger: '/Equip/ these items.'
                  script:
                  - ^execute AS_OP "npc select <npc.id>"
                  - ^execute AS_OP "npc equip"
                  - chat "Give me what you want me to equip.  Tell me when you're done."
                  - ^narrate '/Done/'
                  - ^zap 'step:Equipment'
              'OrderAttack':
                  trigger: '/Attack/ these enemies.'
                  script:
                  - say "List who you want me to attack"
                  - ^narrate '/Mobs/, /Person/, /Nation/, /Town/, /PvP/, /Done/'
                  - ^zap 'step:AttackOrders'
              'OrderStopAttack':
                  trigger: '/Stop Attacking/ these enemies.'
                  script:
                  - say "List who you dont want me to attack"
                  - ^narrate '/Mobs/, /Person/, /Nation/, /Town/, /PvP/, /Done/'
                  - ^zap 'step:AttackOrdersRemove'
              'Help':
                  trigger: '/H/elp'
                  script:
                  - narrate 'Sentries are NPCs that can guard you or an area around you.  You can equip them, tell them to guard an area, tell them to guard you, or tell them to patrol around points.'
                  - wait 3
                  - narrate 'To do so, right click on your sentry and give him in order'
                  - wait 5
                  - narrate 'Orders can be'
                  - narrate '          /Follow/ me.'
                  - narrate '          /Guard/ this area.'
                  - narrate '          /Patrol/ these points. 
                  - narrate '          /Equip/ these items.'
                  - narrate '          /Attack/ these enemies.'
                  - narrate '          /Stop Attacking/ these enemies.'
                  - ^narrate '<&4>Warning, guard order will not result in sentry returning to starting point after killing enemies.<&f>'
                  - ^narrate 'Use patrol with one waypoint instead.'
              'Cancel':
                  trigger: '/C/ancel'
                  script:
                  - chat 'Alright.'
                  - ^zap 'step:NotActivated'
               #If equipment order is issued
       'Equipment':
           chat trigger:
              'Finished':
                  trigger: '/Done/'
                  script:
                  - chat "Ok."
                  - ^execute AS_PLAYER "npc equip"
                  - ^zap 'step:NotActivated'
                  #If waypoint order is used.  Note, does not use default /npc path because it is impossible to make it work
                  #with denizens.  Uses custommade editor.
 
 
 
 
 
               #if npc has been ordered to enter attack orders menu
       'AttackOrders':
           click trigger:
              script:
              - narrate '<&4>In attack orders menu'
              - ^narrate '/Mobs/, /Person/, /Nation/, /Town/, /PvP/, /Done/'
           chat trigger:
              'HostileMobs':
                  trigger: 'Attack all hostile /Mobs/'
                  script:
                  - ^execute AS_SERVER "sentry <npc.id> target add entity:monster"
                  - say "Yes sir."
              'PlayerName':
                  trigger: 'Attack this /Person/.'
                  script:
                  - say "What player should I attack?"
                  - ^narrate 'enter player name or /Cancel/'
                  - ^zap 'step:NameAttackOrders'

              'Finished':
                  trigger: '/Done/'
                  script:
                  - chat "Ok, I will attack these enemies on sight."
                  - ^execute AS_OP "sentry target list"
                  - ^zap 'step:NotActivated'
                  #if npc has been ordered to enter attack orders removal menu 
       'AttackOrdersRemove':
           click trigger:
              script:
              - narrate '<&4>In attack order removal menu'
              - ^narrate '/Mobs/, /Person/, /Nation/, /Town/, /PvP/, /Done/'
           chat trigger:
              'HostileMobs':
                trigger: 'Stop attacking hostile /Mobs/ on sight'
                script:
                - ^execute AS_SERVER "sentry <npc.id> target remove entity:monster"
                - say "Yes sir."
              'PlayerName':
                  trigger: 'Stop attacking this /Person/.'
                  script:
                  - say "What player should I not attack?"
                  - ^narrate 'enter player name'
                  - ^zap 'step:NameAttackOrdersRemove'

              'Finished':
                trigger: '/Done/'
                script:
                - chat "Ok, I will attack these enemies on sight."
                - ^execute AS_PLAYER "sentry target list"
                - ^zap 'step:NotActivated'
                #If they choose to add a name to the attacking list
       'NameAttackOrders':
          click trigger:
              script:
              - narrate '<&4>Waiting for input'
              - ^narrate 'enter player name or /Cancel/'
          chat trigger:
              'Stop':
                  Trigger: '/Cancel/'
                  Script:
                  - chat "Yes sir."
                  - ^zap "step:AttackOrders"
                  - ^narrate '/Mobs/, /Person/, /Nation/, /Town/, /PvP/, /Done/'
              'Input':
                  Trigger: /REGEX:\w+/
                  Script:
                  - Flag Denizen inputSentryFlag:<player.chat_history>
                  - ^execute AS_SERVER "sentry <npc.id> target add player:<flag.d:inputSentryFlag>"
                  - chat "Yes sir."
                  - ^zap 'step:NotActivated'
                  #If they choose to remove a name from the attacking list.
       'NameAttackOrdersRemove':
          click trigger:
              script:
              - narrate '<&4>Waiting for input'
              - ^narrate 'enter player name or /Cancel/'
          chat trigger:
              'Stop':
                  Trigger: '/Cancel/'
                  Script:
                  - chat "Yes sir."
                  - ^zap "step:AttackOrdersRemove"
                  - ^narrate '/Mobs/, /Person/, /Nation/, /Town/, /PvP/, /Done/'
              'Input':
                  Trigger: /REGEX:\w+/
                  Script:
                  - Flag Denizen inputSentryFlag:<player.chat_history>
                  - ^execute AS_SERVER "sentry <npc.id> target remove player:<flag.d:inputSentryFlag>"
                  - chat "Yes sir."
                  - ^zap 'step:NotActivated'
'Patroller':
   Requirements:
       Mode: All
       List:
       - owner
       - flagged npc isPatrolling:1
   type: interact
   steps:
      'Editor*':
          click trigger:
              script:
              - ^narrate '<&4>In patrol editor'
              - ^narrate '/Add/ point, /Done/, /Cancel/'
          chat trigger:
              'Cancel':
                  trigger: '/Cancel/.'
                  script:
                  - chat "Alright."
                  - Flag npc isPatrolling:0
              'Finished':
                  trigger: '/Done/.'
                  script:
                  - chat "Ok, patrolling <flag.n:points.asint> points."
                  - zap "step:PatrollingNow"
                  - runtask "script:StartPatrolling"
              
              'Adding':
                  trigger: '/Add/ point.'
                  script:
                  - ^chat "Alright, added station."
                  - ^Flag npc points:+
                  - ^execute AS_NPC 'npc select <npc.id>'
                  - ^execute AS_NPC "npc tpto '<npc.id>' '<npc.owner>'"
                  - ^execute as_npc 'npc anchor --save "Anchor <flag.n:points.asint>"'
      'PatrollingNow':
          click trigger:
              script:
              - ^narrate "<&4><npc.name> is patrolling."
              - ^narrate "/Stop/."
          chat trigger:
              'Finished':
                  trigger: "/Stop/."
                  script:
                  - chat "Ok"
                  - ^zap "script:Patroller" "step:Editor"
                  - ^zap "script:Helper" "step:NotActivated"
                  - ^flag npc isPatrolling:0
                  - ^runtask "script:StopPatrolling"
                  - ^flag npc pointsOn:0
                  - ^execute AS_NPC "npc select <npc.id>"
'Patrol':
    type: task
    script:
    - chat "Alright, let me know what points to add."
    - ^narrate "/Add/ point, /Done/, /Cancel/"
    - ^Flag npc isPatrolling:1
    - ^Flag npc points:0

'StartPatrolling':
    type: task
    script:
    - ^Flag npc pointsOn:1
    - ^execute AS_NPC 'npc select <npc.id>'
    - ^execute AS_NPC 'sentry guard'
    - ^walkto 'location:<anchor:Anchor <flag.n:pointsOn.asint || 1>>'
    
'PatrolClock':
    type: task
    script:
    - if "<flag.n:pointsOn>" == "<flag.n:points>" Flag npc pointsOn:1 else Flag npc pointsOn:+
    - runtask "PatrolAgain" "queue:patrolQueue" "delay:15"

'PatrolAgain':
    type: task
    script:
    - ^if '<flag.n:spawned>' == 1 walkto 'location:<anchor:Anchor <flag.n:pointsOn.asint || 1>>'
    
'PatrolCheck':
    type: task
    script:
    - if '<flag.n:isPatrolling>' == 1 walkto 'location:<npc.location>'
    
'StopPatrolling':
    type: task
    script:
    - ^execute AS_NPC 'npc anchor --remove Anchor <flag.n:points.asint>'
    - ^Flag npc points:-
    - ^if '<flag.n:points>' > 0 runtask StopPatrolling
    
'WaypointCheck':
    type: task
    script:
    - if '<flag.n:isPatrolling>' == 1 runtask "script:PatrolClock"
 




Comments
2013-04-21 01:22:25 - Wolf:

Any suggestions on how to get waypoints working are appreciated!
2013-04-24 11:25:19 - Wolf:

Waypoints working.
2013-04-24 11:36:42 - Wolf:

Waypoints working.
2013-06-10 15:29:06 - Loodrogh:

Hi! Very cool script. Thx alot for posting! I try to learn from this... Just a question! Waypoints are not working for me. Im using newest versions of all (bukkit citizens denizen sentry and some more stuff) I can add waypoints but not very easy. I have to stand too close to my npc so i cant give him waypoints which are far away. Maybe when he follows? No think i tried and he stops at first waypoint... So I give him for example 4 waypoints but he dont move! And Guard... is it usefull? As far as i understood you have to give him that one waypoint patrol task to keep him in position... I also tried everything with the /npc path command. I know you wrote its not working together but for me its the only way to let him patrol/guard (also with one waypoint) an area... Any Idea?
2013-06-14 09:36:25 - Wolf:

Hey someone likes my script! :D I was away from scripting but I think I uploaded the wrong version, not the final. I'll probably be revisiting this script later but for now I just edited in the correct script. The only problem I've been having with this one is sometimes you have to go near him and then leave to get him patrolling again if you log out near him. But yea, I HATE using commands and while the /npc path is nice, its impossible to incorporate into a denizen.
2013-06-14 09:40:09 - Wolf:

Ooooh also Lood, he won't move until after you walk away from him. This was designed so if you walk near him when he's patrolling he'll stop and you can talk to him. Kinda hard to tell him to stop when hes walking around :D
2013-08-05 06:17:28 - auron117:

i dont get it i assigned him trait sentry he asks what i want him to do then he does not do it. what am i missing thanks