-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfactionboardlua.ttslua
287 lines (256 loc) · 9.14 KB
/
factionboardlua.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
-- Licensed under Creative Commons By 4.0 (https://creativecommons.org/licenses/by/4.0/legalcode)
#include scenarios
chosen_faction = nil
KEEPER = nil
XMLKEEPER = nil
function setXml()
log(self.guid..": setting xml")
XMLKEEPER = find_object_by_name("The keeper of XML")
local assets = XMLKEEPER.getTable("UIASSETS")
local xml = XMLKEEPER.getVar("board_xml")
function routine()
self.UI.setCustomAssets(assets)
coroutine.yield()
self.UI.setXml(xml)
coroutine.yield()
showButtons()
return 1
end
startLuaCoroutine(self, "routine")
end
function onLoad(save_state)
-- log(self.guid.." Finding keeper of xml")
XMLKEEPER = find_object_by_name("The keeper of XML")
if not XMLKEEPER then
log(self.guid.." couldn't find keeper. Self destructing")
self.destruct()
end
Wait.condition(setXml, ||Global.getVar("XML_UPDATED"), 5, setXml)
-- log(self.guid.." Finding keeper of faction info")
KEEPER = find_object_by_name("The keeper of information")
if not KEEPER then
log(self.guid.." couldn't find keeper. Self destructing")
self.destruct()
end
Global.call('ImHere', {self})
end
function toggleButtons(player, value, id)
self.UI.setAttribute("subpanel", "active", "False")
self.UI.setAttribute(id..'Buttons', 'active', value)
end
function setColorRemote(color)
setColor(nil, color)
end
function setColor(_, color)
local colors = Global.getTable('colors')
if not colors[color] then
for k,v in pairs(colors) do
self.UI.setAttribute(k, 'active', v)
end
return
end
if chosen_faction == "Vagabond" then
spawnWithColor(nil, color, true)
else
spawnWithColor(chosen_faction, color)
end
end
function spawnRemote(params)
spawnFunction(params.player, params.faction, params.id, params.fan)
end
function spawnFunction(player, faction, id, fan)
local fan = fan or ''
if isSpectator(player) then
broadcastToColor("Sit down first", player.color, "Red")
return
end
local avail = Global.getTable('available')
local colors = Global.getTable('colors')
if (avail[faction] < 1) then return end
Global.call('FactionChosen', {faction})
local preferred_color = ""
if faction == "Vagabond" then
preferred_color = "White"
else
preferred_color = KEEPER.call('get_faction_color', {fan..'factions', faction})
end
if not colors[preferred_color] then
player.print("Preferred color for faction: "..faction.." alread taken.\nPlease pick another", red)
if faction == "Vagabond" then
chosen_faction = "Vagabond"
else
chosen_faction = KEEPER.call('get_faction_data', {fan..'factions', faction})
end
self.UI.setAttribute("factionsButtons", "active", "False")
self.UI.setAttribute("botsButtons", "active", "False")
self.UI.setAttribute("scenariosButtons", "active", "False")
self.UI.setAttribute("rBotButtons", "active", "False")
self.UI.setAttribute("fanButtons", "active", "False")
self.UI.setAttribute("colorButtons", "active", "True")
for k,v in pairs(colors) do
self.UI.setAttribute(k, 'active', v)
end
return
else
if faction == "Vagabond" then
spawnWithColor(nil, preferred_color, true)
else
spawnWithColor(KEEPER.call('get_faction_data', {fan..'factions', faction}), preferred_color)
end
end
end
function spawnFanFaction(player, faction, id)
spawnFunction(player, faction, id, 'fan')
end
function isSpectator(player)
if player.color == "Grey" then
return true
else
return false
end
end
function spawnWithColor(faction, color, vagabond)
local colors = Global.getTable('colors')
colors[color] = false
Global.setTable('colors', colors)
log(colors)
local closest = findClosestPosition()
closest.scale = {17.20, 5.40, 3.00}
local val = false
while not val do
val = Player[color].setHandTransform(closest, 1)
end
if vagabond then
self.UI.setAttribute("factionsButtons", "active", "False")
self.UI.setAttribute("vagabondButtons", "active", "True")
self.UI.setAttribute('typeToggles', "active", "False")
self.UI.setAttribute("colorButtons", "active", "False")
else
spawnHere(faction)
end
end
function spawnBot(player, faction, fan)
if isSpectator(player) then
broadcastToColor("Sit down first", player.color, "Red")
return
end
local avail = Global.getTable('available')
if (avail[faction:sub(5,-1)] < 1) then return end
local colors = Global.getTable('colors')
local bot = Global.getVar('bot')
if not bot then
bot_pieces = bot_stuff
for _, v in ipairs(bot_pieces) do
spawnObjectJSON({json=v})
end
Global.setVar('bot', true)
end
Global.call('FactionChosen', {faction:sub(5,-1)})
local preferred_color = ""
if fan then
preferred_color = KEEPER.call('get_faction_color', {'fanbots', faction})
else
preferred_color = KEEPER.call('get_faction_color', {'officialbots', faction})
end
if not colors[preferred_color] then
player.print("Preferred color for faction: "..faction.." alread taken.\nPlease pick another", red)
if fan then
chosen_faction = KEEPER.call('get_faction_data', {'fanbots', faction})
else
chosen_faction = KEEPER.call('get_faction_data', {'officialbots', faction})
end
self.UI.setAttribute("factionsButtons", "active", "False")
self.UI.setAttribute("botsButtons", "active", "False")
self.UI.setAttribute("scenariosButtons", "active", "False")
self.UI.setAttribute("rBotButtons", "active", "False")
self.UI.setAttribute("fanButtons", "active", "False")
self.UI.setAttribute("colorButtons", "active", "True")
for k,v in pairs(colors) do
self.UI.setAttribute(k, 'active', v)
end
return
else
if fan then
spawnWithColor(KEEPER.call('get_faction_data', {'fanbots', faction}), preferred_color)
else
spawnWithColor(KEEPER.call('get_faction_data', {'officialbots', faction}), preferred_color)
end
end
end
function spawnFanBot(player, faction)
spawnBot(player, faction, true)
end
function spawnOfficialBot(player, faction)
spawnBot(player, faction, false)
end
function spawnVagabond(player, vaga)
if isSpectator(player) then
broadcastToColor("Sit down first", player.color, "Red")
return
end
avail = Global.getTable('available')
if (avail[vaga] < 1) then return end
Global.call('FactionChosen', {vaga})
spawnHere(KEEPER.call('get_faction_data', {'factions', vaga}))
end
function spawnScenario(player, scenario)
if isSpectator(player) then
broadcastToColor("Sit down first", player.color, "Red")
return
end
spawnHere(KEEPER.call('get_faction_data', {'scenarios', scenario}))
end
function showButtons()
local avail = Global.getTable('available')
local buttons = Global.getTable('BUTTONS')
for _, k in ipairs(buttons) do
if (k:sub(1,-2)..tostring(avail[k:sub(1,-2)] or 0) == k) or (k:sub(5,-2)..tostring(avail[k:sub(5,-2)] or 0) == k:sub(5,-1)) or (avail[k] and avail[k] > 0) then
self.UI.setAttribute(k, 'active', true)
else
self.UI.setAttribute(k, 'active', false)
end
end
end
function deleteThis()
Global.call('ImGone', {self})
self.destruct()
end
function spawnHere(to_spawn)
local my_rot = self.getRotation()
local scale = self.getScale()
scale.x = 1/scale.x
scale.z = 1/scale.z
scale.y = 1/scale.y
for _,v in ipairs(to_spawn) do
local new_pos = self.positionToWorld(Vector(v.move_to) * scale)
spawnObjectJSON({
json = v.json,
position = new_pos,
callback_function = function(o) o.setRotation({o.getRotation().x, o.getRotation().y+my_rot.y, o.getRotation().z}) end
})
end
Global.call('ImGone', {self})
self.destruct()
end
function findClosestPosition()
local own_pos = self.getPosition()
local closest = nil
local smallest_distance = 100000000
local places = {{position={-50.00, 15.00, -64.50}, rotation={0, 0, 0}}, {position={0.00, 15.00, -64.50}, rotation={0, 0, 0}}, {position={50.00, 15.00, -64.50}, rotation={0, 0, 0}}, {position={50.00, 15.00, 64.50}, rotation={0.00, 180.00, 0.00}}, {position={0.00, 15.00, 64.50}, rotation={0.00, 180.00, 0.00}}, {position={-50.00, 15.00, 64.50}, rotation={0.00, 180.00, 0.00}}}
for _, place in ipairs(places) do
pos = place.position
local distance = math.sqrt(math.pow(own_pos.x-pos[1], 2)+math.pow(own_pos.z-pos[3], 2))
if distance < smallest_distance then
smallest_distance = distance
closest = place
end
end
return closest
end
function none() end
function find_object_by_name(name)
for _, obj in ipairs(getAllObjects()) do
if obj.getName() == name then return obj end
end
return nil
end