Skip to content

Commit b31d5c2

Browse files
authored
Changed to Core Virtual Inventory Function.
1 parent 5cbbed4 commit b31d5c2

File tree

2 files changed

+151
-86
lines changed

2 files changed

+151
-86
lines changed

auto_include.ms

Lines changed: 114 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,114 @@
1-
#########################################
2-
# Copyright 2016 ITSTAKE GPL v2.0
3-
# Script by itstake (bexco2010@gmail.com)
4-
# Version 1.3 (2018/02/04)
5-
#########################################
6-
7-
proc(_itemmenu_create, @array,
8-
if(import('MenuOpen'.player()) != true) {
9-
export('MenuOpen'.player(), true)
10-
export('CurMenu'.player(), @array)
11-
12-
@title = @array['title']
13-
@id = @array['id']
14-
if(array_index_exists(@array, size)) {
15-
@size = @array['size']
16-
} else {
17-
@size = ceil((array_size(@array['menu'])) / 9) * 9 # Dynamically set the size
18-
}
19-
20-
@chest = array(id: @id, size: @size, title: @title)
21-
@items = @array['menu']
22-
23-
foreach(@key:@value in @items) {
24-
25-
array_set(@chest, @key, @value['item'])
26-
}
27-
28-
create_virtualchest(@chest)
29-
popen_virtualchest(@id)
30-
}
31-
)
32-
proc(_itemmenu_update, @array,
33-
export('MenuOpen'.player(), true)
34-
export('CurMenu'.player(), @array)
35-
36-
@title = @array['title']
37-
@id = @array['id']
38-
if(array_index_exists(@array, size)) {
39-
@size = @array['size']
40-
} else {
41-
@size = ceil((array_size(@array['menu'])) / 9) * 9 # Dynamically set the size
42-
}
43-
44-
@chest = array(id: @id, size: @size, title: @title)
45-
@items = @array['menu']
46-
for(@i = 0, @i < @size, @i++,
47-
if(!array_index_exists(@items, @i)) {
48-
array_set(@chest, @i, array(type: 0,data: 0,qty: 0))
49-
}
50-
)
51-
foreach(@key:@value in @items) {
52-
array_set(@chest, @key, @value['item'])
53-
}
54-
update_virtualchest(@chest)
55-
)
56-
57-
58-
1+
#########################################
2+
# Copyright 2016 ITSTAKE GPL v2.0
3+
# Script by itstake (bexco2010@gmail.com)
4+
# Version 1.3 (2018/02/04)
5+
#########################################
6+
7+
#############
8+
# USES VIRTUALCHEST EXTENSION
9+
10+
/*
11+
proc(_itemmenu_create_vc, @array,
12+
if(import('MenuOpen'.player()) != true) {
13+
export('MenuOpen'.player(), true)
14+
export('CurMenu'.player(), @array)
15+
16+
@title = @array['title']
17+
@id = @array['id']
18+
if(array_index_exists(@array, size)) {
19+
@size = @array['size']
20+
} else {
21+
@size = ceil((array_size(@array['menu'])) / 9) * 9 # Dynamically set the size
22+
}
23+
24+
@chest = array(id: @id, size: @size, title: @title)
25+
@items = @array['menu']
26+
27+
foreach(@key:@value in @items) {
28+
29+
array_set(@chest, @key, @value['item'])
30+
}
31+
32+
create_virtualchest(@chest)
33+
popen_virtualchest(@id)
34+
}
35+
)
36+
proc(_itemmenu_update_vc, @array,
37+
export('MenuOpen'.player(), true)
38+
export('CurMenu'.player(), @array)
39+
40+
@title = @array['title']
41+
@id = @array['id']
42+
if(array_index_exists(@array, size)) {
43+
@size = @array['size']
44+
} else {
45+
@size = ceil((array_size(@array['menu'])) / 9) * 9 # Dynamically set the size
46+
}
47+
48+
@chest = array(id: @id, size: @size, title: @title)
49+
@items = @array['menu']
50+
for(@i = 0, @i < @size, @i++,
51+
if(!array_index_exists(@items, @i)) {
52+
array_set(@chest, @i, array(type: 0,data: 0,qty: 0))
53+
}
54+
)
55+
foreach(@key:@value in @items) {
56+
array_set(@chest, @key, @value['item'])
57+
}
58+
update_virtualchest(@chest)
59+
)
60+
*/
61+
62+
63+
############
64+
# USES CORE FUNCTIONS
65+
66+
proc(_itemmenu_create, @array,
67+
export('CurMenu'.player(), @array)
68+
@title = @array['title']
69+
@id = @array['id']
70+
@type = 'CHEST'
71+
if(array_index_exists(@array, 'size')) {
72+
@size = @array['size']
73+
} else if(array_index_exists(@array, 'type')) { # If GUI Array have a type
74+
@type = @array['type']
75+
} else {
76+
@size = ceil((array_size(@array['menu'])) / 9) * 9 # Dynamically set the size
77+
}
78+
@menu = @array['menu']
79+
@items = array()
80+
foreach(@key:@value in @menu) {
81+
82+
array_set(@items, @key, @value['item'])
83+
}
84+
if(@type == 'CHEST') {
85+
create_virtual_inventory(@id, @size, colorize(@title), @items)
86+
} else {
87+
create_virtual_inventory(@id, @type, colorize(@title), @items)
88+
}
89+
popen_inventory(player(), @id)
90+
)
91+
proc(_itemmenu_update, @array,
92+
export('CurMenu'.player(), @array)
93+
@title = @array['title']
94+
@id = @array['id']
95+
if(array_index_exists(@array, size)) {
96+
@size = @array['size']
97+
} else {
98+
@size = ceil((array_size(@array['menu'])) / 9) * 9 # Dynamically set the size
99+
}
100+
@menu = @array['menu']
101+
for(@i = 0, @i < @size, @i++,
102+
if(!array_index_exists(@menu, @i)) {
103+
array_set(@chest, @i, array(type: 0,data: 0,qty: 0))
104+
}
105+
)
106+
@items = array()
107+
foreach(@key:@value in @menu) {
108+
array_set(@items, @key, @value['item'])
109+
}
110+
set_inventory(@id, @items)
111+
)
112+
113+
114+

main.ms

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
#########################################
2-
# Copyright 2016 ITSTAKE GPL v2.0
3-
# Script by itstake (bexco2010@gmail.com)
4-
# Version 1.3 (2018/02/04)
5-
#########################################
6-
7-
bind('virtualchest_closed', null, null, @event,
8-
@array = import('CurMenu'.player())
9-
export('MenuOpen'.player(), false) # Itemmenu is closed
10-
)
11-
12-
bind(inventory_click, null, null, @e,
13-
@array = import('CurMenu'.player()) # Import Menu Array
14-
if(@array == null) {
15-
die()
16-
}
17-
if(import('MenuOpen'.player())) { # Itemmenu is Open
18-
cancel() # Cancel Click
19-
@number = @e['rawslot']
20-
if(!(array_index_exists(@array['menu'], @number) && @number >= 0), die())
21-
if(array_index_exists(@array['menu'][@number], to_lower(@e[clicktype]))) {
22-
execute(@array['menu'][@number][to_lower(@e[clicktype])])
23-
} else {
24-
execute(@array['menu'][@number]['click'])
25-
}
26-
play_sound(ploc(@e[player]), array(sound: CLICK), @e[player])
27-
}
28-
)
1+
#########################################
2+
# Copyright 2016 ITSTAKE GPL v2.0
3+
# Script by itstake (bexco2010@gmail.com)
4+
# Version 1.3 (2018/02/04)
5+
#########################################
6+
7+
/*
8+
bind('virtualchest_closed', null, null, @event,
9+
@array = import('CurMenu'.player())
10+
export('MenuOpen'.player(), false) # Itemmenu is closed
11+
)
12+
*/
13+
14+
bind(inventory_close, null, null, @e,
15+
if(@e['virtual'] && is_array(import('CurMenu'.@e['player']))) {
16+
delete_virtual_inventory(@e['holder'])
17+
export('CurMenu'.@e['player'], null)
18+
}
19+
)
20+
21+
22+
bind(inventory_click, null, null, @e,
23+
@array = import('CurMenu'.player()) # Import Menu Array
24+
if(@array == null || !@e['virtual']) {
25+
die()
26+
}
27+
cancel() # Cancel Click
28+
@number = @e['rawslot']
29+
if(!(array_index_exists(@array['menu'], @number) && @number >= 0), die())
30+
if(array_index_exists(@array['menu'][@number], to_lower(@e[clicktype]))) {
31+
execute(@array['menu'][@number][to_lower(@e[clicktype])])
32+
} else {
33+
execute(@array['menu'][@number]['click'])
34+
}
35+
play_sound(ploc(@e[player]), array(sound: CLICK), @e[player])
36+
37+
)

0 commit comments

Comments
 (0)