• 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

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
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...
The function you're looking for is probably getMonsterInfo(name), among other data, it will also return the monster's loot table.

im using a talkaction to do this, but got error in console:

[24/3/2021 9:48:35] [Error - TalkAction Interface]
[24/3/2021 9:48:35] data/talkactions/scripts/info.lua:eek:nSay
[24/3/2021 9:48:35] Description:
[24/3/2021 9:48:35] data/talkactions/scripts/info.lua:13: attempt to index local 'monster' (a nil value)
[24/3/2021 9:48:35] stack traceback:
[24/3/2021 9:48:35] data/talkactions/scripts/info.lua:13: in function 'getMonsterAttacks'
[24/3/2021 9:48:35] data/talkactions/scripts/info.lua:64: in function <data/talkactions/scripts/info.lua:57>


Talkaction 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 getMonsterAttacks(name)
local dir = "data/monster/"..getDirMonsterByNameMonster(name)..""
local monster = io.open(""..dir.."", "r")
str = ""
for i in monster:read("*a"):gmatch('attack name="(.-)"') do
str = ""..str.." - "..i..""
end
return str
end
function getMonsterDefense(name)
local dir = "data/monster/"..getDirMonsterByNameMonster(name)..""
local monster = io.open(""..dir.."", "r")
str = ""
for i in monster:read("*a"):gmatch('defense name="(.-)"') do
str = ""..str.." - "..i..""
end
return str
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.." - "..i..""
end
return str
end
function getMonsterVoices(name)
local dir = "data/monster/"..getDirMonsterByNameMonster(name)..""
local monster = io.open(""..dir.."", "r")
str = ""
for i in monster:read("*a"):gmatch('voice sentence="(.-)"') do
str = ""..str.." - "..i..""
end
return str
end
function getAllMonster()
local str = ""
local monster = io.open("data/monster/monsters.xml", "r")
str = "Você 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 "Vida = "..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, "Você precisa dizer o nome do monstro")
return true
end
local name = param
if (getMonsterInfo(param)) then
doShowTextDialog(cid, 1397, "Info Monster "..name.."\n"..getAttrMonster(name).."\nAttacks = "..getMonsterAttacks(name).."\n\nDefense = "..getMonsterDefense(name).."\n\nVoices = "..getMonsterVoices(name).."\n\nLoots = "..getMonsterLootItens(name).."")
else
doShowTextDialog(cid, 1397, getAllMonster())
return true
end
return true
end
 
Careful with using .io functions.
Ensure you close the files you open, or you'll have a memory leak.
 
thanks for advice Xikini, i will take care. Can u help me to do this funcionable?
This is well above anything I've ever attempted before.
I'm afraid I have nothing else to offer at this moment.

Although, I do agree that getMonsterInfo is probably a better approach.

and/or compiling the information into a table onStartUp, so you aren't having to recursively go through the monster files anytime you are looking for information.
 
This is well above anything I've ever attempted before.
I'm afraid I have nothing else to offer at this moment.

Although, I do agree that getMonsterInfo is probably a better approach.

and/or compiling the information into a table onStartUp, so you aren't having to recursively go through the monster files anytime you are looking for information.

I discovered something, the command is case sensitive, I need to type the name of the monster with the capital letter, like "Demon", is there any way to change this? Another thing is that in the loot he brings the item ID, how can he bring the name of the item?

1616597474882.png
 
I discovered something, the command is case sensitive, I need to type the name of the monster with the capital letter, like "Demon", is there any way to change this? Another thing is that in the loot he brings the item ID, how can he bring the name of the item?

View attachment 56779
getItemNameById(itemid)

as for your other issue.. you could make all the necessary change inside the code, so that you just need to worry about typing the correct letters..

example
Lua:
param = "Here you have a long List of Words"

-- this makes everything small characters
param = param:lower()

-- this turns the first letter of every word into uppercase
param = param:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)

-- print result
print(param)
 
getItemNameById(itemid)

as for your other issue.. you could make all the necessary change inside the code, so that you just need to worry about typing the correct letters..

example
Lua:
param = "Here you have a long List of Words"

-- this makes everything small characters
param = param:lower()

-- this turns the first letter of every word into uppercase
param = param:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)

-- print result
print(param)

I removed some things that didn't work for me, so the code looks like this:

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.." - "..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
if (getMonsterInfo(param)) then
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 didn't understand, where should I put getItemNameById (itemid), so that it brings the name of the item instead of the ID?
 
I removed some things that didn't work for me, so the code looks like this:

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.." - "..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
if (getMonsterInfo(param)) then
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 didn't understand, where should I put getItemNameById (itemid), so that it brings the name of the item instead of the ID?
This line, inside function function getMonsterLootItens(name)
Lua:
str = ""..str.." - "..i..""
Lua:
str = ""..str.." - "..getItemNameById(i)..""
 
This line, inside function function getMonsterLootItens(name)
Lua:
str = ""..str.." - "..i..""
Lua:
str = ""..str.." - "..getItemNameById(i)..""
Thank you so mery much, works. Now I have one last problem: if I type an incorrect name, like "auheuahshus", the script returns an alert in the game, like "You typed the name of the monster incorrectly, see the list below"


1616599073439.png


But if I enter a valid name only with lower case (like "dragon lord") it does not return any error in the game, only in the distro. Can you help me get the alert to appear in that case too?
 
Thank you so mery much, works. Now I have one last problem: if I type an incorrect name, like "auheuahshus", the script returns an alert in the game, like "You typed the name of the monster incorrectly, see the list below"


View attachment 56780


But if I enter a valid name only with lower case (like "dragon lord") it does not return any error in the game, only in the distro. Can you help me get the alert to appear in that case too?
You'd have to show me how you are currently checking the names.
 
You'd have to show me how you are currently checking the names.

I believe it is getting from the file "monsters.xml" which is in data / monster /

Follow monster.xml

XML:
<?xml version="1.0" encoding="UTF-8"?>
<monsters>
    <!-- Amazons -->
    <monster name="Amazon" file="Amazons/amazon.xml"/>
    <monster name="Valkyrie" file="Amazons/valkyrie.xml"/>

    <!-- Annelids -->
    <monster name="Rotworm" file="Annelids/rotworm.xml"/>ferumbras
    <monster name="Ferumbras" file="ferumbras.xml"/>

    <!-- Apes -->
    <monster name="Kongra" file="Apes/kongra.xml"/>
    <monster name="Merlkin" file="Apes/merlkin.xml"/>
    <monster name="Sibang" file="Apes/sibang.xml"/>

    <!-- Arachnids -->
    <monster name="Giant Spider" file="Arachnids/giant spider.xml"/>
    <monster name="Poison Spider" file="Arachnids/poison spider.xml"/>
    <monster name="Scorpion" file="Arachnids/scorpion.xml"/>
    <monster name="Spider" file="Arachnids/spider.xml"/>
    <monster name="Tarantula" file="Arachnids/tarantula.xml"/>

    <!-- Bears -->
    <monster name="Bear" file="Bears/bear.xml"/>
    <monster name="Panda" file="Bears/panda.xml"/>
    <monster name="Polar Bear" file="Bears/polar bear.xml"/>

    <!-- Bonelords -->
    <monster name="Elder Beholder" file="Bonelords/elder beholder.xml"/>
    <monster name="Gazer" file="Bonelords/gazer.xml"/>
    <monster name="Beholder" file="Bonelords/bonelord.xml"/>
    <monster name="The Evil Eye" file="Bonelords/the evil eye.xml"/>

    <!-- Bio-Elementals -->
    <monster name="Carniphila" file="Bio-Elementals/carniphila.xml"/>
    <monster name="Slime" file="Bio-Elementals/slime.xml"/>
    <monster name="Slime Summon" file="Bio-Elementals/slime summon.xml"/>
    <monster name="Spit Nettle" file="Bio-Elementals/spit nettle.xml"/>

    <!-- Birds -->
    <monster name="Chicken" file="Birds/chicken.xml"/>
    <monster name="Flamingo" file="Birds/flamingo.xml"/>
    <monster name="Parrot" file="Birds/parrot.xml"/>
    <monster name="Terror Bird" file="Birds/terror bird.xml"/>

    <!-- Bosses -->
    <monster name="Demodras" file="Bosses/demodras.xml"/>
    <monster name="Dharalion" file="Bosses/dharalion.xml"/>
    <monster name="Dracola" file="Bosses/dracola.xml"/>
    <monster name="Fernfang" file="Bosses/fernfang.xml"/>
    <monster name="General Murius" file="Bosses/general murius.xml"/>
    <monster name="Grorlam" file="Bosses/grorlam.xml"/>
    <monster name="Munster" file="Bosses/munster.xml"/>
    <monster name="Necropharus" file="Bosses/necropharus.xml"/>
    <monster name="Orshabaal" file="Bosses/orshabaal.xml"/>
    <monster name="The Horned Fox" file="Bosses/the horned fox.xml"/>
    <monster name="The Old Widow" file="Bosses/the old widow.xml"/>
    <monster name="Hero King" file="Bosses/hero king.xml"/>
    <monster name="Lucifer" file="Bosses/lucifer.xml"/>
    <monster name="Infernus" file="Bosses/infernus.xml"/>
    <!-- Canines -->
    <monster name="Dog" file="Canines/dog.xml"/>
    <monster name="War wolf" file="Canines/war wolf.xml"/>
    <monster name="Winter wolf" file="Canines/winter wolf.xml"/>
    <monster name="Wolf" file="Canines/wolf.xml"/>

    <!-- Crustaceans -->
    <monster name="Crab" file="Crustaceans/crab.xml"/>

    <!-- Demons -->
    <monster name="Demon" file="Demons/demon.xml"/>
    <monster name="Fire Devil" file="Demons/fire devil.xml"/>

    <!-- Djinns -->
    <monster name="Blue Djinn" file="Djinns/blue djinn.xml"/>
    <monster name="Efreet" file="Djinns/efreet.xml"/>
    <monster name="Green Djinn" file="Djinns/green djinn.xml"/>
    <monster name="Marid" file="Djinns/marid.xml"/>

    <!-- Dragons -->
    <monster name="Dragon Lord" file="Dragons/dragon lord.xml"/>
    <monster name="Dragon" file="Dragons/dragon.xml"/>

    <!-- Dwarves -->
    <monster name="Dwarf Geomancer" file="Dwarves/dwarf geomancer.xml"/>
    <monster name="Dwarf Guard" file="Dwarves/dwarf guard.xml"/>
    <monster name="Dwarf Soldier" file="Dwarves/dwarf soldier.xml"/>
    <monster name="Dwarf" file="Dwarves/dwarf.xml"/>

    <!-- Dworcs -->
    <monster name="Dworc Fleshhunter" file="Dworcs/dworc fleshhunter.xml"/>
    <monster name="Dworc Venomsniper" file="Dworcs/dworc venomsniper.xml"/>
    <monster name="Dworc Voodoomaster" file="Dworcs/dworc voodoomaster.xml"/>

    <!-- Elephants -->
    <monster name="Elephant" file="Elephants/elephant.xml"/>

    <!-- Elves -->
    <monster name="Elf Arcanist" file="Elves/elf arcanist.xml"/>
    <monster name="Elf Scout" file="Elves/elf scout.xml"/>
    <monster name="Elf" file="Elves/elf.xml"/>

    <!-- Felines -->
    <monster name="Lion" file="Felines/lion.xml"/>
    <monster name="Tiger" file="Felines/tiger.xml"/>

    <!-- Geo-Elementals -->
    <monster name="Gargoyle" file="Geo-Elementals/gargoyle.xml"/>
    <monster name="Stone Golem" file="Geo-Elementals/stone golem.xml"/>

    <!-- Ghosts -->
    <monster name="Ghost" file="Ghosts/ghost.xml"/>

    <!-- Giants -->
    <monster name="Behemoth" file="Giants/behemoth.xml"/>
    <monster name="Cyclops" file="Giants/cyclops.xml"/>
    <monster name="Yeti" file="Giants/yeti.xml"/>

    <!-- Goblins -->
    <monster name="Goblin" file="Goblins/goblin.xml"/>
    <!-- Grunts -->
    <monster name="Pig" file="Grunts/pig.xml"/>

    <!-- Insects -->
    <monster name="Ancient Scarab" file="Insects/ancient scarab.xml"/>
    <monster name="Blue Butterfly" file="Insects/blue butterfly.xml"/>
    <monster name="Bug" file="Insects/bug.xml"/>
    <monster name="Centipede" file="Insects/centipede.xml"/>
    <monster name="Larva" file="Insects/larva.xml"/>
    <monster name="Pink Butterfly" file="Insects/pink butterfly.xml"/>
    <monster name="Red Butterfly" file="Insects/red butterfly.xml"/>
    <monster name="Scarab" file="Insects/scarab.xml"/>
    <monster name="Wasp" file="Insects/wasp.xml"/>
    <monster name="Yellow Butterfly" file="Insects/yellow butterfly.xml"/>

    <!-- Lizards -->
    <monster name="Lizard Sentinel" file="Lizards/lizard sentinel.xml"/>
    <monster name="Lizard Snakecharmer" file="Lizards/lizard snakecharmer.xml"/>
    <monster name="Lizard Templar" file="Lizards/lizard templar.xml"/>

    <!-- Minotaurs -->
    <monster name="Minotaur Archer" file="Minotaurs/minotaur archer.xml"/>
    <monster name="Minotaur Guard" file="Minotaurs/minotaur guard.xml"/>
    <monster name="Minotaur Mage" file="Minotaurs/minotaur mage.xml"/>
    <monster name="Minotaur" file="Minotaurs/minotaur.xml"/>

    <!-- Misc -->
    <monster name="Badger" file="Misc/badger.xml"/>
    <monster name="Bat" file="Misc/bat.xml"/>
    <monster name="Deer" file="Misc/deer.xml"/>
    <monster name="Hyaena" file="Misc/hyaena.xml"/>
    <monster name="Rabbit" file="Misc/rabbit.xml"/>
    <monster name="Skunk" file="Misc/skunk.xml"/>

    <!-- Monks -->
    <monster name="Dark Monk" file="Monks/dark monk.xml"/>
    <monster name="Monk" file="Monks/monk.xml"/>

    <!-- Necromancers -->
    <monster name="Necromancer" file="Necromancers/necromancer.xml"/>
    <monster name="Priestess" file="Necromancers/priestess.xml"/>

    <!-- Orcs -->
    <monster name="Orc Berserker" file="Orcs/orc berserker.xml"/>
    <monster name="Orc Leader" file="Orcs/orc leader.xml"/>
    <monster name="Orc Rider" file="Orcs/orc rider.xml"/>
    <monster name="Orc Shaman" file="Orcs/orc shaman.xml"/>
    <monster name="Orc Spearman" file="Orcs/orc spearman.xml"/>
    <monster name="Orc Warlord" file="Orcs/orc warlord.xml"/>
    <monster name="Orc Warrior" file="Orcs/orc warrior.xml"/>
    <monster name="Orc" file="Orcs/orc.xml"/>

    <!-- Outlaws -->
    <monster name="Assasin" file="Outlaws/assasin.xml"/>
    <monster name="Bandit" file="Outlaws/bandit.xml"/>
    <monster name="Black Knight" file="Outlaws/black knight.xml"/>
    <monster name="Golden Knight" file="Outlaws/golden knight.xml"/>
    <monster name="Red Knight" file="Outlaws/red knight.xml"/>
    <monster name="Hero" file="Outlaws/hero.xml"/>
    <monster name="Hunter" file="Outlaws/hunter.xml"/>
    <monster name="Smuggler" file="Outlaws/smuggler.xml"/>
    <monster name="Stalker" file="Outlaws/stalker.xml"/>
    <monster name="Wild Warrior" file="Outlaws/wild warrior.xml"/>

    <!-- Pharaohs -->
    <monster name="Ashmunrah" file="Pharaohs/ashmunrah.xml"/>
    <monster name="Dipthrah" file="Pharaohs/dipthrah.xml"/>
    <monster name="Mahrdis" file="Pharaohs/mahrdis.xml"/>
    <monster name="Morguthis" file="Pharaohs/morguthis.xml"/>
    <monster name="Omruc" file="Pharaohs/omruc.xml"/>
    <monster name="Rahemos" file="Pharaohs/rahemos.xml"/>
    <monster name="Thalas" file="Pharaohs/thalas.xml"/>
    <monster name="Vashresamun" file="Pharaohs/vashresamun.xml"/>

    <!-- Pyro-Elementals -->
    <monster name="Fire Elemental" file="Pyro-Elementals/fire elemental.xml"/>

    <!-- Rats -->
    <monster name="Cave Rat" file="Rats/cave rat.xml"/>
    <monster name="Rat" file="Rats/rat.xml"/>

    <!-- Reptiles -->
    <monster name="Crocodile" file="Reptiles/crocodile.xml"/>
    <monster name="Hydra" file="Reptiles/hydra.xml"/>

    <!-- Serpents -->
    <monster name="Cobra" file="Serpents/cobra.xml"/>
    <monster name="Serpent Spawn" file="Serpents/serpent spawn.xml"/>
    <monster name="Snake" file="Serpents/snake.xml"/>

    <!-- Sheeps -->
    <monster name="Black Sheep" file="Sheeps/black sheep.xml"/>
    <monster name="Sheep" file="Sheeps/sheep.xml"/>

    <!-- Shapeshifters -->
    <monster name="Mimic" file="Shapeshifters/mimic.xml"/>

    <!-- Skeletons -->
    <monster name="Bonebeast" file="Skeletons/bonebeast.xml"/>
    <monster name="Bone Beast" file="Skeletons/bone beast.xml"/>
    <monster name="Demon Skeleton" file="Skeletons/demon skeleton.xml"/>
    <monster name="Skeleton" file="Skeletons/skeleton.xml"/>

    <!-- Sorcerers -->
    <monster name="Warlock" file="Sorcerers/warlock.xml"/>
    <monster name="Mercenary Mage" file="Sorcerers/mercenary mage.xml"/>
    <monster name="Witch" file="Sorcerers/witch.xml"/>
    <monster name="Master Warlock" file="Sorcerers/master warlock.xml"/>

    <!-- Traps -->
    <monster name="Deathslicer" file="Traps/deathslicer.xml"/>
    <monster name="Eye of the Seven" file="Traps/eye of the seven.xml"/>
    <monster name="Flamethrower" file="Traps/flamethrower.xml"/>
    <monster name="Lavahole" file="Traps/lavahole.xml"/>
    <monster name="Magicthrower" file="Traps/magicthrower.xml"/>
    <monster name="Poisonthrower" file="Traps/poisonthrower.xml"/>
    <monster name="Shredderthrower" file="Traps/shredderthrower.xml"/>

    <!-- Trolls -->
    <monster name="Frost Troll" file="Trolls/frost troll.xml"/>
    <monster name="Swamp Troll" file="Trolls/swamp troll.xml"/>
    <monster name="Troll" file="Trolls/troll.xml"/>

    <!-- Undead Humanoids -->
    <monster name="Banshee" file="Undead Humanoids/banshee.xml"/>
    <monster name="Crypt Shambler" file="Undead Humanoids/crypt shambler.xml"/>
    <monster name="Ghoul" file="Undead Humanoids/ghoul.xml"/>
    <monster name="Lich" file="Undead Humanoids/lich.xml"/>
    <monster name="Mummy" file="Undead Humanoids/mummy.xml"/>
    <monster name="Vampire" file="Undead Humanoids/vampire.xml"/>

    <!-- Custom Monsters -->
    <monster name="Trainer" file="trainer.xml"/>
</monsters>
 
I believe it is getting from the file "monsters.xml" which is in data / monster /

Follow monster.xml

XML:
<?xml version="1.0" encoding="UTF-8"?>
<monsters>
    <!-- Amazons -->
    <monster name="Amazon" file="Amazons/amazon.xml"/>
    <monster name="Valkyrie" file="Amazons/valkyrie.xml"/>

    <!-- Annelids -->
    <monster name="Rotworm" file="Annelids/rotworm.xml"/>ferumbras
    <monster name="Ferumbras" file="ferumbras.xml"/>

    <!-- Apes -->
    <monster name="Kongra" file="Apes/kongra.xml"/>
    <monster name="Merlkin" file="Apes/merlkin.xml"/>
    <monster name="Sibang" file="Apes/sibang.xml"/>

    <!-- Arachnids -->
    <monster name="Giant Spider" file="Arachnids/giant spider.xml"/>
    <monster name="Poison Spider" file="Arachnids/poison spider.xml"/>
    <monster name="Scorpion" file="Arachnids/scorpion.xml"/>
    <monster name="Spider" file="Arachnids/spider.xml"/>
    <monster name="Tarantula" file="Arachnids/tarantula.xml"/>

    <!-- Bears -->
    <monster name="Bear" file="Bears/bear.xml"/>
    <monster name="Panda" file="Bears/panda.xml"/>
    <monster name="Polar Bear" file="Bears/polar bear.xml"/>

    <!-- Bonelords -->
    <monster name="Elder Beholder" file="Bonelords/elder beholder.xml"/>
    <monster name="Gazer" file="Bonelords/gazer.xml"/>
    <monster name="Beholder" file="Bonelords/bonelord.xml"/>
    <monster name="The Evil Eye" file="Bonelords/the evil eye.xml"/>

    <!-- Bio-Elementals -->
    <monster name="Carniphila" file="Bio-Elementals/carniphila.xml"/>
    <monster name="Slime" file="Bio-Elementals/slime.xml"/>
    <monster name="Slime Summon" file="Bio-Elementals/slime summon.xml"/>
    <monster name="Spit Nettle" file="Bio-Elementals/spit nettle.xml"/>

    <!-- Birds -->
    <monster name="Chicken" file="Birds/chicken.xml"/>
    <monster name="Flamingo" file="Birds/flamingo.xml"/>
    <monster name="Parrot" file="Birds/parrot.xml"/>
    <monster name="Terror Bird" file="Birds/terror bird.xml"/>

    <!-- Bosses -->
    <monster name="Demodras" file="Bosses/demodras.xml"/>
    <monster name="Dharalion" file="Bosses/dharalion.xml"/>
    <monster name="Dracola" file="Bosses/dracola.xml"/>
    <monster name="Fernfang" file="Bosses/fernfang.xml"/>
    <monster name="General Murius" file="Bosses/general murius.xml"/>
    <monster name="Grorlam" file="Bosses/grorlam.xml"/>
    <monster name="Munster" file="Bosses/munster.xml"/>
    <monster name="Necropharus" file="Bosses/necropharus.xml"/>
    <monster name="Orshabaal" file="Bosses/orshabaal.xml"/>
    <monster name="The Horned Fox" file="Bosses/the horned fox.xml"/>
    <monster name="The Old Widow" file="Bosses/the old widow.xml"/>
    <monster name="Hero King" file="Bosses/hero king.xml"/>
    <monster name="Lucifer" file="Bosses/lucifer.xml"/>
    <monster name="Infernus" file="Bosses/infernus.xml"/>
    <!-- Canines -->
    <monster name="Dog" file="Canines/dog.xml"/>
    <monster name="War wolf" file="Canines/war wolf.xml"/>
    <monster name="Winter wolf" file="Canines/winter wolf.xml"/>
    <monster name="Wolf" file="Canines/wolf.xml"/>

    <!-- Crustaceans -->
    <monster name="Crab" file="Crustaceans/crab.xml"/>

    <!-- Demons -->
    <monster name="Demon" file="Demons/demon.xml"/>
    <monster name="Fire Devil" file="Demons/fire devil.xml"/>

    <!-- Djinns -->
    <monster name="Blue Djinn" file="Djinns/blue djinn.xml"/>
    <monster name="Efreet" file="Djinns/efreet.xml"/>
    <monster name="Green Djinn" file="Djinns/green djinn.xml"/>
    <monster name="Marid" file="Djinns/marid.xml"/>

    <!-- Dragons -->
    <monster name="Dragon Lord" file="Dragons/dragon lord.xml"/>
    <monster name="Dragon" file="Dragons/dragon.xml"/>

    <!-- Dwarves -->
    <monster name="Dwarf Geomancer" file="Dwarves/dwarf geomancer.xml"/>
    <monster name="Dwarf Guard" file="Dwarves/dwarf guard.xml"/>
    <monster name="Dwarf Soldier" file="Dwarves/dwarf soldier.xml"/>
    <monster name="Dwarf" file="Dwarves/dwarf.xml"/>

    <!-- Dworcs -->
    <monster name="Dworc Fleshhunter" file="Dworcs/dworc fleshhunter.xml"/>
    <monster name="Dworc Venomsniper" file="Dworcs/dworc venomsniper.xml"/>
    <monster name="Dworc Voodoomaster" file="Dworcs/dworc voodoomaster.xml"/>

    <!-- Elephants -->
    <monster name="Elephant" file="Elephants/elephant.xml"/>

    <!-- Elves -->
    <monster name="Elf Arcanist" file="Elves/elf arcanist.xml"/>
    <monster name="Elf Scout" file="Elves/elf scout.xml"/>
    <monster name="Elf" file="Elves/elf.xml"/>

    <!-- Felines -->
    <monster name="Lion" file="Felines/lion.xml"/>
    <monster name="Tiger" file="Felines/tiger.xml"/>

    <!-- Geo-Elementals -->
    <monster name="Gargoyle" file="Geo-Elementals/gargoyle.xml"/>
    <monster name="Stone Golem" file="Geo-Elementals/stone golem.xml"/>

    <!-- Ghosts -->
    <monster name="Ghost" file="Ghosts/ghost.xml"/>

    <!-- Giants -->
    <monster name="Behemoth" file="Giants/behemoth.xml"/>
    <monster name="Cyclops" file="Giants/cyclops.xml"/>
    <monster name="Yeti" file="Giants/yeti.xml"/>

    <!-- Goblins -->
    <monster name="Goblin" file="Goblins/goblin.xml"/>
    <!-- Grunts -->
    <monster name="Pig" file="Grunts/pig.xml"/>

    <!-- Insects -->
    <monster name="Ancient Scarab" file="Insects/ancient scarab.xml"/>
    <monster name="Blue Butterfly" file="Insects/blue butterfly.xml"/>
    <monster name="Bug" file="Insects/bug.xml"/>
    <monster name="Centipede" file="Insects/centipede.xml"/>
    <monster name="Larva" file="Insects/larva.xml"/>
    <monster name="Pink Butterfly" file="Insects/pink butterfly.xml"/>
    <monster name="Red Butterfly" file="Insects/red butterfly.xml"/>
    <monster name="Scarab" file="Insects/scarab.xml"/>
    <monster name="Wasp" file="Insects/wasp.xml"/>
    <monster name="Yellow Butterfly" file="Insects/yellow butterfly.xml"/>

    <!-- Lizards -->
    <monster name="Lizard Sentinel" file="Lizards/lizard sentinel.xml"/>
    <monster name="Lizard Snakecharmer" file="Lizards/lizard snakecharmer.xml"/>
    <monster name="Lizard Templar" file="Lizards/lizard templar.xml"/>

    <!-- Minotaurs -->
    <monster name="Minotaur Archer" file="Minotaurs/minotaur archer.xml"/>
    <monster name="Minotaur Guard" file="Minotaurs/minotaur guard.xml"/>
    <monster name="Minotaur Mage" file="Minotaurs/minotaur mage.xml"/>
    <monster name="Minotaur" file="Minotaurs/minotaur.xml"/>

    <!-- Misc -->
    <monster name="Badger" file="Misc/badger.xml"/>
    <monster name="Bat" file="Misc/bat.xml"/>
    <monster name="Deer" file="Misc/deer.xml"/>
    <monster name="Hyaena" file="Misc/hyaena.xml"/>
    <monster name="Rabbit" file="Misc/rabbit.xml"/>
    <monster name="Skunk" file="Misc/skunk.xml"/>

    <!-- Monks -->
    <monster name="Dark Monk" file="Monks/dark monk.xml"/>
    <monster name="Monk" file="Monks/monk.xml"/>

    <!-- Necromancers -->
    <monster name="Necromancer" file="Necromancers/necromancer.xml"/>
    <monster name="Priestess" file="Necromancers/priestess.xml"/>

    <!-- Orcs -->
    <monster name="Orc Berserker" file="Orcs/orc berserker.xml"/>
    <monster name="Orc Leader" file="Orcs/orc leader.xml"/>
    <monster name="Orc Rider" file="Orcs/orc rider.xml"/>
    <monster name="Orc Shaman" file="Orcs/orc shaman.xml"/>
    <monster name="Orc Spearman" file="Orcs/orc spearman.xml"/>
    <monster name="Orc Warlord" file="Orcs/orc warlord.xml"/>
    <monster name="Orc Warrior" file="Orcs/orc warrior.xml"/>
    <monster name="Orc" file="Orcs/orc.xml"/>

    <!-- Outlaws -->
    <monster name="Assasin" file="Outlaws/assasin.xml"/>
    <monster name="Bandit" file="Outlaws/bandit.xml"/>
    <monster name="Black Knight" file="Outlaws/black knight.xml"/>
    <monster name="Golden Knight" file="Outlaws/golden knight.xml"/>
    <monster name="Red Knight" file="Outlaws/red knight.xml"/>
    <monster name="Hero" file="Outlaws/hero.xml"/>
    <monster name="Hunter" file="Outlaws/hunter.xml"/>
    <monster name="Smuggler" file="Outlaws/smuggler.xml"/>
    <monster name="Stalker" file="Outlaws/stalker.xml"/>
    <monster name="Wild Warrior" file="Outlaws/wild warrior.xml"/>

    <!-- Pharaohs -->
    <monster name="Ashmunrah" file="Pharaohs/ashmunrah.xml"/>
    <monster name="Dipthrah" file="Pharaohs/dipthrah.xml"/>
    <monster name="Mahrdis" file="Pharaohs/mahrdis.xml"/>
    <monster name="Morguthis" file="Pharaohs/morguthis.xml"/>
    <monster name="Omruc" file="Pharaohs/omruc.xml"/>
    <monster name="Rahemos" file="Pharaohs/rahemos.xml"/>
    <monster name="Thalas" file="Pharaohs/thalas.xml"/>
    <monster name="Vashresamun" file="Pharaohs/vashresamun.xml"/>

    <!-- Pyro-Elementals -->
    <monster name="Fire Elemental" file="Pyro-Elementals/fire elemental.xml"/>

    <!-- Rats -->
    <monster name="Cave Rat" file="Rats/cave rat.xml"/>
    <monster name="Rat" file="Rats/rat.xml"/>

    <!-- Reptiles -->
    <monster name="Crocodile" file="Reptiles/crocodile.xml"/>
    <monster name="Hydra" file="Reptiles/hydra.xml"/>

    <!-- Serpents -->
    <monster name="Cobra" file="Serpents/cobra.xml"/>
    <monster name="Serpent Spawn" file="Serpents/serpent spawn.xml"/>
    <monster name="Snake" file="Serpents/snake.xml"/>

    <!-- Sheeps -->
    <monster name="Black Sheep" file="Sheeps/black sheep.xml"/>
    <monster name="Sheep" file="Sheeps/sheep.xml"/>

    <!-- Shapeshifters -->
    <monster name="Mimic" file="Shapeshifters/mimic.xml"/>

    <!-- Skeletons -->
    <monster name="Bonebeast" file="Skeletons/bonebeast.xml"/>
    <monster name="Bone Beast" file="Skeletons/bone beast.xml"/>
    <monster name="Demon Skeleton" file="Skeletons/demon skeleton.xml"/>
    <monster name="Skeleton" file="Skeletons/skeleton.xml"/>

    <!-- Sorcerers -->
    <monster name="Warlock" file="Sorcerers/warlock.xml"/>
    <monster name="Mercenary Mage" file="Sorcerers/mercenary mage.xml"/>
    <monster name="Witch" file="Sorcerers/witch.xml"/>
    <monster name="Master Warlock" file="Sorcerers/master warlock.xml"/>

    <!-- Traps -->
    <monster name="Deathslicer" file="Traps/deathslicer.xml"/>
    <monster name="Eye of the Seven" file="Traps/eye of the seven.xml"/>
    <monster name="Flamethrower" file="Traps/flamethrower.xml"/>
    <monster name="Lavahole" file="Traps/lavahole.xml"/>
    <monster name="Magicthrower" file="Traps/magicthrower.xml"/>
    <monster name="Poisonthrower" file="Traps/poisonthrower.xml"/>
    <monster name="Shredderthrower" file="Traps/shredderthrower.xml"/>

    <!-- Trolls -->
    <monster name="Frost Troll" file="Trolls/frost troll.xml"/>
    <monster name="Swamp Troll" file="Trolls/swamp troll.xml"/>
    <monster name="Troll" file="Trolls/troll.xml"/>

    <!-- Undead Humanoids -->
    <monster name="Banshee" file="Undead Humanoids/banshee.xml"/>
    <monster name="Crypt Shambler" file="Undead Humanoids/crypt shambler.xml"/>
    <monster name="Ghoul" file="Undead Humanoids/ghoul.xml"/>
    <monster name="Lich" file="Undead Humanoids/lich.xml"/>
    <monster name="Mummy" file="Undead Humanoids/mummy.xml"/>
    <monster name="Vampire" file="Undead Humanoids/vampire.xml"/>

    <!-- Custom Monsters -->
    <monster name="Trainer" file="trainer.xml"/>
</monsters>
Right.. but how are you checking the names to get the error?
I need to see the script.
 
Right.. but how are you checking the names to get the error?
I need to see the script.
I just have a talkaction to do this,

XML
XML:
    <talkaction words="/info" event="script" value="info.lua"/>

And the LUA, dont have other place with a script to do this

Lua:
[/B]
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
if (getMonsterInfo(param)) then
doShowTextDialog(cid, 1397, "Info Monster "..name.."\n"..getAttrMonster(name).."\n\nLoots = "..getMonsterLootItens(name).."")
else
doShowTextDialog(cid, 1397, getAllMonster())
return true
end
return true
end

in line 22 shows the message when a player type an incorrect name
 
I just have a talkaction to do this,

XML
XML:
    <talkaction words="/info" event="script" value="info.lua"/>

And the LUA, dont have other place with a script to do this

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
if (getMonsterInfo(param)) then
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 see now. Sorry.

You should do what I said earlier..
example
Lua:
param = "Here you have a long List of Words"

-- this makes everything small characters
param = param:lower()

-- this turns the first letter of every word into uppercase
param = param:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)

-- print result
print(param)
This way you only need to confirm if the monster exists, then let the code worry about capitalizing the letters correctly.
Lua:
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
 
Last edited:
I see now. Sorry.

You should do what I said earlier..

This way you only need to confirm if the monster exists, then let the code worry about capitalizing the letters correctly.
Lua:
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
    if getMonsterInfo(param) then
        name = param: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

Sorry if I'm being abusive, but I can't organize it within the current code due to lack of knowledge, could you help me?
 
Sorry if I'm being abusive, but I can't organize it within the current code due to lack of knowledge, could you help me?
I posted the answer already, you just need to copy paste. lol
 
Back
Top