-
Notifications
You must be signed in to change notification settings - Fork 1
/
UpdateBoxPlayers.ttslua
112 lines (101 loc) · 2.58 KB
/
UpdateBoxPlayers.ttslua
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
--[[
Update Box
Made by Lost Savage
--]]
------------------Constants
BOX_NAME = 'SH Expansion Box + Players'
PACKING_LIST_PLAYERS = {
'Players',
'Player Effects',
'Darthvader Effect Deck',
'Player Reference',
'Rounds Until Armageddon',
'Rounds Until Swap',
'Gold',
}
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',
'Free Stamp',
'Secret Hitler Probability Calc',
'Ability Drafter',
'Timer',
'Rulings',
}
function onLoad()
local buttonParam = {
click_function = 'updateBox',
label = 'Update Box\nWith Player Abilities',
function_owner = self,
position = {0, 0.2, 0},
rotation = {0, 0, 0},
width = 3400,
height = 1500,
font_size = 300
}
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_PLAYERS, tmpObj.getName()) then
local newObj = tmpObj.clone({position = boxObj.getPosition()})
newObj.setLock(false)
sleep(0.5)
end
end
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