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

Lua [TFS 1.3] Monster:onDropLoot question

E

Evil Puncker

Guest
Hello everyone, its me again, I have a table with monsters names, and one of them get selected on startUp and set its name into a variable, now I want to edit the monsters.lua OnDrop function so that specific creature gets twice the chance to drop loot, but I don't know how, can you guys help me?

Lua:
-- here is where I set the creature from a table with monsters name
local boostedMonster = boostedMonstersList[Game.getStorageValue(1232)]

-- here is the piece of code from data\events\scripts\monsters.lua that I think is needed to change:

        local monsterLoot = mType:getLoot()
        for i = 1, #monsterLoot do
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
            -- autoloot
            if item > 0 then
                local tmpItem = Item(item)
                if player and player:getAutoLootItem(tmpItem:getId()) then
                    if tmpItem:moveTo(player) then
                        autolooted = string.format("%s, %s", autolooted, tmpItem:getNameDescription())
                    end
                end
            end
        end

or maybe this file is not where I should mess with? I've found this function but I don't know how/where to use it, any help is welcome, thanks for reading
 
Solution
data/lib/core/container.lua
Lua:
function Container.createLootItem(self, item, rate)
    multiplier = multiplier or 1

    if self:getEmptySlots() == 0 then
        return true
    end

    local itemCount = 0
    local randvalue = getLootRandom()
    if (randvalue / rate) < item.chance then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

    if itemCount > 0 then
        local tmpItem = self:addItem(item.itemId, math.min(itemCount, 100))
        if not tmpItem then
            return false
        end

        if tmpItem:isContainer() then
            for i = 1, #item.childLoot do
                if not...
data/lib/core/container.lua
Lua:
function Container.createLootItem(self, item, rate)
    multiplier = multiplier or 1

    if self:getEmptySlots() == 0 then
        return true
    end

    local itemCount = 0
    local randvalue = getLootRandom()
    if (randvalue / rate) < item.chance then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

    if itemCount > 0 then
        local tmpItem = self:addItem(item.itemId, math.min(itemCount, 100))
        if not tmpItem then
            return false
        end

        if tmpItem:isContainer() then
            for i = 1, #item.childLoot do
                if not tmpItem:createLootItem(item.childLoot[i]) then
                    tmpItem:remove()
                    return false
                end
            end
        end

        if item.subType ~= -1 then
            tmpItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, item.subType)
        end

        if item.actionId ~= -1 then
            tmpItem:setActionId(item.actionId)
        end

        if item.text and item.text ~= "" then
            tmpItem:setText(item.text)
        end
    end
    return true
end

And just replace the createLootItem used in monster.lua with this:
Lua:
local item = corpse:createLootItem(monsterLoot[i], nil, boostedMonster)
Assuming `boostedMonster `contains the multiplier for the drop chance.
 
Solution
@Delusion boostedMonster contains the chosen monster name from this:

Lua:
BOOSTED_MONSTER = 56404
boostedMonstersList = {"rat", "spider", "troll", "orc", "demon"}

function globalevent.onStartup()
    local randomMonster = math.random(#boostedMonstersList)
    Game.setStorageValue(BOOSTED_MONSTER, randomMonster)
    local boostedMonster = boostedMonstersList[Game.getStorageValue(BOOSTED_MONSTER)]
    print("Today boosted monster is: " .. boostedMonster)
    return true
end
 
Back
Top