Paste #3341: Bakery Worker

Date: 2014/04/09 16:57:31 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# LNPC Baker Cycle
# Citizens 2.0.10-SNAPSHOT (build 979)
# Denizen 0.9.4-1.6.2-SNAPSHOT (build Unknown)
#
# At 6am an enabled NPC will wake up and walk to work.  At 7pm, the NPC will finish work and walk home to their bed.
#
# When the "LNPC_Baker" or "LNPC_Unlseep" scripts are assigned, they will automatically remove the assignment when setup is complete
#
# Usage:
# command:
# 
# /npc select <npc id>
# /npc assignment --set lnpc_Baker # adds the npc to the Baker Cycle
# /npc assignment --set lnpc_unBaker # removes the npc to the Baker Cycle
# 
# in script:
#  - assignment lnpc_Baker # adds the npc to the Baker Cycle
#  - assignment lnpc_unBaker # removes the npc to the Baker Cycle
#  
#  Optional Flags:
#  lnpc_work_assignment - if set, this assignment script will be assigned when the NPC reaches their work anchor
#  lnpc_Baker_assignment - if set, this assignment script will be assigned when the NPC reaches their bed anchor
#  
#  Example:
#  /ex flag npc lnpc_Baker_assignment:s@LNPCBakerInteract
# @author chromecide
# @script version 1.0.0
# @last-updated 8 April 2014

LNPC_BakerDirector:
  type: world
  events:
    on time changes in world:
    - run LNPC_BakerLoop
#Runs the Baker handler against the supplied npc
LNPC_BakerLoop:
    type: task
    script:
    # run the Baker handler
      - foreach <global.flag[lnpc_Baker_npcs].as_list> {
        - if !<%value%.flag[lnpc_sleep] run LNPC_BakerHandler as:n@%value%
        }
# UnBaker Assignment
"LNPC_UnBaker":
  type: assignment
  actions:
    on assignment:
      - if <global.flag[lnpc_Baker_npcs].aslist> contains '<npc.id>' flag global lnpc_Baker_npcs:<-:<npc.id>
      - narrate "<npc.name> has been removed from the Baker Cycle"
      - run LNPC_ClearBakerAssignment delay:10t
# Baker Assignment
"LNPC_Baker":
  type: assignment
  #Constants setup
  default constants:
    # Toggle the Baker Cycle on and off
    BakerCycle: true
  #action setup
  actions:
    # when this script is applied to an npc
    on assignment:
    - if <npc.anchor.list> contains work_oven && <npc.anchor.list> contains work_bench && <npc.anchor.list> contains work_chest {
      - if <global.flag[lnpc_Baker_npcs]> !contains '<npc.id>' {
        - ^flag global lnpc_Baker_npcs:->:<npc.id>
        - narrate "<npc.name> has been added to  the Baker Cycle"
        - run LNPC_ClearBakerAssignment delay:10t
        }
      } else {
      - narrate "<npc.name> does not have the required anchors to use the Baker Assignment.  Please create <green>work_oven <white>, <green>work_bench <white>and <green>work_chest <white>anchors for <npc.name>"
      - assignment remove
      }
    # when the npc is spawned
    on spawn:
    # add the npc to the server list of tracked npcs, if they aren't already on the list
    - if <global.flag[lnpc_Baker_npcs].aslist> !contains <npc.id> flag global lnpc_Baker_npcs:->:<npc.id>
    # when the npc is despawned
    on despawn:
    # remove the npc from server list of tracked lnpc_Baker_npcs, if they are on the list
    - if <global.flag[lnpc_Baker_npcs].aslist> !contains '<npc.id>' flag global lnpc_Baker_npcs:<-:<npc.id>
    # when the npc is removed
    on remove:
    # remove the npc from server list of tracked lnpc_Baker_npcs, if they are on the list
    - if <global.flag[lnpc_Baker_npcs].aslist> !contains '<npc.id>' flag global lnpc_Baker_npcs:<-:<npc.id>
    # when the npc has finished moving somwhere
    on complete navigation:
    #- if !<npc.flag[lnpc_Bakering]> && <npc.flag[lnpc_work_assignment]> {assignment <npc.flag[lnpc_work_assignment]>
    #- if <npc.flag[lnpc_Bakering]> assignment LNPC_BakeringAssignment
    # select the npc if they have the lnpc_Bakering flag set
    # - if <npc.flag[lnpc_Bakering]> == true execute as_npc "npc select <npc.id>"
    # set the npc to Baker in their bed anchor, if the lnpc_Bakering flag is set
    # - if <npc.flag[lnpc_Bakering]> == true execute as_npc "npc Baker --anchor:bed"
"LNPC_BakerAssignment":
  type: assignment
  interact scripts:
  - 10 LNPC_BakeringInteract
  actions:
    on assignment:
    # This enables interaction with NPC via clicking, entering proximity and damage.
    - trigger name:click toggle:true
    #- run LNPC_ClearBakerAssignment delay:10t
LNPC_BakeringInteract:
  type: interact
  steps:
    1:
      click trigger:
        script:
        - random {
          - chat "Hey There.  What I can get for you?"
          - chat "We have some bread fresh out of the oven, can I interest you in some?"
          - chat "Try our tasty Cakes!!" 
          }
# Clears the assignment for the npc 
LNPC_ClearBakerAssignment:
  type: task
  script:
  - assignment remove
  - narrate "<npc.name> is now ready to accept other assignments"
# Main Baker handler
LNPC_BakerHandler:
  type: task
  script:
  # if the Baker Cycle has been disabled, clear the script queue
  #- if <cons:BakerCycle> == false queue clear
  - announce "processing baker -  <npc.name>"
  - lookclose <npc> state:false
  # determine what the baker needs to do at the moment
  - ~walkto location:<npc.anchor[work_chest]>
  - animatechest <npc.anchor[work_chest].inventory.location> open sound:true <server.list_online_players>
  - wait 1s
  - if <npc.anchor[work_chest].inventory.qty[bread]> < 64 {
    - wait 1s
    - announce "we're running low on bread...let's check the wheat supplies!"
    - wait 1s
    - if <npc.anchor[work_chest].inventory.qty[wheat]> >= 64 {
      - announce "We should have enough to get by...better make some bread..."
      - announce <npc.anchor[work_chest].inventory.list_contents>
      - take i@wheat qty:30 from:<npc.anchor[work_chest].inventory>
      - animatechest <npc.anchor[work_chest].inventory.location> close sound:true <server.list_online_players>
      - ~walkto location:<npc.anchor[work_bench]>
      - wait 2s
      - ~walkto location:<npc.anchor[work_oven]>
      - wait 5s
      - ~walkto location:<npc.anchor[work_chest]>
      - animatechest <npc.anchor[work_chest].inventory.location> open sound:true <server.list_online_players>
      - wait 1s
      - give i@wheat qty:10 to:<npc.anchor[work_chest].inventory>
      - wait 1s
      - ~walkto location:<npc.anchor[work]>
      - lookclose <npc> state:true
      } else {
      - if <npc.anchor[work_chest].inventory.qty[wheat]> < 64 {
        - announce "Uh-Oh. Getting low on that too. What am I going to do? I better see if I can find someone to fetch me some more wheat."
        - animatechest <npc.anchor[work_chest].inventory.location> close sound:true <server.list_online_players>
        }
      }
    } else {
    - wait 1s
    - announce "got plenty of bread, what else should i do?"
    - walkto location:<npc.anchor[work]>
    }