TalkAction [TFS 1.x / LuaJIT] Debug LUA scripts with talkaction!

Gesior.pl

Mega Noob&LOL 2012
Joined
Sep 18, 2007
Messages
2,027
Best answers
19
Reaction score
1,071
Location
PLand
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:
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
Result:
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)
Set player 'Adsad' storage value with key 123 to 456:
Lua:
!lua Player('Adsad'):setStorageValue(123, 456)
5. Get GOD storage value with key 123:
Lua:
!lua return player:getStorageValue(123)
Get player 'Adsad' storage value with key 123:
Lua:
!lua return Player('Adsad'):getStorageValue(123)
Result:
Local Chat in Tibia client said:
 
Last edited by a moderator:

pepsiman

---
Joined
Nov 17, 2017
Messages
118
Best answers
5
Reaction score
56
hey this is really useful. Thanks for sharing :D
 

slawkens

Developer
Premium User
Joined
Aug 27, 2007
Messages
2,880
Best answers
61
Reaction score
391
Location
Germany
For TFS 0.3.6+ (as a mod): slawkens/tfs-mods

Usage: (same as above, the only difference is Lua functions that are used in 0.3.6 that diverse from 1.x)

I am making a short tutorial currently, that I will update with time (currently just a few examples).

Link to tutorial with examples (work in progress): slawkens/tfs-mods
 
OP
Gesior.pl

Gesior.pl

Mega Noob&LOL 2012
Joined
Sep 18, 2007
Messages
2,027
Best answers
19
Reaction score
1,071
Location
PLand
Can some moderator change in my first post code:
PHP:
result = setmetatable({ ... }, {
to:
PHP:
local result = setmetatable({ ... }, {
#globalscope
@slawkens
 
Top