Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
225 lines (206 loc) · 7.22 KB
/
Copy pathmain.lua
File metadata and controls
225 lines (206 loc) · 7.22 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
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
-- VFX Socket Layers Cookbook (Lua API 7+, Changes tier)
-- Demonstrates R1 multi-layer native `.effect` socket attachments:
-- - Enumerates `game.vfx.sockets(actor)`
-- - Attaches 3 simultaneous `.effect` layers with `offset`, Euler `rot`, quaternion `quat`, and non-uniform `scale`
-- - Continuously updates transforms via `:set_transform(...)` and verifies `game.vfx.active() >= 3`
-- 100% native .effect visuals (no 2D overlay drawing).
local state = {
world_ready = false,
is_mock = false,
started = false,
done = false,
frames = 0,
layers = {},
status = "Waiting for world_ready...",
}
local panel, status_lbl
local function detect_mock_world()
if game.actors then
local ok, _, err = pcall(game.actors, 1)
local msg = (not ok and _) or err
if type(msg) == "string" and msg:lower():find("mock world", 1, true) then
return true
end
end
return false
end
local function pick_effect(query, fallback)
if game.vfx and game.vfx.catalog then
local ok, res = pcall(game.vfx.catalog, query, 20)
if ok and type(res) == "table" then
for i = 1, #res do
local p = res[i].path
if type(p) == "string" and not p:lower():find("pure_gpu", 1, true) then
return p
end
end
end
end
return fallback
end
local function pick_distinct_sockets(socks)
local chosen, used = {}, {}
local prefs_list = {
{ "hand_r", "weapon_r", "r_hand" },
{ "hand_l", "weapon_l", "l_hand" },
{ "spine", "head", "chest" },
}
for _, prefs in ipairs(prefs_list) do
local pick = nil
for _, p in ipairs(prefs) do
for i = 1, #socks do
if not used[socks[i]] and socks[i]:lower():find(p, 1, true) then
pick = socks[i]
break
end
end
if pick then break end
end
if not pick then
for i = 1, #socks do
if not used[socks[i]] then pick = socks[i]; break end
end
end
pick = pick or socks[1] or "Bip01_R_Hand"
used[pick] = true
chosen[#chosen + 1] = pick
end
return chosen
end
local function resolve_player_actor()
if game.player then
local ok, pa = pcall(game.player)
if ok and type(pa) == "number" and pa > 0 then return pa end
end
if game.actors then
local ok, list, err = pcall(game.actors, 64)
if ok and type(list) == "table" then
for i = 1, #list do
if list[i].controlled and list[i].actor then return list[i].actor end
end
elseif type(err) == "string" and err:lower():find("mock world", 1, true) then
return 0x1001
end
end
return 0
end
local function stop_layers()
for i = 1, #state.layers do
if state.layers[i].stop then pcall(function() state.layers[i]:stop(0.05) end) end
end
state.layers = {}
end
local function spawn_layers()
state.is_mock = detect_mock_world()
local p_actor = resolve_player_actor()
if p_actor == 0 then
state.status = "Waiting for player actor..."
if panel and status_lbl then panel:set_text(status_lbl, "Status: " .. state.status) end
return false
end
local ok_s, socks = pcall(game.vfx.sockets, p_actor)
if state.is_mock then
assert(ok_s and type(socks) == "table" and #socks >= 1, "no sockets enumerated")
elseif not ok_s or type(socks) ~= "table" or #socks == 0 then
socks = { "Bip01_R_Hand", "Bip01_L_Hand", "Bip01_Spine1" }
end
local chosen = pick_distinct_sockets(socks)
local fx1 = pick_effect("fire_blade", "effect/weapon/fire_blade_aura.level.effect")
local fx2 = pick_effect("holy_shield", "effect/magic/holy_shield_aura.level.effect")
local fx3 = pick_effect("shadow_vortex", "effect/magic/shadow_vortex.level.effect")
stop_layers()
state.frames = 0
state.done = false
local specs = {
{
path = fx1,
attach_actor = p_actor,
socket = chosen[1],
offset = { x = 0.05, y = 0.10, z = 0.00 },
rot = { rx = 0.0, ry = 45.0, rz = 0.0 },
scale = { x = 0.85, y = 1.15, z = 0.85 },
duration = 6.0,
},
{
path = fx2,
attach_actor = p_actor,
socket = chosen[2],
offset = { -0.05, 0.10, 0.00 },
quat = { qx = 0.0, qy = 0.38268, qz = 0.0, qw = 0.92388 },
scale = { 0.90, 0.90, 1.10 },
duration = 6.0,
},
{
path = fx3,
attach_actor = p_actor,
socket = chosen[3],
offset = { x = 0.0, y = 0.25, z = -0.10 },
rot = { 15.0, 0.0, 15.0 },
scale = 1.20,
duration = 6.0,
},
}
for i = 1, 3 do
local ok_sp, h, err = pcall(game.vfx.spawn, specs[i])
if not ok_sp then h = nil end
if state.is_mock then
assert(h ~= nil, "layer " .. i .. " spawn failed: " .. tostring(err))
end
if h then
state.layers[#state.layers + 1] = h
end
end
state.started = true
state.status = string.format("Attached %d/3 layers (%s, %s, %s)", #state.layers, chosen[1], chosen[2], chosen[3])
if panel and status_lbl then panel:set_text(status_lbl, "Status: " .. state.status) end
return #state.layers > 0
end
if bsx.ui and bsx.ui.panel then
panel = bsx.ui.panel("VFX Socket Layers")
if panel then
status_lbl = panel:text("Status: " .. state.status)
panel:button("Attach 3 Layers", function() spawn_layers() end)
panel:same_line()
panel:button("Clear Layers", function() stop_layers() end)
end
end
bsx.on("world_ready", function()
state.world_ready = true
end)
bsx.on("frame", function()
if state.world_ready and not state.started then
spawn_layers()
return
end
if not state.started then return end
state.frames = state.frames + 1
local angle = state.frames * 4.0
if state.layers[1] and state.layers[1]:alive() then
local ok_t, res_t = pcall(function()
return state.layers[1]:set_transform({
offset = { x = 0.05, y = 0.10 + 0.03 * math.sin(state.frames * 0.2), z = 0.0 },
rot = { rx = 0.0, ry = angle, rz = 0.0 },
scale = { x = 0.9, y = 1.1, z = 0.9 },
})
end)
if state.is_mock then
assert(ok_t and res_t == true, "set_transform failed")
end
end
if not state.done and state.frames >= 5 then
local ok_a, act = pcall(game.vfx.active)
local active_count = (ok_a and type(act) == "table") and #act or #state.layers
if state.is_mock then
assert(ok_a and type(act) == "table" and #act >= 3, "expected >= 3 active socket layers")
for i = 1, 3 do
local inf = assert(state.layers[i]:info())
assert(inf.attached == true, "expected attached=true on layer " .. i)
end
end
state.done = true
bsx.log(string.format("VFX_SOCKET_LAYERS_OK active=%d", active_count))
end
end)
function on_unload()
stop_layers()
end