Townsmen


Author: Hyruii
Created: 2013-12-26T22:07:34-0500
Edited: 2014-02-12T10:08:30-0500
Denizen Version: 0.9.3
Views: 140
Downloads: 894
Likes: 1


WGET
Description: NPC townsmen are scripted to open their doors at dawn (06:00) and walk to a location.
At midday (11:00), NPC will walk to another location for lunch.
At afternoon (13:00), NPC will walk to another location.
At dusk (18:00), NPC will walk to their home and close the switch.

Only locations have to be customized to your world (x, y, z, world).

# FOR EASY SETUP
# 1) Press ctr-h to find all 'Wolf Den' and replace with your server name.
# 2) Replace all locations in "globaltime" with your own x,y,z,world.
# 3) Put levers inside their homes beside their doors.
# 4) Create anchors named 'home' for each Townsmen NPC, which is located inside their house. (within 3 blocks from their door)
# 5) Select the NPC and type /npc assign --set "townsmen"

# NPC Townsmen
# Citizens 2 (build #992)
# Denizen 0.9.3 (build #1352)
#
# @author Hyruii
#
# FOR EASY SETUP
# 1) Press ctr-h to find all 'Wolf Den' and replace with your server name.
# 2) Replace all locations in "globaltime" with your own x,y,z,world.
# 3) Put levers inside their homes beside their doors.
# 4) Create anchors named 'home' for each Townsmen NPC, which is located inside their house. (within 3 blocks from their door)
# 5) Select the NPC and type /npc assign --set "townsmen"

"globaltime":
  type: world

  events:
   
   on server start:
    # Flag all the town locations.
    # Location of Blacksmith
    - ^flag global "Blacksmith:l@235,66,782,Wolf Den"
    # Location of Farm
    - ^flag global "Farm:l@257,69,822,Wolf Den"
    # Location of General Shop
    - ^flag global "General:l@224,65,783,Wolf Den"
    # Location of Park
    - ^flag global "Park:l@220,64,810,Wolf Den"
    # Location of Inn
    - ^flag global "Inn:l@230,70,791,Wolf Den"
    # Location of Cafe
    - ^flag global "Cafe:l@223,65,820,Wolf Den"
 
   # Use your own server name to replace Wolf Den
   on 6:00 in Wolf Den:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <[email protected]_list> {
     - run npcid:%value% wake
     }
 
   # Use your own server name to replace Wolf Den
   on 11:00 in Wolf Den:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <[email protected]_list> {
     - run npcid:%value% lunch
     }  
 
   # Use your own server name to replace Wolf Den
   on 13:00 in Wolf Den:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <[email protected]_list> {
     - run npcid:%value% work
     }
 
   # Use your own server name to replace Wolf Den
   on 18:00 in Wolf Den:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <[email protected]_list> {
     - run npcid:%value% sleep
     }

"townsmen":
  type: assignment
 
  interact scripts:
  # Priority starts from 10.
  - 10 Townsmen Chat
  
  actions:
    on assignment:
     # These triggers enable/disable interaction with an NPC via chatting, clicking and entering proximity.
     - trigger name:chat toggle:false
     - trigger name:click toggle:false
     - trigger name:proximity toggle:true radius:2
 
     # Add NPC id to npclist upon assignment.
     - if <[email protected]_list> contains '<npc.id>' {
       - narrate 'I am already a townsmen'
       }
       else {
       - flag global "npclist:->:<npc.id>"       
       }
 
    # on despawn:
    
    on complete navigation:
     # Check that if NPC has walked home, it will close the door.
     # If NPC is at lunch, eating/drinking sound will play.
     - if <npc.location.simple> equals <npc.anchor[home].simple> {
       - define hlever <npc.location.find.blocks[lever].within[1.1]>
       - foreach %hlever% {
       - switch %value% state:off
       }
      }
       else {
       - if <npc.location.simple> equals <flag.global:[Tavern|Cafe].simple> {
         - random 2
         - playsound <npc.location> sound:eat
         - playsound <npc.location> sound:drink
         }
       }

    on remove assignment:
     # Removes NPC id from npclist upon another assignment.
     - flag global "npclist:<-:<npc.id>"

    on remove:
     # Removes NPC id from npclist upon removal.
     - flag global "npclist:<-:<npc.id>"

"Townsmen Chat":
  type: interact
  
  steps:
    1:
      proximity trigger:
        entry:
          script:
          # Replace Wolf Den with own server name.
          - define greeting "<w@Wolf Den.time.period>"
          - narrate "<npc.name> smiles at you."
          - chat "Good %greeting%, <player.name>."
 

wake:
  type: task
  
  script:
   # NPC will use switch to open the door and walk to a location.
   # NPC will use switch inside house to open the door.
   - define hlever <npc.location.find.blocks[lever].within[1.1]>
   - foreach %hlever% {
     - switch %value% state:on
     }
   # NPC will randomly choose a location to visit.
   - random 4
   - inject locally blacksmith
   - inject locally farm
   - inject locally general
   - inject locally park
   
  blacksmith:
   - equip shears
   - walk <flag.global:Blacksmith> speed:0.8 auto_range
   
  farm:
   - equip stone_hoe
   - walk <flag.global:Farm> speed:0.8 auto_range
   
  general:
   - equip paper
   - walk <flag.global:General> speed:0.8 auto_range
   
  park:
   - equip red_rose
   - walk <flag.global:Park> speed:0.8 auto_range
 
lunch:
  type: task
  
  script:
   # NPC will randomly choose the inn/tavern/cafe to walk to for lunch.
   - random 2
   - walk <flag.global:Inn> speed:0.8 auto_range
   - walk <flag.global:Cafe> speed:0.8 auto_range
 
work:
  type: task
  
  script:
   # NPC will randomly choose a location to walk to.
   - random 4
   - inject locally blacksmith
   - inject locally farm
   - inject locally general
   - inject locally park
   
  blacksmith:
   - equip shears
   - walk <flag.global:Blacksmith> speed:0.8 auto_range
   
  farm:
   - equip stone_hoe
   - walk <flag.global:Farm> speed:0.8 auto_range
   
  general:
   - equip paper
   - walk <flag.global:General> speed:0.8 auto_range
   
  park:
   - equip red_rose
   - walk <flag.global:Park> speed:0.8 auto_range
 
sleep:
  type: task
  
  script:
   # Stops the NPC wandering and make it walk home.
   - walk <npc.anchor[home]> speed:0.8 auto_range




Comments
2014-03-22 01:19:42 - darthriddle:

I need help with this, I have followed the directions (I think) and the npc just stand in the doorways never leaving. Please help: Skype me :MCEmpire.co