Fidgeting NPC


Author: |Anthony|
Created: 2014-02-28T08:10:13-0500
Edited: 2014-05-06T18:58:34-0400
Denizen Version: 0.9.4
Views: 43
Downloads: 855
Likes: 1


WGET
Description: F i d g e t i n g N P C

Author: |Anthony|
Version: 1.0
dScript Version: 0.9.4-b1471

Make any NPC pace, or fidget, around a central location.
Reference the assignment script example and the Init script example as needed.
Odd results when applied to non-player NPC types.

You can also just pass the info needed to any npc as you need to with
- ^run s@Fidget def:radius|speed|wait|location|height|pathmat id:<npc.id>_YourQueueID
Use queue command to stop fidgeting later.
- ^queue <npc.id>_YourQueueID stop


See the script comments for additional info.

################################################################################
#
#                           F i d g e t i n g   N P C 
#
#   Author: |Anthony|
#   Version: 1.0
#   dScript Version: 0.9.4-b1471
#
# Make any NPC pace, or fidget, around a central location.
# Reference the assignment script example and the Init script example as needed.
# Odd results when applied to non-player NPC types.
#
#
# U S A G E
#
# Create player type NPC
#   /npc create FidgetingFred
# Define the starting location:
#   /ex flag npc Pathfind.FidgetLocation:<npc.location>
#   OR use the example in the Init script.
# Set the fidget radius
#   /ex flag npc Pathfind.FidgetRadius:[someNumber]
#   Default fidget radius is 5 blocks.
# Set the fidget speed
#   /ex flag npc Pathfind.FidgetSpeed:[someNumber]
#   Default fidget speed is 0.8
# Set the assignment script
#   /npc assignment --set 'FidgetingNPC'
# Now that the NPC is already set up you can adjust the NPC type
#   /npc type chicken
#
################################################################################
#
#'FidgetingNPC':
#  type: assignment
#
#  default constants:
#    npctype: "FidgetingNPC"
#
#  actions:
#    on assignment:
#      - run s@FidgetingInit instantly
#    on spawn:
#      - run s@FidgetingInit instantly
#    on despawn:
#      - run s@FidgetStop instantly
#    on exit proximity:
#      - run s@Fidget id:<npc.id>_fidgetQueue
#    on enter proximity:
#      - queue <npc.id>_fidgetQueue stop
#      - walk <player.location> radius:2
#    on unavailable:
#      - narrate 'You tap <npc.name> on the shoulder.'
#
#'FidgetingInit':
#  type: task
#  script:
#    - ^trigger name:chat state:false
#    - ^trigger name:click state:false
#    - ^trigger name:proximity state:true radius:5
#    - ^trigger name:damage state:false
#    - ^lookclose true range:4 realistic
#    - ^if !<npc.flag[Pathfind.FidgetLocation]> {
#      - ^flag npc Pathfind.FidgetLocation:<npc.location>
#      }
#      else walk <npc.flag[Pathfind.FidgetLocation]> speed:0.8
#    - run s@Fidget id:<npc.id>_fidgetQueue
#
################################################################################
 

'Fidget':
#
# Directly pass info to the fidget script for one time uses
#
# - ^run s@Fidget def:radius|speed|wait|location|height|pathmat id:<npc.id>_YourQueueID
#
    type: task
    debug: false
    script:
      - ^if !<npc.is_spawned> queue clear
      - ^define radius '<def[1] || <npc.flag[Pathfind.FidgetRadius] || 5>>'
      - ^define speed '<def[2] || <npc.flag[Pathfind.FidgetSpeed] || 0.6>>'
      - ^define wait '<def[3] || <npc.flag[Pathfind.FidgetWait] || 10>>'
      - ^define FidgetLocation '<def[4] || <npc.flag[Pathfind.FidgetLocation] || <npc.location>>>'
      - ^define FidgetHeight '<def[5] || <npc.flag[Pathfind.FidgetHeight] || 4>>'
      - ^define pathMaterial '<def[6] || <npc.flag[Pathfind.FidgetPathMaterial] || cobblestone|coal_block|cobblestone_stairs>>'
      - ^define counter 0
      - inject s@FidgetChooseLocation instantly
      - wait <util.random.int[<def[wait].mul[0.5].as_int>].to[<def[wait].mul[1.5].as_int>]>s
      - inject s@Fidget
 

'FidgetChooseLocation':
    type: task
    debug: true
    script:
      - define target '<def[FidgetLocation].as_location.find.surface_blocks[<def[pathMaterial]>].within[<def[radius]>].random>'
      - define counter '<def[counter] || 0>'
 
      - if <def[counter].is[LESS].than[5]> {
        - if <def[target].distance[%FidgetLocation%].vertical.is[OR_LESS].than[%fidgetHeight%]> {
          - walkto %target% speed:%speed%
          }
          else {
          - define counter <math:%counter%+1>
          - inject s@FidgetChooseLocation instantly
          }
        }
 

'FidgetStop':
# Phasing this out. Doesn't make sense to make a task for one queue command
    type: task
    debug: false
    script:
      - ^queue <npc.name>_fidgetQueue stop
      - ^queue <npc.id>_fidgetQueue stop




Comments
2014-03-01 07:17:40 - joeistek:

Looks Cool ^^