• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua Talkaction MonsterInfo

tiag0_bn

Active Member
Joined
Dec 8, 2011
Messages
155
Reaction score
39
I got a script here and would like help to fix it...

[19/2/2022 11:35:58] [Error - TalkAction Interface]
[19/2/2022 11:35:58] data/talkactions/scripts/info.lua:eek:nSay
[19/2/2022 11:35:58] Description:
[19/2/2022 11:35:58] data/talkactions/scripts/info.lua:21: attempt to index local 'monster' (a nil value)
[19/2/2022 11:35:58] stack traceback:
[19/2/2022 11:35:58] data/talkactions/scripts/info.lua:21: in function 'getMonsterLootItens'
[19/2/2022 11:35:58] data/talkactions/scripts/info.lua:48: in function <data/talkactions/scripts/info.lua:38>



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
 

soul4soul

Intermediate OT User
Joined
Aug 13, 2007
Messages
1,874
Solutions
3
Reaction score
126
Location
USA
What server are you using? Opening a file to get the data seems like a terrible idea, I think the creature metatable can be used instead.
 
OP
OP
tiag0_bn

tiag0_bn

Active Member
Joined
Dec 8, 2011
Messages
155
Reaction score
39

Roddet

Premium User
Support Team
Joined
May 1, 2013
Messages
791
Solutions
86
Reaction score
569
Location
Mex
Top