Date: 2016/01/20 07:40:22 UTC-08:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# 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
actions:
on assignment:
- flag <npc> yamlnpcstart:<npc.anchor[yamlnpcstart]>
- flag <npc> invPageLength:3
- run YAML NPC Init
interact scripts:
- 1 YAML_NPC_TEST
# Main script to display NPC menu, populate the yml file, and start the loop
YAML_NPC_TEST:
type: interact
steps:
1:
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:
1:
trigger: "/Populate/ the YAML config file."
script:
- run Populate_YAML_File
2:
trigger: "/list/ the /items/ for me."
script:
- yaml id:testinv load:npcyamltest.yml
- flag player itemnum:0
- flag player invpagesize:3
- narrate "Here is the current inventory"
- ^run script:loopYAMLinv
- narrate "Right Click me to see next page"
- ^zap 2
# After seeing the first page the script repeats here to paginate through the rest of the pages
2:
click trigger:
script:
- ^flag player invpagesize:+:<npc.flag[invPageLength]>
- ^run 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.<player.flag[itemnum]>]> == null {
- run InventoryListEnd
}
else {
- narrate "<blue><yaml[testinv].read[item.storeinv.<player.flag[itemnum]>]><green> -<yaml[testinv].read[item.price.<yaml[testinv].read[item.storeinv.<flag.p:itemnum.asint>]>]> <player.money> each"
}
- if <player.flag[itemnum]> < <player.flag[invpagesize]> {
- run loopYAMLinv
}
# After paginating through the the inventory list this task returns the player to the start
InventoryListEnd:
type: task
script:
- narrate "<&4>That is the end of the list"
- zap s@YAML_NPC_TEST 1
# Creates a yaml file and stores the data in it.
Populate_YAML_File:
type: task
script:
- narrate "<&2>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
- narrate "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"
- walk <npc> <npc.anchor[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"
- narrate "<red>Assignment removed."
- assignment remove
- flag <npc> loaded:false