Skip to content

Commit

Permalink
Create debugLua.lua (#51)
Browse files Browse the repository at this point in the history
Feature for lua commands in-game, interesting for DEV's.
Function by Gesior, found here:
https://otland.net/threads/tfs-1-x-luajit-debug-lua-scripts-with-talkaction.260910/
  • Loading branch information
LuanGP authored Jan 22, 2025
1 parent 61f3e27 commit 7130b41
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions data/scripts/talkactions/debugLua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function sendToPlayerLuaCallResult(player, ...)
local n = select('#', ...)
local result = setmetatable({ ... }, {
__len = function()
return n
end,
})

local t = {}
for i = 2, #result do
local v = tostring(result[i])
if v:len() > 0 then
table.insert(t, v)
end
end

if #t > 0 then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, table.concat(t, ', '))
end
end


local talk = TalkAction("/lua")
function talk.onSay(player, words, param)
if player:getGroup():getId() < 6 then
return false
end

if player:getAccountType() < ACCOUNT_TYPE_GOD then
return false
end

sendToPlayerLuaCallResult(player, pcall(loadstring(
'local cid = ' .. player:getId() .. ' ' ..
'local player = Player(cid) ' ..
'local pos = player:getPosition() ' ..
'local position = pos ' ..
param
)))

return false
end

talk:separator(" ")
talk:register()

0 comments on commit 7130b41

Please sign in to comment.