-
Notifications
You must be signed in to change notification settings - Fork 0
/
item-gift.lua
152 lines (147 loc) · 3.97 KB
/
item-gift.lua
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- 7
local version = 7
local Table = nil
local socket = nil
local config = {
selectedIndex = 1,
selectedAmount = 1,
playername = ''
}
local configPath = 'var/item-gift.conf'
local itemList = {{
name = 'Iron ore',
stackSize = 64,
code = 'minecraft:iron_ore',
dmg = 0
}, {
name = 'Copper ore',
stackSize = 64,
code = 'thermalfoundation:ore',
dmg = 0
}, {
name = 'Silver ore',
stackSize = 64,
code = 'thermalfoundation:ore',
dmg = 2
}, {
name = 'Lead ore',
stackSize = 64,
code = 'thermalfoundation:ore',
dmg = 3
}, {
name = 'Cinnabar ore',
stackSize = 64,
code = 'thaumcraft:ore_cinnabar',
dmg = 0
}, {
name = 'Uranium ore',
stackSize = 64,
code = 'ic2:resource',
dmg = 4
}, {
name = 'Block of Enderpearl',
stackSize = 64,
code = 'actuallyadditions:block_misc',
dmg = 6
}}
local function init()
if not fs.exists('lib/table.lua') then
shell.run('installer lib/table.lua')
end
Table = require('lib/table')
if not fs.exists('websocket.lua') then
shell.run('installer websocket.lua')
end
socket = require('websocket')
if not fs.exists(configPath) then
local file = fs.open(configPath, 'w')
file.write(textutils.serialise(config))
file.close()
end
local file = fs.open(configPath, 'r')
config = textutils.unserialise(file.readAll())
file.close()
end
local function setConfig(key, value)
config[key] = value
local file = fs.open(configPath, 'w')
file.write(textutils.serialise(config))
file.close()
end
local function sendMethods()
if socket then
socket.info({{
key = "Version",
value = version,
type = 'number'
}})
socket.methods({{
type = 'text',
key = 'playername',
name = 'Player',
value = config.playername,
fn = function(value)
setConfig('playername', value)
return value
end
}, {
type = 'dropdown',
key = 'itemcode',
name = 'Item',
options = Table.map(itemList, function(item)
return item.name
end),
value = itemList[config.selectedIndex].name,
fn = function(value)
local _, index = Table.find(itemList, function(item)
return item.name == value
end)
setConfig('selectedIndex', index)
return value
end
}, {
type = 'number',
key = 'selectedAmount',
name = 'Amount',
value = config.selectedAmount,
min = 1,
fn = function(value)
if value == nil or value < 1 then
value = 1
end
setConfig('selectedAmount', value)
return value
end
}, {
type = 'void',
key = 'exec',
name = 'Give items',
fn = function()
local item = itemList[config.selectedIndex]
local count = config.selectedAmount
while count >= 1 do
print('Giving ' .. config.playername .. ' ' .. count .. ' ' .. item.name)
if count > 64 then
commands.give(config.playername, item.code, 64, item.dmg)
count = count - 64
else
commands.give(config.playername, item.code, count, item.dmg)
count = 0
end
end
end
}, {
type = 'void',
key = 'update',
name = 'Update program',
fn = function()
shell.run('installer.lua item-gift.lua')
os.reboot()
end
}})
end
end
init()
sendMethods()
socket.connect('Give items', true)
socket.runtime()