Paste #39838: Untitled Paste

Date: 2017/02/11 00:36:28 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# NPC Townsmen
# Citizens 2 (build #992)
# Denizen 0.9.3 (build #1352)
#
# @author Hyruii
#
# FOR EASY SETUP
# 1) Press ctr-h to find all 'world10' 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@778,77,1038,world10"
    # Location of Farm
    - ^flag global "Farm:l@852,76,1032,world10"
    # Location of General Shop
    - ^flag global "General:l@819,76,1036,world10"
    # Location of Park
    - ^flag global "Park:l@220,64,810,world10"
    # Location of Inn
    - ^flag global "Inn:l@230,70,791,world10"
    # Location of Cafe
    - ^flag global "Cafe:l@223,65,820,world10"

   # Use your own server name to replace world10
   on 6:00 in world10:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <fl@npclist.as_list> {
     - run npcid:%value% wake
     }

   # Use your own server name to replace world10
   on 11:00 in world10:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <fl@npclist.as_list> {
     - run npcid:%value% lunch
     }  

   # Use your own server name to replace world10
   on 13:00 in world10:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <fl@npclist.as_list> {
     - run npcid:%value% work
     }

   # Use your own server name to replace world10
   on 18:00 in world10:
    # Loop checking trait of list of NPC assigned as townsmen.
    - foreach <fl@npclist.as_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 <fl@npclist.as_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 world10 with own server name.
          - define greeting "<w@world10.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