-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUpdateBox.ttslua
More file actions
91 lines (81 loc) · 2.02 KB
/
UpdateBox.ttslua
File metadata and controls
91 lines (81 loc) · 2.02 KB
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
--[[
Update Box
Made by Lost Savage
--]]
------------------Constants
BOX_NAME = 'SH Expansion Box'
PACKING_LIST = {
'Abilities',
'Effects',
'SH Expansion Tool',
'SH Expansion Rulebook',
'Ability Reference',
'Effect Reference',
'Rounds Until Poisoning',
'Rounds Until Death',
'Rounds until Aegis expires',
'Line Drawer',
'Secret Hitler Probability Calc'
}
function onLoad()
local buttonParam = {
click_function = 'updateBox',
label = 'Update Box',
function_owner = self,
position = {0, 0.2, 0},
rotation = {0, 0, 0},
width = 3400,
height = 1500,
font_size = 600
}
self.createButton(buttonParam)
self.setDescription('v ' .. VERSION)
end
function updateBox()
function updateBoxCoroutine()
local allObjs = getAllObjects()
local boxObj
--Find and empty box
for _, tmpObj in ipairs(allObjs) do
if tmpObj.getName() == BOX_NAME then
boxObj = tmpObj
local inBox = boxObj.getObjects()
for _, j in ipairs(inBox) do
local deleteObj = boxObj.takeObject({})
deleteObj.destruct()
end
break
end
end
--Clone objects and put them in the box
allObjs = getAllObjects()
if boxObj then
for _, tmpObj in ipairs(allObjs) do
if inTable(PACKING_LIST, tmpObj.getName()) then
local newObj = tmpObj.clone({position = boxObj.getPosition()})
newObj.setLock(false)
sleep(0.5)
end
end
else
broadcastToAll("ERROR: " .. BOX_NAME .. " not found.", {1, 0, 0})
end
return true
end
startLuaCoroutine(self, "updateBoxCoroutine")
end
function inTable(tableIn, valueIn)
local value
if tableIn then
for _, value in pairs(tableIn) do
if value == valueIn then
return true
end
end
end
return false
end
function sleep(numSeconds)
local t0 = os.clock()
while os.clock() - t0 <= numSeconds do coroutine.yield(0) end
end