potinho
Advanced OT User
I have a command on my server that brings information about monsters like health, EXP and loot. It works fine, but today I saw it reporting errors on the console. Could you help me to fix it and, if necessary, improve it?
Error:
[Error - TalkAction Interface]
data/talkactions/scripts/info.luanSay
Description:
data/talkactions/scripts/info.lua:36: attempt to index a boolean value
stack traceback:
data/talkactions/scripts/info.lua:36: in function 'getAttrMonster'
data/talkactions/scripts/info.lua:48: in function <data/talkactions/scripts/info.lua:38>
[Error - TalkAction Interface]
data/talkactions/scripts/info.luanSay
Description:
(luaGetMonsterInfo) Monster not found
[Error - TalkAction Interface]
data/talkactions/scripts/info.luanSay
Description:
data/talkactions/scripts/info.lua:36: attempt to index a boolean value
stack traceback:
data/talkactions/scripts/info.lua:36: in function 'getAttrMonster'
data/talkactions/scripts/info.lua:48: in function <data/talkactions/scripts/info.lua:38>
info.lua
Error:
[Error - TalkAction Interface]
data/talkactions/scripts/info.luanSay
Description:
data/talkactions/scripts/info.lua:36: attempt to index a boolean value
stack traceback:
data/talkactions/scripts/info.lua:36: in function 'getAttrMonster'
data/talkactions/scripts/info.lua:48: in function <data/talkactions/scripts/info.lua:38>
[Error - TalkAction Interface]
data/talkactions/scripts/info.luanSay
Description:
(luaGetMonsterInfo) Monster not found
[Error - TalkAction Interface]
data/talkactions/scripts/info.luanSay
Description:
data/talkactions/scripts/info.lua:36: attempt to index a boolean value
stack traceback:
data/talkactions/scripts/info.lua:36: in function 'getAttrMonster'
data/talkactions/scripts/info.lua:48: in function <data/talkactions/scripts/info.lua:38>
info.lua
Lua:
function ExistMonsterByName(name) -- by vodka
local monster = io.open("data/monster/monsters.xml", "r"):read("*all")
local get = monster:lower():match('name="' .. name:lower() ..'"')
if get == nil or get == "" then
return false
end
return true
end
function getDirMonsterByNameMonster(name)
local t = {}
local monster = io.open("data/monster/monsters.xml", "r")
for i in monster:read("*a"):gmatch('<monster name="'..tostring(name)..'" file="(.-)"/>') do
table.insert(t, tostring(i))
end
return t[1] or 0
end
function getMonsterLootItens(name)
local dir = "data/monster/"..getDirMonsterByNameMonster(name)..""
local monster = io.open(""..dir.."", "r")
str = ""
for i in monster:read("*a"):gmatch('id="(.-)"') do
str = ""..str.." - "..getItemNameById(i)..""
end
return str
end
function getAllMonster()
local str = ""
local monster = io.open("data/monster/monsters.xml", "r")
str = "Voce digitou incorretamente o nome do monstro veja a lista de monstro\n"
for i in monster:read("*a"):gmatch('<monster name="(.-)"') do
str = ""..str.." - "..i..""
end
return str
end
function getAttrMonster(name)
return "Life = "..getMonsterInfo(name).health.."\nExp = "..getMonsterInfo(name).experience.."\n"
end
function onSay(cid, words, param, channel)
if param == "" or not param or param == " " then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to enter the monster's name.")
return true
end
local name = param:lower()
if not ExistMonsterByName(name) then
doShowTextDialog(cid, 1397, getAllMonster()) return true
end
local name = name:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)
doShowTextDialog(cid, 1397, "Info Monster "..name.."\n"..getAttrMonster(name).."\n\nLoots = "..getMonsterLootItens(name).."")
return true
end