-
Notifications
You must be signed in to change notification settings - Fork 0
/
map-positioner.lua
254 lines (219 loc) · 6.98 KB
/
map-positioner.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
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
local _map_bag = "6ca58b"
--local _map_bag = "efc1f7"
local _center_pos = {x = 54.26, y = 5.70, z = -3.65}
--local _center_pos = {x = 88.40, y = -1.74, z = 22.10}
-- local _bag_pos = {x = 5.33, y = 4.72, z = -6.28}
local _bag_pos = {x = 84.13, y = 6.00, z = -3.65}
--local _bag_pos = {x = 38.25, y = 1.00, z = 38.25}
-- local _piece_pos = {x = 5.33, y = 5.72, z = -3.44}
local _piece_pos = {x = 84.13, y = 6.00, z = 18.17}
--local _piece_pos = {x = 55.25, y = -1.74, z = 38.25}
--Runs when the scripted button inside the button is clicked
function buttonPress()
if lockout == false then
--Call on any other function here. For example:
--Global.call("Function Name", {table of parameters if needed})
--You could also add your own scrting here. For example:
--print("The button was pressed. Hoozah.")
positionMap()
self.AssetBundle.playTriggerEffect(0) --triggers animation/sound
lockout = true --locks out the button
startLockoutTimer() --Starts up a timer to remove lockout
end
end
--Runs on load, creates button and makes sure the lockout is off
function onload()
self.createButton(
{
label = "Big Red Button\n\nBy: MrStump",
click_function = "buttonPress",
function_owner = self,
position = {0, 0.25, 0},
height = 1400,
width = 1400
}
)
lockout = false
end
--Starts a timer that, when it ends, will unlock the button
function startLockoutTimer()
Timer.create({identifier = self.getGUID(), function_name = "unlockLockout", delay = 0.5})
end
--Unlocks button
function unlockLockout()
lockout = false
end
--Ends the timer if the object is destroyed before the timer ends, to prevent an error
function onDestroy()
Timer.destroy(self.getGUID())
end
function positionMap()
local new_pos = _center_pos
new_pos.y = 0
takeParams = {
position = new_pos,
rotation = {0, 0, 0}, --to read from desc
callback_function = function(obj)
take_item(obj)
end
}
getObjectFromGUID(_map_bag).takeObject(takeParams)
end
function take_item(obj)
-- processing wether this item is a bag or not
local t = obj.tag
if t == "Board" then -- this means this is a map
take_map(obj)
elseif t == "Bag" then
obj.setPositionSmooth(_bag_pos)
obj.setRotationSmooth({0.00, 90.00, 0.00})
local waiter = function()
return obj.resting
end
local waited = function()
process_bag(obj)
end
Wait.condition(waited, waiter)
--process_bag(obj)
end
end
function process_bag(obj)
if obj.tag ~= "Bag" then
return
end
local contained = obj.getObjects()
local taken_objects = {}
local piece_pos = _piece_pos
piece_pos.y = math.random(_piece_pos.y, _piece_pos.y + 5)
for i = 1, #contained do
takeParams = {
position = piece_pos,
callback_function = function(obj)
take_piece(obj)
end
}
local taken = obj.takeObject(takeParams)
table.insert(taken_objects, taken)
end
local waiter = function()
return all_resting(taken_objects)
end
local waited = function()
process_pieces(taken_objects)
end
Wait.condition(waited, waiter)
if obj.getGMNotes() ~= "" then
-- this is about the notes if i have to create a fog of war
local notes = obj.getGMNotes()
local vars = JSON.decode(notes)
if vars["zone"] then
local pos = {x = vars["zone"]["pos"][1], y = vars["zone"]["pos"][2], z = vars["zone"]["pos"][3]}
local rot = {x = vars["zone"]["rot"][1], y = vars["zone"]["rot"][2], z = vars["zone"]["rot"][3]}
local scale = {x = vars["zone"]["scale"][1], y = vars["zone"]["scale"][2], z = vars["zone"]["scale"][3]}
local spawnParams = {
type = "FogOfWar",
position = pos,
rotation = rot,
scale = scale,
sound = false
}
spawnObject(spawnParams)
end
end
end
function all_resting(objs)
for i = 1, #objs do
if not objs[i].resting then
return false
end
end
return true
end
function process_pieces(pieces)
for i = 1, #pieces do
Wait.time(
function()
local tar_params = process_params(pieces[i])
if pieces[i].tag ~= board then
place_object(pieces[i], tar_params, 0)
else
place_object(pieces[i], tar_params)
end
pieces[i].tooltip = false
end,
1 + (i + 3) / 10
)
end
end
-- position
-- rotation
-- scale
function process_params(object)
local desc = object.getDescription()
local s = mysplit(desc, "\n")
local tar_rotation = nil
local tar_position = nil
local tar_scale = nil
if #s == 2 then -- rotation, scale
local s_tar_rotation = mysplit(s[1], ",")
tar_rotation = {x = s_tar_rotation[1], y = s_tar_rotation[2], z = s_tar_rotation[3]}
local s_tar_scale = mysplit(s[2], ",")
tar_scale = {x = s_tar_scale[1], y = s_tar_scale[2], z = s_tar_scale[3]}
elseif #s == 3 then -- position, rotation, scale
local s_tar_position = mysplit(s[1], ",")
tar_position = {x = s_tar_position[1], y = s_tar_position[2], z = s_tar_position[3]}
local s_tar_rotation = mysplit(s[2], ",")
tar_rotation = {x = s_tar_rotation[1], y = s_tar_rotation[2], z = s_tar_rotation[3]}
local s_tar_scale = mysplit(s[3], ",")
tar_scale = {x = s_tar_scale[1], y = s_tar_scale[2], z = s_tar_scale[3]}
end
return {tar_position, tar_rotation, tar_scale}
end
function place_object(obj, tar_params, offset)
if not offset then
offset = 0
end
if tar_params[1] then
tar_params[1].y = tar_params[1].y + offset
obj.setPositionSmooth(tar_params[1], false, false)
else
obj.setPositionSmooth({_center_pos.x, _center_pos.y + offset, _center_pos.z}, false, false)
end
if tar_params[2] then
obj.setRotationSmooth(tar_params[2], false, true)
else
obj.setRotationSmooth({0, 0, 0}, false, true)
end
if tar_params[3] then
obj.setScale(tar_params[3])
end
obj.setLock(true)
if obj.hasTag("light_component") then
Wait.time(function()
obj.call("setLightState")
obj.call("initializeGui")
end
, 5)
end
end
function take_piece(obj)
obj.setLock(true)
end
function take_map(obj)
local tar_params = process_params(obj)
place_object(obj, tar_params)
obj.setLock(true)
obj.tooltip = false
end
function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
i = 1
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
t[i] = str
i = i + 1
end
return t
end