• 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!

Easily add new stuff to all your monsters

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
I got a request from someone ( I won't mention who :p ) They wanted to update their monsters based on certain criteria.

So lets say you wanted to add new attacks, spells, loot etc to specific creatures based on certain characteristics, like their immunities, elements, loot etc..

It is by no means a perfect script but it is definitely a good start, there is 2 modes, preview and production
by setting commit to false you will see the preview mode.
Something like this
Code:
>lua -e "io.stdout:setvbuf 'no'" "Mparser.lua"
data/monster/Blobs/essence of darkness.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Blobs/floor blob.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Bonelords/eye of the seven.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Bosses/countess sorrow.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Bosses/spider queen.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Dreamhaunters/bad dream.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Ghosts/ghost.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Ghosts/phantasm summon.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Ghosts/phantasm.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Ghosts/tarnished spirit.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Ghosts/tormented ghost.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Misc/Misc Mounts/Incredibly Old Witch.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Misc/Misc Mounts/modified gnarlhound.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Pharaohs/dipthrah.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Pirates/pirate ghost.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Sorcerers/yalahari.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/deathslicer.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/flamethrower.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/hive pore.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/lavahole.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/magic pillar.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/magicthrower.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/plaguethrower.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
data/monster/Traps/shredderthrower.xml    physical    immunity    <loot>    <item id="5911" chance="530" /><!-- red piece of cloth -->
>Exit code: 0

When commit is set to true then you enter the production mode and the changes are committed to the file.
Code:
>lua -e "io.stdout:setvbuf 'no'" "Mparser.lua"
data/monster/Blobs/essence of darkness.xml updated...
data/monster/Blobs/floor blob.xml updated...
data/monster/Bonelords/eye of the seven.xml updated...
data/monster/Bosses/countess sorrow.xml updated...
data/monster/Bosses/spider queen.xml updated...
data/monster/Dreamhaunters/bad dream.xml updated...
data/monster/Ghosts/ghost.xml updated...
data/monster/Ghosts/phantasm summon.xml updated...
data/monster/Ghosts/phantasm.xml updated...
data/monster/Ghosts/tarnished spirit.xml updated...
data/monster/Ghosts/tormented ghost.xml updated...
data/monster/Misc/Misc Mounts/Incredibly Old Witch.xml updated...
data/monster/Misc/Misc Mounts/modified gnarlhound.xml updated...
data/monster/Pharaohs/dipthrah.xml updated...
data/monster/Pirates/pirate ghost.xml updated...
data/monster/Sorcerers/yalahari.xml updated...
data/monster/Traps/deathslicer.xml updated...
data/monster/Traps/flamethrower.xml updated...
data/monster/Traps/hive pore.xml updated...
data/monster/Traps/lavahole.xml updated...
data/monster/Traps/magic pillar.xml updated...
data/monster/Traps/magicthrower.xml updated...
data/monster/Traps/plaguethrower.xml updated...
data/monster/Traps/shredderthrower.xml updated...
>Exit code: 0
 
And here is the sloppy code :p
Code:
    local data = {
        ['monster'] = {'name', 'nameDescription', 'race', 'experience', 'speed', 'manacost', 'skull', 'script'},
        ['health'] = {'min', 'max'},
        ['look'] =  { 'type', 'head', 'body', 'legs', 'feet', 'corpse', 'addons', 'typeex', 'mount'},
        ['targethange'] = { 'interval', 'chance', 'speed'},
        ['flag'] = {'summonable', 'attackable', 'hostile', 'illusionable', 'convinceable', 'pushable', 'canpushitems',
        'canpushcreatures', 'staticattack', 'lightlevel', 'lightcolor', 'targetdistance', 'runonhealth', 'hidehealth'},
        ['attack'] = {'name', 'interval', 'min', 'max', 'range', 'chance'},
        ['attribute'] = {'key', 'value'},
        ['defenses'] ={'armor', 'defense'},
        ['element'] = {'physicalPercent', 'icePercent', 'poisonPercent', 'earthPercent', 'firePercent', 'energyPercent',
        'holyPercent', 'deathPercent', 'drownPercent', 'lifedrainPercent', 'manadrainPercent'},
        ['immunity'] = {'name', 'physical', 'energy', 'fire', 'poison', 'earth', 'drown', 'ice', 'holy', 'death',
        'lifedrain', 'manadrain', 'paralyze', 'outfit', 'drunk', 'invisible', 'invisibility', 'bleed'},
        ['voices'] = {'speed', 'interval', 'chance', 'sentence', 'yell'},
        ['voice'] = {'speed', 'interval', 'chance', 'sentence', 'yell'},
        ['summons'] = {'maxSummons'},
        ['summon'] = {'name','interval','chance','speed'},
        ['script'] = {'name'},
        ['item'] = {'id','countmax','chance', 'chance1', 'subtype', 'actionId', 'text'}
    }

    -- its kind of a sloppy way to code, change this to the comparison value
    function comparison(v)
        return tonumber(v) > 0
    end
   -- change the values in this table to refine your search criteria
    local c = {
        -- all creatures with the immunity tag
        element = 'immunity',
        -- all creatures with the fire attribute, this is based on the comparison function above
        attribute = 'physical',
        -- this is the tag that were looking to append the updated information to
        elementTag = '<loot>',
        -- the stuff you want to add to the file
        append = '<item id="5911" chance="530" /><!-- red piece of cloth -->',
        -- should we execute this or just preview the results
        commit = false
    }

    local tempName = {}
    local creatures = {}


    local dir = 'data/monster/'
    local file = 'monsters.xml'

    -- this aspect will just read the files initially so we can track down the creatures that meet the criteria
    for line in io.lines(dir..file) do
        if string.match(line, '<(%a-)%s* ') ~= nil then
            -- temporarily store all the creatures directories
            tempName[#tempName+1] = dir..line:match('file="(.-)"')
            for lines in io.lines(dir..line:match('file="(.-)"') ) do
                if string.match(lines, '<(%a-)%s* ') ~= nil then
                    local p = data[string.match(lines, '<(%a-)%s* ')]
                    if p ~= nil then
                        for i = 1, #p do
                            -- which element & attribute are we looking for
                            if c.attribute == p[i] and string.match(lines, '<(%a-)%s* ') == c.element then
                                local t = lines:match(p[i]..'="(.-)"')
                                -- the kind of data to filter, comparison function will determine this
                                if t ~= nil and comparison(t) then
                                    -- only store the creatures that meet the criteria
                                    creatures[#creatures+1] = tempName[#tempName]
                                end
                            end
                        end
                    end
                end
           end
        end
    end



    function updatedFile(filename, element, str)
        local tempFile = {}
        for line in io.lines(filename) do
            tempFile[#tempFile + 1] = line
        end

        for k, l in ipairs(tempFile) do
            if l:match(element) then
                table.insert(tempFile, k+1, str)
            end
        end
        local file = assert(io.open(filename, "w+"))
        for i, d in ipairs(tempFile) do
            file:write(d, "\n")
        end
        print(filename..' updated...')
        file:close()
    end

    -- now we can directly access those files and work on modifying them
    for _, path in pairs(creatures) do
        if c.commit then
            updatedFile(path, c.elementTag, c.append)
        else
            print(path, c.attribute, c.element, c.elementTag, c.append)
        end
    end
 
Last edited:
Meh.. it works for only existing tags, so if the file doesn't contain the tag then it won't write to it.. no biggie :p

e.g. loot, defenses etc..
 
Great. It is associatively configured with the current options.

Thanks.
 

Similar threads

Back
Top