Paste #30521: Untitled Paste

Date: 2016/02/18 20:48:55 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#############################
# File for Behaviour Module #
#############################

####################################################
# Task script for initalising the behaviour module #
####################################################
Initialise_Module_Behaviour:
  type: task
  script:
  - if <yaml[config].list_keys[framework.modules].contains[npcs].not> || <server.has_file[../dFramework/NPC/yml].not> {
    - debug error "Dependency: NPCs module could not be found"
    - queue clear
    }

  - yaml id:config set "framework.modules.behaviour.description:This module requires the npcs module to work. Provides a library of scripts for behaviours."
  - yaml id:config set framework.modules.behaviour.enabled:null
  - yaml id:config set framework.modules.behaviour.files:->:null
  - yaml savefile:../dFramework/config.yml id:config

  - yaml id:npcs set behaviour.chat:3
  - yaml id:npcs set behaviour.click:5
  - yaml id:npcs set behaviour.proximity:3
  - yaml id:npcs set behaviour.lookclose:3

  - yaml id:npcs set behaviour.pauseVariable:0|20
  - yaml id:npcs set behaviour.speed:0.9

  - yaml savefile:../dFramework/NPC/yml id:npcs

######################################################################
# Task script for assigning triggers and lookclose states for an NPC #
######################################################################
Assign_Triggers:
  type: task
  definitions: chat|click|proximity|lookclose
  script:
  - if <yaml.list.contains[npcs].not> {
    - debug error "Module: Behaviour either could not be loaded or could not be found"
    - queue clear
    }
  - trigger name:chat state:true range:<def[chat].as_int||<yaml[npcs].read[behaviour.chat]>>
  - trigger name:click state:true range:<def[click].as_int||<yaml[npcs].read[behaviour.click]>>
  - trigger name:proximity state:true range:<def[proximity].as_int||<yaml[npcs].read[behaviour.proximity]>>
  - lookclose <npc> state:true range:<def[lookclose].as_int||<yaml[npcs].read[behaviour.lookclose]>> realistic
  - queue clear

################################################
# Task script for assigning walk related flags #
################################################
Assign_Walk_Flags:
  type: task
  definitions: min|max|speed
  script:
  - if <yaml.list.contains[npcs].not> {
    - debug error "Module: Behaviour either could not be loaded or could not be found"
    - queue clear
    }
  - flag <npc> walk
  - flag <npc> pauseMin:<def[min].as_int||<yaml[npcs].read[behaviour.pauseVariable].get[1]>>
  - flag <npc> pauseMax:<def[min].as_int||<yaml[npcs].read[behaviour.pauseVariable].get[2]>>
  - flag <npc> speed:<def[min].as_int||<yaml[npcs].read[behaviour.speed]>>

###################################
# Task script to make an NPC Walk #
###################################
Walk:
  type: task
  debug: false
  script:
  - flag <npc> walkQueue:<queue>
  - while <npc.has_flag[walk]> {
    - if <npc.location.chunk.is_loaded.not> {
      - queue pause
      }
    - flag <npc> anchorPoint:<npc.anchor.list.random>
    - ~walk <npc> <npc.anchor[<npc.flag[anchorPoint]>]> speed:<npc.flag[speed]> auto_range
    - wait <util.random.int[<npc.flag[pauseMin]>].to[<npc.flag[pauseMax]>]>
    }
  - queue clear

#########################################################
# World script that re-runs walk scripts and hides NPCs #
#########################################################
Behaviour_Manager:
  type: world
  debug: false
  events:
    on server start:
    - wait 1t
    - foreach <server.list_filter[has_flag[walk]]> {
      - run Walk npc:<def[Value].as_npc>
      }
    - queue clear

    on chunk loads:
    - wait 1t
    - foreach <chunk.living_entities.filter[has_flag[walk]]> {
      - if <def[value].as_npc.flag[walkQueue].state> == "paused" {
        - queue <def[value].as_npc.flag[walkQueue].state> resume
        }
      }    

    on player joins:
    - if <player.has_flag[debug]
    - foreach <server.list_players.filter[has_flag[hidden]]> {
      - adjust
      }