• 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] NPC Helper

potinho

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

Is there any way to create an NPC that consults the monster files and their loots? I want to create an NPC that says which monster drops which item, or which monster drops a particular item, as if it were an in-game wiki. I would like to do it in the most automated way possible, without specifying item by item.
 
Solution
i guess i copy correctly, now my code is like this, only works if i use lower case:

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...
Sorry, didnt saw, u help me again, thanks bro. Just a thing, now when i type "Demon" console got error, only works if i type "demon". Is there a chance who works in both ways, like talkaction "/goto monster.name", works in both ways. @Xikini
 
Last edited:
Sorry, didnt saw, u help me again, thanks bro. Just a thing, now when i type "Demon" console got error, only works if i type "demon". Is there a chance who works in both ways, like talkaction "/goto monster.name", works in both ways. @Xikini
That makes no sense though.. cuz I lower case the param before it even checks.. So it should be checking the same way for both..?

Are you sure you copy-pasted correctly?
Or maybe you copy-pasted while I was still fiddling with it.. cuz the quote messages and your bold text were fighting each other. xD

Try copy-paste again, is what I'm saying, and tell us if you get the same issue.
 
That makes no sense though.. cuz I lower case the param before it even checks.. So it should be checking the same way for both..?

Are you sure you copy-pasted correctly?
Or maybe you copy-pasted while I was still fiddling with it.. cuz the quote messages and your bold text were fighting each other. xD

Try copy-paste again, is what I'm saying, and tell us if you get the same issue.
i saw my error, fixed. Thanks

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(param) 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
 
i guess i copy correctly, now my code is like this, only works if i use lower case:

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(param) 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
oh for the love of.. xD
I missed 1 line.

change
Lua:
if getMonsterInfo(param) then
to
Lua:
if getMonsterInfo(name) then
 
Solution
Back
Top