好吧,所以我知道如何很好地使用元表,但是我正在尝试对游戏功能进行备份(使用getrawmetatable(game))例如,下面的脚本在游戏中禁用了功能Kick()< / p>
local getrawmetatable = getrawmetatable or debug.getmetatable
local make_writeable = make_writeable or setreadonly or changereadonly or
change_writeable
make_writeable(getrawmetatable(game), false)
local backup = getrawmetatable(game).__namecall
getrawmetatable(game).__namecall = function(u, ...)
local m = ({...})[select('#', ...)]
local packed = {...}
local a = {}
for i = 1, #packed - 1 do
a[i] = packed[i]
end
if m == 'Kick' then
warn('Kick attempt at ' .. os.time() .. ' (' .. tostring(unpack(a)) ..
')')
return true
end
return backup and backup(u, ...) or u[m](u, unpack(a))
end
我知道您可以使用
将表恢复到原始状态local mt = getrawmetatable(game)
mt.__namecall = backup
但是有一种方法可以备份所有名称调用(到文件或其他内容),然后将其恢复为原始功能