forked from NerdNu/EasySigns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ms
100 lines (98 loc) · 2.77 KB
/
main.ms
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
export('easysign.signs', get_value('easysign.signs'))
bind(player_interact, null, null, @e,
if(array_index_exists(@e, 'location') && is_sign_at(@e['location'])){
@signdata = import('easysign.signs')
@key = json_encode(@e['location'])
if(is_array(@signdata) && array_index_exists(@signdata, @key)){
foreach(@signdata[@key], @cmd,
@data = @cmd['data']
switch(@cmd['type'],
# Add new types here
'sleep',
set_pbed_location(ploc())
msg(color(LIGHT_PURPLE).'Your bed has now been set!')
,'warp',
set_ploc(@data)
,'ci',
foreach(0..104,@i,
@array = associative_array()
@array[@i] = null
set_pinv(@array)
)
,'give',
@item = @data['item']
@qty = @data['qty']
@slot = @data['slot']
if(@slot != null){
@array = associative_array()
@array[@slot] = array(type: @item, qty: @qty)
console(@array)
set_pinv(@array)
} else {
pgive_item(@item, @qty)
}
,'hunger',
set_phunger(20)
set_psaturation(20),
,'announce',
@message = @data['message']
if(reg_count('%s', @data['message'])){
@message = sprintf(@message, player())
}
@value = get_value('easysign.announce')
@id = @data['id']
if(!is_array(@value), @value = associative_array())
if(!array_index_exists(@value, @id)){
@value[@id] = array()
}
if(array_contains(@value[@id], player())){
msg(color(GREEN).'[SIGN] '.color(WHITE).'You can only announce here once!')
} else {
array_push(@value[@id], player())
store_value('easysign.announce', @value)
broadcast(colorize(@message))
}
,'heal',
if(@data == 0){
set_phealth(20)
} else {
for(@i = 0, @i <= 20 - pinfo()[5] - 1, @i++,
@to = 1000 * @data + (@i * 1000)
set_timeout(@to, closure(
if(pinfo()[5] < 20){
set_phealth(pinfo()[5] + 1)
}
))
)
}
,'msg',
msg(colorize(@data))
,'take',
cancel() # Cancel here because of the die
if(phas_item(@data['item']) < @data['qty']){
die(colorize(@data['failmsg']))
}
ptake_item(@data['item'], @data['qty'])
)
)
cancel()
}
}
)
# Every minute, check to see if all the locations are valid signs. If not,
# go ahead and delete it.
set_interval(1 * 60 * 1000, closure(
@signdata = get_value('easysign.signs')
if(!is_array(@signdata)){
@signdata = array()
}
foreach(@signdata, @key, @data,
if(!is_sign_at(json_decode(@key))){
array_remove(@signdata, @key)
store_value('easysign.signs', @signdata)
export('easysign.signs', @signdata)
console(color(RED).'The sign at '.@key.' is no longer a sign, so it has been deleted from easy signs')
die()
}
)
))