-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro-maker.lua
132 lines (122 loc) · 3.41 KB
/
macro-maker.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
function onLoad()
self.createButton(
{
click_function = "work_macro",
function_owner = self,
label = "Activate Macro",
position = {0, 0.5, 0.8},
scale = {0.5, 0.5, 0.5},
width = 3300,
height = 600,
font_size = 400,
color = {0.2026, 0.4071, 0.9773, 1}
}
)
end
function none()
end
function onCollisionEnter(info)
if info.collision_object.interactable then
local id = info.collision_object.getGUID()
local gm = self.getGMNotes()
local macro = JSON.decode(gm)
macro.obj = id
self.setGMNotes(JSON.encode(macro))
end
end
function onHover(player_color)
if player_color == "Black" then
local gm = self.getGMNotes()
if gm == "" or gm == nil then
self.setGMNotes(
[[{
"obj":"aaaaaa",
"position":[999,999,999],
"rotation":[999,999,999],
"interact": true,
"lock": true,
"visible": true
}]]
)
self.highlightOn(Color.Green, 1)
end
end
end
function work_macro()
-- position
-- make interactable
-- make visible
--[[
{
"obj":"aaaaaa",
"position":[1,1,1],
"rotation":[1,1,1],
"interact": true,
"lock": true,
"visible": true
}
]]
-- with position = 999 then the token will take relative position
local gm = self.getGMNotes()
if gm then
local macro = JSON.decode(gm)
local obj = getObjectFromGUID(macro.obj)
local pos,
rot,
interact
if exists(macro.position) ~= nil then
pos = {
x = correctPositionCoordinate("x", macro.position[1], obj),
y = correctPositionCoordinate("y", macro.position[2], obj),
z = correctPositionCoordinate("z", macro.position[3], obj)
}
obj.setPosition(pos)
end
if exists(macro.rotation) then
rot = {
x = correctRotationCoordinate("x", macro.rotation[1], obj),
y = correctRotationCoordinate("y", macro.rotation[2], obj),
z = correctRotationCoordinate("z", macro.rotation[3], obj)
}
obj.setRotation(rot)
end
if exists(macro.interact) then
interact = macro.interact
if exists(macro.lock) then
toggle_interact(obj, interact, macro.lock)
else
toggle_interact(obj, interact, true)
end
end
if exists(macro.visible) then
if macro.visible then
obj.setColorTint({r = 1, g = 1, b = 1, a = 1})
else
obj.setColorTint({r = 1, g = 1, b = 1, a = 0})
end
end
end
end
function correctPositionCoordinate(xyz, coord, obj)
if coord == 999 then
return obj.getPosition()[xyz]
else
return coord
end
end
function correctRotationCoordinate(xyz, coord, obj)
if coord == 999 then
return obj.getRotation()[xyz]
else
return coord
end
end
function exists(variable)
return variable ~= nil
end
function toggle_interact(o, interact, lock)
o.interactable = interact
o.setLock(lock)
local code = "function onload() self.interactable = " .. tostring(interact) .. " end"
o.setLuaScript(code)
end