Paste #20226: Tea Walker

Date: 2015/09/21 09:54:09 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


TeaWalker:
  Type: Assignment
  Debug: false
  Default Constants:
    PatrolPoints: Pacing1|Pacing2|Pacing3
  Actions:
    On Assignment:
     - flag <npc> Status:passive
     - flag <npc> Goal:seek
     - flag <npc> PatrolList:!
     - foreach <npc.constant[PatrolPoints]> {
       - flag <npc> PatrolList:->:%value%
     }

     - ^trigger name:click toggle:true

  interact scripts:
    - 1 TeaWalkerInteract

TeaWalkerInteract:
  type: interact
  Debug: false
  steps:
    1:
      click trigger:
        script:
          - run VillagerGoalSwitcher

"VillagerGoalSwitcher":
  type: task
  debug: false
  script:
  - if <npc.flag[Goal]||patrol> == patrol {
    - narrate "<npc.name> will follow you!"
    - pause waypoints
    - flag <npc> Goal:seek
    - run VillagerSeek def:<player> delay:2s
  }
  else if <npc.flag[Goal]||patrol> == seek {
    - narrate "<npc.name> will patrol!"
    - pause waypoints
    - flag <npc> Goal:patrol
    - run VillagerPatrol delay:2s

  }

"VillagerPatrol":
  type: task
  debug: true
  script:
  - while <npc.is_spawned||false> {
    - if <npc.flag[Status]||passive> == passive && <npc.flag[Goal]||null> == patrol {
      - if <npc.flag[PatrolList].as_list.size> <= <npc.flag[HasChecked].as_list.size||0> {
        - flag <npc> HasChecked:<npc.flag[CurrentTarget]>
      }
      - flag <npc> CurrentTarget:!
      - flag <npc> CurrentTargetDistance:!
      - foreach <npc.flag[PatrolList].as_list> {
        - if <npc.flag[HasChecked].as_list.contains[%value%]||false> {
          - foreach next
        }
        else {
          - flag <npc> DistanceTo%value%:<npc.location.distance[<server.flag[%value%]>]>
          - if <npc.flag[CurrentTargetDistance]||100> > <npc.flag[DistanceTo%value%]> {
            - flag <npc> CurrentTarget:%value%
            - flag <npc> CurrentTargetDistance:<npc.flag[DistanceTo%value%]>
          }
        }
      }
      - pause navigation
      - ~walk <npc> <server.flag[<npc.flag[CurrentTarget]>].as_location> radius:5
      - wait 2s
      - flag <npc> HasChecked:->:<npc.flag[CurrentTarget]>
    }
    else {
      - queue clear
    }
  }

"VillagerSeek":
  type: task
  debug: false
  script:
  - while <npc.is_spawned||false> {
    - if <npc.flag[Status]||passive> == passive && <npc.flag[Goal]||null> == seek && <npc.location.distance[<def[1].location>]> < 25 {
      - if <npc.location.distance[<def[1].location>]> > 5 {
        - pause waypoints
        - ~walk <npc> <npc.location.find.players.within[25].get[1].location.cursor_on[2].ignore[tall_grass|double_tallgrass]> radius:4
      }
      else {
        - wait 10t
      }
    }
    else {
      - pause waypoints
      - queue clear
    }
  }