-
Notifications
You must be signed in to change notification settings - Fork 2
/
sleep.sk
54 lines (39 loc) · 1.37 KB
/
sleep.sk
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
# ### Sleep voting by Roy Curtis
# ### Licensed under MIT, 2015
# ### Global variables
# sleep.%world% - number; amount of players for tracking
# ### Configuration
options:
sleep percent : 25
wake message : Wakey wakey, eggs and bakey!
# ### Global functions
function sleepCalculate(world: world):
set {_players} to number of players in {_world}
set {_sleepers} to 0
loop all players in {_world}:
loop-player is sleeping
add 1 to {_sleepers}
# Don't bother if nobody is sleeping
if {_sleepers} is 0:
exit trigger
set {_perc} to ({_sleepers} / {_players}) * 100
broadcast "*** &a%rounded {_perc}%%%&f of players in &a%{_world}%&f are sleeping ({@sleep percent}%% required)" to {_world}
if {_perc} is greater than or equal to {@sleep percent}:
set {sleep.handling} to true
wait 20 ticks
delete {sleep.handling}
set time in {_world} to 6:00
set weather in {_world} to clear
broadcast "&6*** {@wake message} It is now morning in %{_world}%" to {_world}
# ### Events
on bed enter:
if {sleep.handling} is set:
exit trigger
wait 1 tick
sleepCalculate(world)
on bed leave:
if {sleep.handling} is set:
exit trigger
time in world is not between 6:00 and 18:00
wait 1 tick
sleepCalculate(world)