Credits to Cykotitan, based on TFS 0.x version TalkAction - Debug LUA scripts with talkaction!
Talkaction that let you find problems with LUA scripts on GOD character.
You can also use it to do some admin actions in game. Fix small map bugs, make new spawns - without server restart.
XML data/talkactions/talkactions.xml:
LUA data/talkactions/scripts/lua_debug.lua:
Predefined variables:
cid - GOD character 'cid'
player - GOD character Player object
pos - position of GOD character
position - position of GOD character
Examples:
1. Get current position of player 'Adsad':
Result:
You can also split code to few lines:
2. Spawn monster Demon next to GOD:
3. Spawn monster Demon 20 times every 5 seconds on position on which is GOD in moment of saying !lua:
4. Set GOD storage value with key 123 to 456:
Set player 'Adsad' storage value with key 123 to 456:
5. Get GOD storage value with key 123:
Get player 'Adsad' storage value with key 123:
Result:
Talkaction that let you find problems with LUA scripts on GOD character.
You can also use it to do some admin actions in game. Fix small map bugs, make new spawns - without server restart.
XML data/talkactions/talkactions.xml:
XML:
<talkaction words="/lua" separator=" " script="lua_debug.lua" />
<talkaction words="!lua" separator=" " script="lua_debug.lua" />
LUA data/talkactions/scripts/lua_debug.lua:
LUA:
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
function onSay(player, words, param)
if player:getGroup():getId() <= 4 then
return false
end
if player:getAccountType() < ACCOUNT_TYPE_GAMEMASTER 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
Predefined variables:
cid - GOD character 'cid'
player - GOD character Player object
pos - position of GOD character
position - position of GOD character
Examples:
1. Get current position of player 'Adsad':
LUA:
!lua p = Player('Adsad'):getPosition() return p.x, p.y, p.z
Local Chat in Tibia client said:32368, 32224, 7
You can also split code to few lines:
LUA:
!lua var1 = Player('Adsad')
!lua var2 = var1:getPosition()
!lua return var2.x, var2.y, var2.z
2. Spawn monster Demon next to GOD:
LUA:
!lua Game.createMonster("Demon", pos)
3. Spawn monster Demon 20 times every 5 seconds on position on which is GOD in moment of saying !lua:
LUA:
!lua function spawnDemon(pos, countLeft) if countLeft > 0 then addEvent(spawnDemon, 5000, pos, countLeft - 1) end Game.createMonster("Demon", pos) end spawnDemon(pos, 20)
4. Set GOD storage value with key 123 to 456:
LUA:
!lua player:setStorageValue(123, 456)
LUA:
!lua Player('Adsad'):setStorageValue(123, 456)
5. Get GOD storage value with key 123:
LUA:
!lua return player:getStorageValue(123)
LUA:
!lua return Player('Adsad'):getStorageValue(123)
Local Chat in Tibia client said:
Last edited by a moderator: