Date: 2017/06/17 13:07:49 UTC-07: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
World Director:
type: world
events:
#Morning - 0 ticks
on time 6 in creative:
- flag global "night:false"
- foreach <server.flag[npcs]> { - run sleep_handler npc:<def[value]> }
#Night - 13000 ticks
on time 19 in creative:
- flag global "night:true"
- foreach <server.flag[npcs]> { - run sleep_handler npc:<def[value]> }
#Each NPC is assigned sleep to activate the sleeping mechanism
"Sleep":
type: assignment
default constants:
SleepCycle: true
actions:
on assignment:
- if !<global.flag[npcs].aslist> contains '<npc.id>' { - flag global "npcs:->:<npc.id>" }
on spawn:
- if !<global.flag[npcs].aslist> contains '<npc.id>' { - flag global "npcs:->:<npc.id>" }
on despawn:
- if <global.flag[npcs].aslist> contains '<npc.id>' { - flag global "npcs:<-:<npc.id>" }
on remove:
- if <global.flag[npcs].aslist> contains '<npc.id>' { - flag global "npcs:<-:<npc.id>" }
on complete navigation:
- if <npc.has_flag[sleeping]> == true { - execute as_npc "npc select <npc.id>" }
- if <npc.has_flag[sleeping]> == true { - execute as_npc "npc sleep --anchor:bed" }
sleep_handler:
type: task
script:
- if <npc.constant[SleepCycle]> == "false" {
- queue clear
}
#If it is night time AND NPC is NOT sleeping, pause their normal path
- if <server.flag[night]> == true {
- if !<npc.flag[sleeping]> {
- pause waypoints
}
}
#If it is night time AND NPC is NOT sleeping, walk to their bed
- if <server.flag[night]> == true {
- if !<npc.flag[sleeping]> {
- walk location:<npc.anchor[bed]>
}
}
#If it is night time AND NPC is NOT sleeping, set npc to sleeping
- if <server.flag[night]> == true {
- if !<npc.flag[sleeping]> {
- flag npc "sleeping:true"
}
}
#If NPC is sleeping and it is NOT night then resume normal path
- if <npc.flag[sleeping]> == true {
- if !<server.flag[night]> {
- run 'unpause_waypoints'
}
}
#If NPC is sleeping and it is NOT night then wakeup
- if <npc.flag[sleeping]> == true {
- if !<server.flag[night]> {
- flag npc "sleeping:true"
- execute as_npc "npc wakeup"
}
}
unpause_waypoints:
type: task
script:
- pause duration:1 waypoints
- wait duration:1