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

onDroploot and bags question

xixigisi

New Member
Joined
May 11, 2023
Messages
16
Reaction score
2
Heloo guys!

I'm trying to implement a script to increase loot chance when player has an storage value. To do it, I'm using the function onDropLoot from EventCallback.

The original code is something like:

Lua:
local ec = EventCallback

ec.onDropLoot = function(self, 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
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            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_INFO_DESCR, 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_INFO_DESCR, text)
        end
    end
end

ec:register()

When I try to debug items chance (to understand how it works) it returned me it:

monsterLoot.chance: 2000
monsterLoot.chance: 20000
monsterLoot.chance: 50000
monsterLoot.chance: 70000
monsterLoot.chance: 40000
monsterLoot.chance: 200
monsterLoot.chance: 200
monsterLoot.chance: 100000

How to change chance from a item inside a bag?
The last item in the list is the bag, and I get no children of it.


The monster used for example is a cyclops:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Cyclops" nameDescription="a cyclops" race="blood" experience="150" speed="190" manacost="490">
    <health now="260" max="260"/>
    <look type="22" head="0" body="0" legs="0" feet="0" corpse="3069"/>
    <targetchange interval="1000" chance="5"/>
    <targetstrategies nearest="70" health="0" damage="30" random="0"/>
    <flags>
        <flag attackable="1"/>
        <flag hostile="1"/>
        <flag summonable="1"/>
        <flag convinceable="1"/>
        <flag illusionable="1"/>
        <flag pushable="0"/>
        <flag canpushitems="1"/>
        <flag canpushcreatures="1"/>
        <flag targetdistance="1"/>
        <flag staticattack="80"/>
        <flag runonhealth="0"/>
    </flags>
    <attacks>
        <attack name="melee" skill="50" attack="30"/>
    </attacks>
    <defenses armor="17" defense="62">
    </defenses>
    <elements>
    </elements>
    <immunities>
    </immunities>
    <voices interval="1000" chance="5">
        <voice sentence="Il lorstok human!"/>
        <voice sentence="Toks utat."/>
        <voice sentence="Human, uh whil dyh!"/>
        <voice sentence="Youh ah trak!"/>
        <voice sentence="Let da mashing begin!"/>
    </voices>
    <loot>
        <item id="5130" chance="2000" /><!-- Cyclops Toe -->
        <item id="2671" chance="20000" countmax="2"/><!-- 2 20% ham -->
        <item id="2666" chance="50000"/><!-- 50% meat -->
        <item id="2148" chance="70000" countmax="10"/><!-- 10 70% gold coin -->
        <item id="2148" chance="40000" countmax="20"/><!-- 20 40% gold coin -->
        <item id="2490" chance="200"/><!-- 0.2% dark helmet -->
        <item id="2129" chance="200"/><!-- 0.2% wolf tooth chain -->
        <item id="1987" chance="100000"><!-- bag -->
            <inside>
                <item id="2406" chance="8000"/><!-- 8% short sword -->
                <item id="2381" chance="700"/><!-- 0.7% halberd -->
                <item id="2510" chance="2000"/><!-- 2% plate shield -->
                <item id="2513" chance="1500"/><!-- 1.5% battle shield -->
                <item id="2209" chance="100"/><!-- 0.1% club ring -->
            </inside>
        </item>
    </loot>
</monster>
 
isn't it easier to just remove bags from all monsters by using regular expression+replace all? 🤔 even cipsoft knew bags are weird and removed them since 8.54 version, so unless your server is really old school and trying to 1:1 old tibia, you should just get rid of bag in monsters
 
isn't it easier to just remove bags from all monsters by using regular expression+replace all? 🤔 even cipsoft knew bags are weird and removed them since 8.54 version, so unless your server is really old school and trying to 1:1 old tibia, you should just get rid of bag in monsters
I thought about that. Just trying to understand why it happens.

If don't find some clear solution I'll remove bags, it will be not so hard.
 
Inside data\lib\core\container.lua
Find this function function Container.createLootItem(self, item)

Above this line
Lua:
   if randvalue < item.chance then
add this
Lua:
local chance = math.min(item.chance * boostedLootChanceMultiplier, MAX_LOOTCHANCE)

and boostedLootChanceMultiplier would be your storage value
 
Back
Top