YAML Command Test


Author: PrimerBlock
Created: 2013-05-30T23:19:15-0400
Edited: 2013-05-30T23:19:15-0400
Denizen Version: 0.8.8
Views: 23
Downloads: 925
Likes: 0


WGET
Description: # This script is a working test of the denizen yaml command.
# Basically created to learn the yaml command myself.
# Once assigned to a NPC the NPC will allow a player to
# populate a yaml config file npcyamltest.yml. Once the file
# is populated with data. The script will be able to loop
# through printing both the name and the price keyed off of
# the storeinv number.
# Thanks to dimensionZ for the loop task and aufdemrand for
# the HallMonitor script which I borrowed much from.

Still some bugs in this script but it mostly works. Hoping it will serve as a starting point for others to use the yaml command. The file created npcyamltest.yml will be saved by default in the ./denizens/ directory and not the ./denizens/scripts/ directory. DON'T MOVE IT! It belongs there.

# This script is a working test of the denizen yaml command.
# Basically created to learn the yaml command.
# Once assigned to a NPC the NPC will allow a player to 
# populate a yaml config file npcyamltest.yml. Once the file
# is populated with data. The script will be able to loop
# through printing both the name and the price keyed off of 
# the storeinv number.
# Thanks to dimensionZ for the loop task and aufdemrand for
# the HallMonitor script which I borrowed much from.

yamlnpc:
    type: assignment
    
    default constants:
        # This is the starting point for the NPC YAML NPC
        # set it with the command /npc anchor --save yamlnpcstart
        yamlnpcstart: <anchor:yamlnpcstart>
        invPageLength: 3
    interact scripts:
    
    actions:
        on assignment:
        - if '<cons:yamlnpcstart>' matches location
          runtask "script:YAML NPC Init" instant
          else runtask 'script:YAML NPC Invalid Init' instant
        - if <flag.n:loaded> true
          narrate "YAML NPC '<npc.name>' is ready to go!"
        on spawn:
        - runtask "script:YAML NPC Init" instant
            
    interact scripts:
        - 10 YAML NPC TEST
 
# Main script to display NPC menu, populate the yml file, and start the loop
"YAML NPC TEST":
    type: interact
    steps:
        'yamlNPCfirstStep*':
            click trigger:
                script:
                - narrate "<green>======<&nl> Menu<&nl>======"
                - narrate "<blue>populate <green>- populate YAML config file npcyamltest.yml"
                - narrate "<blue>list <green>- list items"
            chat trigger:
                'populate':
                    trigger: "/Populate/ the YAML config file."
                    script:
                    - runtask "script:Populate YAML File"
                'list items':
                    trigger: "/list/ the /items/ for me."
                    script:
                    - yaml id:testinv load:npcyamltest.yml
                    - flag player itemnum:0
                    - flag player invpagesize:3
                    - chat "Here is the current inventory"
                    - ^runtask script:loopYAMLinv
                    - narrate "Right Click me to see next page" 
                    - ^zap "step:BrowseNextPage"
        # After seeing the first page the script repeats here to paginate through the rest of the pages
        'BrowseNextPage':
            click trigger:
                script:
                - ^flag player invpagesize:+:<cons:invPageLength>
                - ^runtask script:loopYAMLinv
                - narrate "Right Click me to see next page" 
 
# This script loops through the inventory list limited by the page size
"loopYAMLinv":
    type: task
    script:
    - ^flag player itemnum:+:1
    - ^if <yaml[testinv].read[item.storeinv.<flag.p:itemnum.asint>]> == "null" runtask script:InventoryListEnd
      else ^narrate "<blue><yaml[testinv].read[item.storeinv.<flag.p:itemnum.asint>]><green> -
      <yaml[testinv].read[item.price.<yaml[testinv].read[item.storeinv.<flag.p:itemnum.asint>]>]> <player.money.currency.plural> each"
    - ^if <flag.p:itemnum> < <flag.p:invpagesize> runtask script:loopYAMLinv
 
# After paginating through the the inventory list this task returns the player to the start
"InventoryListEnd":
    type: task
    script:
    - chat "<red>That is the end of the list"
    - zap "script:YAML NPC TEST" "step:yamlNPCfirstStep"
 
# Creates a yaml file and stores the data in it.
"Populate YAML File":
    type: task
    script:
    - chat "<green>OK performing population..."
    - yaml id:testinv create:npcyamltest.yml
    - yaml id:testinv write:item.id.stone value:1
    - yaml id:testinv write:item.id.grass value:2
    - yaml id:testinv write:item.id.dirt value:3
    - yaml id:testinv write:item.id.cobblestone value:4
    - yaml id:testinv write:item.id.sand value:12
    - yaml id:testinv write:item.id.gravel value:13
    - yaml id:testinv write:item.id.oak_wood value:17
    - yaml id:testinv write:item.id.spruce_wood value:17:1
    - yaml id:testinv write:item.id.birch_wood value:17:2
    - yaml id:testinv write:item.id.jungle_wood value:17:3
    - yaml id:testinv write:item.price.stone value:15
    - yaml id:testinv write:item.price.grass value:10
    - yaml id:testinv write:item.price.dirt value:1
    - yaml id:testinv write:item.price.cobblestone value:4
    - yaml id:testinv write:item.price.sand value:2
    - yaml id:testinv write:item.price.gravel value:1000
    - yaml id:testinv write:item.price.oak_wood value:200
    - yaml id:testinv write:item.price.spruce_wood value:1
    - yaml id:testinv write:item.price.birch_wood value:64
    - yaml id:testinv write:item.price.jungle_wood value:640
    - yaml id:testinv write:item.storeinv.1 value:stone
    - yaml id:testinv write:item.storeinv.2 value:grass
    - yaml id:testinv write:item.storeinv.3 value:dirt
    - yaml id:testinv write:item.storeinv.4 value:cobblestone
    - yaml id:testinv write:item.storeinv.5 value:sand
    - yaml id:testinv write:item.storeinv.6 value:gravel
    - yaml id:testinv write:item.storeinv.7 value:oak_wood
    - yaml id:testinv write:item.storeinv.8 value:spruce_wood
    - yaml id:testinv write:item.storeinv.9 value:birch_wood
    - yaml id:testinv write:item.storeinv.10 value:jungle_wood
    - yaml id:testinv save:npcyamltest.yml
    - chat "OK done!"
 
# NPC Init tasks derived from aufdemrands HallMonitor.yml script
"YAML NPC Init":
    type: task
    script:
        - trigger name:chat toggle:true radius:5
        - trigger name:click toggle:true radius:5
        - trigger name:proximity toggle:true
        - trigger name:damage toggle:true
        - vulnerable toggle:true
        - execute as_npc "npc select <npc.id>"
        - execute as_npc "npc health --respawndelay 30s"
        - execute as_npc "npc health --set 50"
        - walkto location:<cons:yamlnpcstart>
        - equip HAND item:0
        - flag npc loaded:true
"YAML NPC Invalid Init":
    type: task
    script:
    - narrate "<red>[X] <white>YAML NPC failed to initialize<&cm> did you create the
      anchors? Remember you need to create the NPC anchor before assigning the script. 
      Select the npc and run the following command<&co>
      <green>/npc anchor --save yamlnpcstart"
    - narrate "<red>Assignment removed."
    - assignment remove
    - flag npc loaded:false




Comments
No one has posted a comment! Post one below: