• 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 [7.72] Functional script returning error

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Hello everyone, everything good?

I have a script that is bothering me: it searches for the monsters that I have and some information about it. Everything works normal, including when I type a wrong or invalid name, it shows me the table with the name of the monsters and the alert that I typed wrong, but even with everything working, when I type a wrong name it returns the following error in console, could you help me remove this error? I have typed "/info blasduhadsuh" and return me a warning and table of monster.

1616714620871.png

But my console got error:

[25/3/2021 20:25:59] [Error - TalkAction Interface]
[25/3/2021 20:25:59] data/talkactions/scripts/info.lua:eek:nSay
[25/3/2021 20:25:59] Description:
[25/3/2021 20:25:59] (LuaInterface::luaGetMonsterInfo) Monster not found

Follow my script:

Lua:
function getDirMonsterByNameMonster(name)
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, "Voce precisa dizer o nome do monstro")
        return true
    end
    local name = param:lower()
    if getMonsterInfo(name) then
        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).."")
    else
        doShowTextDialog(cid, 1397, getAllMonster())
        return true
    end
    return true
end
 
Solution
Hello everyone, everything good?

I have a script that is bothering me: it searches for the monsters that I have and some information about it. Everything works normal, including when I type a wrong or invalid name, it shows me the table with the name of the monsters and the alert that I typed wrong, but even with everything working, when I type a wrong name it returns the following error in console, could you help me remove this error? I have typed "/info blasduhadsuh" and return me a warning and table of monster.

View attachment 56850

But my console got error:

[25/3/2021 20:25:59] [Error - TalkAction Interface]
[25/3/2021 20:25:59] data/talkactions/scripts/info.lua:eek:nSay
[25/3/2021 20:25:59] Description:
[25/3/2021 20:25:59]...
ummmm maybe try...

change
Lua:
if getMonsterInfo(name) then
to
Lua:
if getMonsterInfo(name) ~= nil then
-- or maybe..
if getMonsterInfo(name).name ~= nil then
 
ummmm maybe try...

change
Lua:
if getMonsterInfo(name) then
to
Lua:
if getMonsterInfo(name) ~= nil then
-- or maybe..
if getMonsterInfo(name).name ~= nil then
No one of this codes works, using this now the list of monster dont appear, console got this error:

[25/3/2021 20:47:12] [Error - TalkAction Interface]
[25/3/2021 20:47:12] data/talkactions/scripts/info.lua:eek:nSay
[25/3/2021 20:47:12] Description:
[25/3/2021 20:47:12] (LuaInterface::luaGetMonsterInfo) Monster not found

[25/3/2021 20:47:12] [Error - TalkAction Interface]
[25/3/2021 20:47:12] data/talkactions/scripts/info.lua:eek:nSay
[25/3/2021 20:47:12] Description:
[25/3/2021 20:47:12] data/talkactions/scripts/info.lua:36: attempt to index a boolean value
[25/3/2021 20:47:12] stack traceback:
[25/3/2021 20:47:12] data/talkactions/scripts/info.lua:36: in function <data/talkactions/scripts/info.lua:30>
 
I really didn't think it'd work. xD

But was worth a try.

Honestly.. the only thing I can think of is to get a table of all the monsters, and then compare against that.

So.. you'd want to do this onStartUp..

Create an empty table in lib/000-constant
Use your already pre-made function (getAllMonster()) in onStartUp.. but make it add all the monster names into the empty table instead of creating a string.
Then just compare against that table in the script using isInArray
 
Hello everyone, everything good?

I have a script that is bothering me: it searches for the monsters that I have and some information about it. Everything works normal, including when I type a wrong or invalid name, it shows me the table with the name of the monsters and the alert that I typed wrong, but even with everything working, when I type a wrong name it returns the following error in console, could you help me remove this error? I have typed "/info blasduhadsuh" and return me a warning and table of monster.

View attachment 56850

But my console got error:

[25/3/2021 20:25:59] [Error - TalkAction Interface]
[25/3/2021 20:25:59] data/talkactions/scripts/info.lua:eek:nSay
[25/3/2021 20:25:59] Description:
[25/3/2021 20:25:59] (LuaInterface::luaGetMonsterInfo) Monster not found

Follow my script:

Lua:
function getDirMonsterByNameMonster(name)
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, "Voce precisa dizer o nome do monstro")
        return true
    end
    local name = param:lower()
    if getMonsterInfo(name) then
        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).."")
    else
        doShowTextDialog(cid, 1397, getAllMonster())
        return true
    end
    return true
end
works with the code bellow:

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, "Voce precisa dizer o nome do monstro")
        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
Back
Top