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

Make 1 out of X item always drop

Is there a way to always force a item to drop from a boss?
If we are talking about TFS 1.5 then I would go this way:

onDropLoot event
Lua:
ec.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    local doCreateLoot = false

    local specialItemIDs = {2195, 2488}
    if not player or player:getStamina() > 840 then
        doCreateLoot = true
    end

    if doCreateLoot then
        local monsterLoot = mType:getLoot()
        local specialItems = {}
        for i = 1, #monsterLoot do
            if table.contains(specialItemIDs, monsterLoot[i].itemId) then
                table.insert(specialItems, loot)
            else
                local item = corpse:createLootItem(monsterLoot[i], false)
                if not item then
                    print("[Warning] DropLoot: Could not add loot item to corpse.")
                end
            end
        end
        if #specialItems > 0 then
            local selectedSpecial = specialItems[math.random(#specialItems)]
            corpse:createLootItem(selectedSpecial, true)
        end
    end

    if player then
        local text
        if doCreateLoot then
            text = ("Loot of %s: %s."):format(mType:getNameDescription(), corpse:getContentDescription())
        else
            text = ("Loot of %s: nothing (due to low stamina)."):format(mType:getNameDescription())
        end
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_LOOT, text)
        end
    end
end

createLootItem function
Lua:
function Container.createLootItem(self, item, specialItem)
    if self:getEmptySlots() == 0 then
        return true
    end

    local itemCount = 0
    local randvalue = getLootRandom()
    local itemType = ItemType(item.itemId)

    if specialItem then
        if itemType:isStackable() then
                itemCount = randvalue % item.maxCount + 1
        else
                itemCount = 1
        end
    else
        if randvalue < item.chance then
            if itemType:isStackable() then
                itemCount = randvalue % item.maxCount + 1
            else
                itemCount = 1
            end
        end
    end

    while itemCount > 0 do
        local count = math.min(ITEM_STACK_SIZE, itemCount)

        local subType = count
        if itemType:isFluidContainer() then
            subType = math.max(0, item.subType)
        end

        local tmpItem = Game.createItem(item.itemId, subType)
        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

            if #item.childLoot > 0 and tmpItem:getSize() == 0 then
                tmpItem:remove()
                return true
            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

        local ret = self:addItemEx(tmpItem)
        if ret ~= RETURNVALUE_NOERROR then
            tmpItem:remove()
        end

        itemCount = itemCount - count
    end
    return true
end

You can add any item id you wish to be 'special' into this table specialItemIDs.
Remember that a monster need to have that item in his loot list.
 
Last edited:
Either that or go down the route like Canary did, add a "unique" attribute to any of your loot items, and then add the relevant code to deserialize (in items.cpp). Then when looping through loot, you can check for a unique attribute, and give it once (via highest score from damage map, or however else you like it)
 
Back
Top