• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Useful for GM (Check monster loot)

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
I made this command based in a script by Nahruto.

This command will obtain the loot of a monster.

Create a file called monster_info.lua and paste this
Lua:
function onSay(cid, words, param, channel)

local monsterFile = "data/monster/" .. param .. ".xml"
local loot = {}
local t = 0
local text = "File opened: " .. monsterFile .. ""

	if (io.open(monsterFile, "r") ~= nil) then
	for line in io.lines(monsterFile) do
		if (line:find('id=".*".*')) then
			line = string.match(line, 'id=".*".*')
			lootid = string.sub(line, string.find(line, '="') + 2, string.find(line, '" ') - 1)
			table.insert(loot, lootid)
		end
	end
	text = text .. "\n\n" .. "Found " .. #loot .. " items\n"
	for _, i in ipairs(loot) do
		t = t + 1
		text = text .. "\n " .. t .. ". " .. getItemArticleById(i) .. " " .. getItemNameById(i) .. " [" .. i .. "]"
	end
		doPlayerPopupFYI(cid, text)
		return TRUE
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "File: " .. monsterFile .. " does not exist.")
		return TRUE
	end
	return TRUE
end

Add this to talkactions.xml
Lua:
	<talkaction log="yes" words="/minfo" event="script" value="monster_info.lua" />

Example: /minfo bosses/ghazbaran
ivxsuc.jpg
 
Last edited:
This have a problem, because this will check in the folder data/monster, but all monster come in different inside monster.
español:
Esto tiene un problema, porque el script solo revisa dentro de la carpeta data/monster y los monstruos vienen en carpetas diferentes cada uno...

Ej:

data/monster/amazons/amazon.xml ^_^

but you script only check

data/monster/amazon.xml :(

And i don't want put all monster together in the same folder or put alway the subfolder :(
 
Last edited:
This have a problem, because this will check in the folder data/monster, but all monster come in different inside monster.


Ej:

data/monster/amazons/amazon.xml ^_^

but you script only check

data/monster/amazon.xml :(

And i don't want put all monster together in the same folder or put alway the subfolder :(

Exactly.

Helpful here may be getMonsterLootList(name) which is in TFS 0.3+ from half year ;)
 
You idiots! Someone showed you how to operate on files and now you're doing useless scripts. :blink:
 
@up, this script is usefull. Thanks for it.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Nice job!

What about showing the chances? For example, if the chances are set to "3333", show:
1. a mastermind shield [2514](3.333%)
 
ah you copied me >_>

you should do like this

Lua:
local myFile = "data/monster/monsters.xml"

local function getMonsterFile(name)
    local name, file = tostring(name), nil
    if (io.open(myFile, "r") ~= nil) then
        for line in io.lines(myFile) do
            if (line:find(name) and not (line:find("<!--"))) then
                n = string.match(line, 'name=".*".*')
                _name = string.sub(n, string.find(n, '="') + 2, string.find(n, '" ') - 1)
                if name:len() == _name:len() then
                    f = string.match(line, 'file=".*".*')
                    file = string.sub(f, string.find(f, '="') + 2, string.find(f, '"/') - 1)
                end
            end
        end
    end
    return file
end

local myTable = {}

function getXMLValues(str, values, ignored)
    if type(values) == 'table' then
        for _, i in ipairs(values) do
            for _, x in ipairs(ignored) do
                if not (str:find(x)) then
                    if (str:find(i)) then
                        t = string.match(str, i .. '=".*".*')
                        _t = string.find(t, '" ') or string.find(t, '"/') or string.find(t, '">')
                        info = string.sub(t, string.find(t, '="') + 2, _t - 1)
                        table.insert(myTable, info)
                    end
                end
            end
        end
    end
    return myTable
end

function onSay(cid, words, param, channel)
    local file, txt = getMonsterFile(param), "Monster Info\n\n"
    if file then
        file = "data/monster/" .. file
        if (io.open(file, "r") ~= nil) then
            for line in io.lines(file) do
                vals = 
                {
                    '<monster name', 
                    'race',
                    'experience',
                    'speed',
                    'manacost',
                    '<health now',
                    '<flag summonable',
                    '<flag convinceable'
                }
                ignore = 
                {
                    'name="speed"'
                }
                info = getXMLValues(line, vals, ignore)
            end
            infos = 
            {
                "Nombre = ",
                "Raza = ",
                "Experiencia = ",
                "Velocidad = "
            }
            for _i, i in ipairs(infos) do
                txt = txt .. i .. info[_i] .. "\n"
            end
            txt = txt .. "Hitpoints = " .. info[6] .. "\n"
            s, c = tonumber(info[7]), tonumber(info[8])
            txt = txt .. "Summoneable = " .. (s == 1 and "Si" or "No") .. "\n"
            txt = txt .. "Convinceable = " .. (c == 1 and "Si" or "No") .. "\n"
            if (s == 1 or c == 1) then
                txt = txt .. "Costo de mana = " .. info[5] .. "\n"
            end
            doPlayerPopupFYI(cid, txt)
            myTable = {}
        end
    else
        doPlayerPopupFYI(cid, "Sorry, monster name is wrong.")
    end
    return TRUE
end

see the example and do your job
 
Back
Top