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

monsters drop empty bags

zaptos

New Member
Joined
May 16, 2019
Messages
36
Reaction score
4
is there a way to fix this? using tfs 1.3 8.6

Code:
    <loot>
        <item id="2148" countmax="10" chance="23000"/><!-- gold coin -->
        <item id="2229" countmax="2" chance="55500"/><!-- skull -->
        <item id="2379" chance="81000"/><!-- dagger -->
        <item id="2467" chance="43000"/><!-- leather armor -->
        <item id="2691" chance="26000"/><!-- brown bread -->
        <item id="2385" chance="22000"/><!-- sabre -->
        <item id="1987" chance="100000"><!-- bag -->
            
        <item id="2526" chance="7000"/><!-- studded shield -->
        <item id="2050" chance="5000"/><!-- torch -->
        <item id="2125" chance="500"/><!-- crystal necklace -->
        <item id="2147" chance="200"/><!-- small ruby -->   
            
        </item>
    </loot>
</monster>
Post automatically merged:

i want bags to drop only when there is loot inside of them
 
Last edited:
Post your container.lua
It should already only be dropping bags if their are items in them because of this.
Code:
function Container.isContainer(self)
    return true
end

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

    local itemCount = 0
    local randvalue = getLootRandom()
    if randvalue < 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
 
I don't think the stock TFS code cares for bags properly, as bags were removed from loot entirely way before this was added.
Leave this with me for a bit.

Alternatively, the stock code does try to look for childloot:
Post your container.lua
It should already only be dropping bags if their are items in them because of this.

So maybe try using the oldschool inside flags and see if that works with the default code??
XML:
<loot>
    <item id="x" countmax="x" chance="x"/>
    <item id="x" chance="x"/>
    <item id="1987" chance="10000"> <!-- bag -->
        <inside>
            <item id="x" chance="x"/>
        </inside>
    </item>
</loot>
 
Last edited:
I don't think the stock TFS code cares for bags properly, as bags were removed from loot entirely way before this was added.
Leave this with me for a bit.
Post automatically merged:

I can't test this as my container.lua and monster.lua are custom.
But something like this should fix it?

replace monster.lua with:
Lua:
function Monster:onDropLoot(corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    if not player or player:getStamina() > 840 then
        local monsterLoot = mType:getLoot()
        for i = 1, #monsterLoot do
            -- Bag fix?
            if ItemType(monsterLoot[i].ItemId):isContainer() then
                local bag = corpse:addItem(monsterLoot[i])
                if bag then
                    local index = i + 1
                    if index < #monsterLoot then
                        for j = index, #monsterLoot do
                            if bag:getItemHoldingCount() < bag:getSize() then
                                bag:createLootItem(monsterLoot[index])
                            end
                        end
                    end
                    if bag:getItemHoldingCount() == 0 then
                        bag:remove()
                    end
                end
                break
            else
                local item = corpse:createLootItem(monsterLoot[i])
                if not item then
                    print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
                end
            end
        end

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

Alternatively, the stock code does try to look for childloot:


So maybe try using the oldschool inside flags and see if that works with the default code??
XML:
<loot>
    <item id="x" countmax="x" chance="x"/>
    <item id="x" chance="x"/>
    <item id="1987" chance="10000"> <!-- bag -->
        <inside>
            <item id="x" chance="x"/>
        </inside>
    </item>
</loot>
Lua Script Error: [Event Interface]
data/events/scripts/monster.lua:Monster@onDropLoot
data/events/scripts/monster.lua:12: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/events/scripts/monster.lua:12: in function <data/events/scripts/monster.lua:1>
 
Capital letter I stuffed it:

Change:
if ItemType(monsterLoot[i].ItemId):isContainer() then

to:
if ItemType(monsterLoot[i].itemId):isContainer() then

on line 12
 
Capital letter I stuffed it:

Change:
if ItemType(monsterLoot[i].ItemId):isContainer() then

to:
if ItemType(monsterLoot[i].itemId):isContainer() then

on line 12
crashes client:confused: i also tried doing the old <inside> but that does not work either
 
crashes client:confused: i also tried doing the old <inside> but that does not work either

Are you using OTClient? It might help to upload the crash log from otclient.txt for better information. From my past experience, the client crashing is usually from custom edits. your otclient.txt would provide better insight into the crash. Or if you have your client open do a ctrl+t to get the terminal and try to have the charcter kill again. It might show you in the terminal as to what is going on.
 
Are you using OTClient? It might help to upload the crash log from otclient.txt for better information. From my past experience, the client crashing is usually from custom edits. your otclient.txt would provide better insight into the crash. Or if you have your client open do a ctrl+t to get the terminal and try to have the charcter kill again. It might show you in the terminal as to what is going on.
im using nekiro/forgottenserver (https://github.com/nekiro/forgottenserver/tree/8.6-downgrade)
 
This tells me that you just add child nodes:

So put monster.lua and container.lua back to stock.
And try this in your monster xml file, as an item:
XML:
<item id="1987" chance="10000">
    <item id="7588" chance="10000" /><!-- strong health potion -->
</item>
 
Last edited:
This tells me that you just add child nodes:

So put monster.lua and container.lua back to stock.
And try this in your monster xml file, as an item:
XML:
<item id="1987" chance="10000">
    <item id="7588" chance="10000" /><!-- strong health potion -->
</item>

Wouldn't this mean that the bag has a 10% chance of dropping as well? So maybe the items inside drop, but the bag doesn't.

I just tried removing the empty bag from a demon's loot, and setting every item to 100% chance. Maybe the empty bag would magically appear, but that wasn't the case.

The empty bags a messing with my OCD...
 
TFS handles bags just fine...
That's how you are supposed to use it:
XML:
<item id="1987" chance="100000"> <!-- bag -->
    <item id="2160" countmax="4" chance="100000" /> <!-- crystal coin -->
</item>
1589639549680.png
 
Alright. But in this case it seems the monster will drop a crystal coin 100% of the time, right?

My issue is that they are always dropping a bag, even if it's empty.

Great job on the downgrade, by the way!
 
Back
Top