sm64coopdx/docs/lua/examples/texture-override/main.lua
2026-03-25 11:10:23 -05:00

43 lines
No EOL
1 KiB
Lua

-- name: Matrix Code
-- description: Run /matrix and a builtin texture name to replace with the digital rain
-- deluxe: true
local sMatrixFrames = {}
for i = 0, 10 do
sMatrixFrames[i] = get_texture_info("matrix_" .. i)
end
local matrixFrame = 0
local sOverrideTextures = {}
local globalTimer = 0
local function split(s)
local result = {}
for match in (s):gmatch(string.format("[^%s]+", " ")) do
table.insert(result, match)
end
return result
end
local function update()
globalTimer = globalTimer + 1
if globalTimer % 2 ~= 1 then return end
for _, texture in pairs(sOverrideTextures) do
texture_override_set(texture, sMatrixFrames[matrixFrame])
matrixFrame = (matrixFrame + 1) % 10
end
end
local function on_matrix_command(msg)
local textures = split(msg)
for _, texture in pairs(textures) do
table.insert(sOverrideTextures, texture)
end
return true
end
hook_event(HOOK_UPDATE, update)
hook_chat_command("matrix", "[TEXTURE]", on_matrix_command)