Paste #11916: NPC SmartLook

Date: 2014/12/08 15:54:41 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# +-------------------
# | N P C
# | S M A R T L O O K
# |
# | NPCs that look around realistically!
#
# @author mcmonkey
# @date 2014 / 12 / 8
# @build 1546
# @version 1.0
#
# Installation:
# Copy into your scripts folder and /denizen reload scripts
#
# Usage:
# /npc select            # Select an NPC
# /ex flag npc smartlook # Enable smartlook functionality

npcsmartlook_world_handler:
    type: world
    debug: false
    events:
        on server start:
        - inject locally "events.on reload scripts"
        on reload scripts:
        - define queues <queue.list.filter[starts_with[npcsmartlook_task_run]]>
        - foreach %queues% {
          - queue %value% stop
          }
        - wait 5s
        - run npcsmartlook_task_run delay:10t

npcsmartlook_task_run:
    type: task
    debug: false
    script:
    - while true {
      - foreach <server.get_npcs_flagged[smartlook]> {
        - if !<def[value].has_flag[smartlookcooldown]> && <util.random.int[1].to[4]> == 1 && <def[value].is_spawned> {
          - define x <util.random.int[-5].to[5]>
          - define z <util.random.int[-5].to[5]>
          - define y <util.random.int[-2].to[2]>
          - look %value% <def[value].location.add[%x%,%y%,%z%]>
          - flag %value% smartlookcooldown duration:3s
          }
        }
      - wait 1s
      }