• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X [LUA] Info command - attempt to index a boolean value

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,402
Solutions
17
Reaction score
150
Location
Brazil
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.lua:eek:nSay
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.lua:eek:nSay
Description:
(luaGetMonsterInfo) Monster not found

[Error - TalkAction Interface]
data/talkactions/scripts/info.lua:eek:nSay
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
 
Solution
Because there is no check for special/punctuation characters
!monster rat* <-- this will lead to the error

Just replace
Lua:
local name = param:lower()

To
Lua:
local name = param:lower():gsub("%p", "")
This will find and delete special characters in case they were found on the name string
Because there is no check for special/punctuation characters
!monster rat* <-- this will lead to the error

Just replace
Lua:
local name = param:lower()

To
Lua:
local name = param:lower():gsub("%p", "")
This will find and delete special characters in case they were found on the name string
 
Last edited:
Solution
Because there is no check for special/punctuation characters
!monster rat* <-- this will lead to the error

Just replace
Lua:
local name = param:lower()

To
Lua:
local name = param:lower():gsub("%p", "")
This will find and delete special characters in case they were found on the name string
Wow! Exactly that, thank you very much Roddet.
 
Back
Top