Paste #581: Prison Guard Manager, for DrVonNoobenstein

Date: 2013/12/17 00:22:29 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# | Prison Guard Manager
# A quick example script for guards that patrol by night, but guard a specific location by day

# | How to create a prison guard
# | Step 1:
# Create an NPC
# Command: /npc create NAMEHERE
# | Step 2:
# Mark it as a prison guard
# Command: /ex flag <npc> prison_guard
# | Step 3:
# Identify its home point
# Walk to where it should stand around at day time
# Command: /ex flag <npc> prison_guard_basepoint:<player.location>
# | Step 4:
# Identify its night time patrol path
# Walk to each point on the path and do:
# Command: /ex flag <npc> prison_guard_locs:->:<player.location>

# This world script tells the guards when to patrol or not
prison_guard_manager:
    type: world
    events:
        # Note: if your world is not name named 'world', change that in the line below
        on 19:00 in world:
        # Unfortunately, we can't directly link this to an NPC... so find NPCs who are involved by looping through all NPCs
        - foreach <server.list_npcs> {
          - if !<%value%.flag[prison_guard]> queue clear
          - flag %value% prison_guard_patrol_point:0
          - flag %value% prison_guard_should_patrol:true
          - run prison_guard_patrol_task delay:1s as:%value%
          }
        # Note: if your world is not name named 'world', change that in the line below
        on 7:00 in world:
        - foreach <server.list_npcs> {
          - if !<%value%.flag[prison_guard]> queue clear
          - flag %value% prison_guard_should_patrol:false
          - walk <%value%.flag[prison_guard_basepoint]> auto_range npc:%value%
          }

# This task makes it walk around on patrol
prison_guard_patrol_task:
    type: task
    script:
    - ^if !<npc.flag[prison_guard_should_patrol]> queue clear
    - ^if <npc.navigator.is_navigating> {
      - run prison_guard_patrol_task delay:2s
      - queue clear
      }
    - ^flag <npc> prison_guard_patrol_point:++
    - ^if <npc.flag[prison_guard_patrol_point]> > <npc.flag[prison_guard_patrol_locs].size> flag <npc> prison_guard_patrol_point:1
    - ^walk <npc.flag[prison_guard_patrol_locs].get[<npc.flag[prison_guard_patrol_point].asint>]> auto_range
    - run prison_guard_patrol_task delay:2s