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

Item chance unique="1" drop double Reward Chest

Azerty

Active Member
Joined
Apr 15, 2022
Messages
316
Solutions
4
Reaction score
32
Can anyone help me with this problem, all participants are getting a reward for an item that should be unique, Ex: Ferumbras' Hat. Any solution?

Lua:
if not globalBosses then
    globalBosses = {}
end

function Monster.setReward(self, enable)
    if enable then
        if not self:getType():isRewardBoss() then
            error("Rewards can only be enabled to rewards bosses.")
            return false
        end
        globalBosses[self:getId()] = {}
        self:registerEvent("BossDeath")
        self:registerEvent("BossThink")
    else
        globalBosses[self:getId()] = nil
        self:unregisterEvent("BossDeath")
        self:unregisterEvent("BossThink")
    end
    return true
end

local function pushValues(buffer, sep, ...)
    local argv = {...}
    local argc = #argv
    for k, v in ipairs(argv) do
        table.insert(buffer, v)
        if k < argc and sep then
            table.insert(buffer, sep)
        end
    end
end

function Item.getNameDescription(self)
    local subType = self:getSubType()
    local itemType = self:getType()

    local buffer = {}

    local name = self:getName() or ''
    if(#name ~= 0) then
        if(itemType:isStackable() and subType > 1) then
            pushValues(buffer, ' ', subType, self:getPluralName())
        else
            local article = self:getArticle() or ''
            pushValues(buffer, ' ', select(#article ~= 0 and 1 or 2, article, name))
        end
    else
        pushValues(buffer, ' ', 'an item of type', self:getId())
    end

    return table.concat(buffer)
end

function Container.getContentDescription(self, outputBuffer)
    local firstItem = true
    local buffer = outputBuffer or {}
    for i = 1, self:getSize() do
        local item = self:getItem(i - 1)

        if(firstItem) then
            firstItem = false
        else
            table.insert(buffer, ", ")
        end

        table.insert(buffer, item:getNameDescription())
    end

    if firstItem then
        table.insert(buffer, "nothing")
    end

    if not outputBuffer then
        return table.concat(buffer)
    end
end

function Player.getRewardChest(self, autocreate)
    return self:getDepotChest(99, autocreate)
end

function Player.inBossFight(self)
    if not next(globalBosses) then
        return false
    end
    local playerGuid = self:getGuid()

    for _, info in pairs(globalBosses) do
        local stats = info[playerGuid]
        if stats and stats.active then
            return stats
        end
    end
    return false
end

-- by https://otland.net/members/cbrm.25752/ with some modifications
function MonsterType.createLootItem(self, lootBlock, chance, lootTable)
    local lootTable, itemCount = lootTable or {}, 0
    local randvalue = math.random(0, 100000) / (getConfigInfo("rateLoot") * chance)
    if randvalue < lootBlock.chance then
        if (ItemType(lootBlock.itemId):isStackable()) then
            itemCount = randvalue % lootBlock.maxCount + 1
        else
            itemCount = 1
        end
    end

    while itemCount > 0 do
        local n = math.min(itemCount, 100)
        itemCount = itemCount - n
        table.insert(lootTable, {lootBlock.itemId, n})
    end

    return lootTable
end

function MonsterType.getBossReward(self, lootFactor, topScore)
    local result = {}
    if getConfigInfo("rateLoot") > 0 then
        local loot = self:getLoot() or {}
        for i = #loot, 0, -1 do
            local lootBlock = loot[i]
            if lootBlock then
                if lootBlock.unique and not topScore then
                    --continue
                else
                    self:createLootItem(lootBlock, lootFactor, result)
                end
            end
        end
    end
    return result
end

XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Ferumbras" nameDescription="Ferumbras" race="venom" experience="12000" speed="320" script="rewardboss.lua">
    <health now="50000" max="50000"/>
    <look type="229" corpse="6078"/>
    <targetchange interval="5000" chance="8"/>
    <flags>
        <flag rewardboss="1" />
        <flag summonable="0"/>
        <flag attackable="1"/>
        <flag hostile="1"/>
        <flag illusionable="0"/>
        <flag convinceable="0"/>
        <flag pushable="0"/>
        <flag canpushitems="1"/>
        <flag canpushcreatures="1"/>
        <flag targetdistance="2"/>
        <flag staticattack="90"/>
        <flag runonhealth="2500"/>
    </flags>
    <attacks>
        <attack name="melee" interval="2000" min="0" max="-350"/>
        <attack name="manadrain" interval="2000" chance="20" range="7" min="-500" max="-700">
            <attribute key="areaEffect" value="redshimmer"/>
        </attack>
        <attack name="lifedrain" interval="2000" chance="25" length="8" spread="0" min="-300" max="-450">
            <attribute key="areaEffect" value="greenspark"/>
        </attack>
        <attack name="lifedrain" interval="2000" chance="21" radius="6" target="0" min="-450" max="-500">
            <attribute key="areaEffect" value="poff"/>
        </attack>
        <attack name="poisoncondition" interval="2000" chance="15" range="7" min="-20" max="-40">
            <attribute key="shooteffect" value="poison"/>
        </attack>
        <attack name="lifedrain" interval="2000" chance="15" target="0" radius="3" range="4" min="-900" max="-1000"/>
        <attack name="energycondition" interval="2000" chance="18" radius="6" target="0" min="-300" max="-400">
            <attribute key="areaEffect" value="energy"/>
        </attack>
        <attack name="firecondition" interval="3000" chance="20" range="7" radius="7" target="1" min="-500" max="-600">
            <attribute key="shootEffect" value="fire"/>
            <attribute key="areaEffect" value="firearea"/>
        </attack>
    </attacks>
    <defenses armor="100" defense="120">
        <defense name="healing" interval="2000" chance="10" min="900" max="1500">
            <attribute key="areaEffect" value="greenshimmer"/>
        </defense>
        <defense name="invisible" interval="4000" chance="20" duration="5000">
            <attribute key="areaEffect" value="blueshimmer"/>
        </defense>
    </defenses>
    <elements>
        <element firePercent="90"/>
        <element holyPercent="20"/>
    </elements>
    <immunities>
        <immunity earth="1"/>
        <immunity energy="1"/>
        <immunity lifedrain="1"/>
        <immunity paralyze="1"/>
        <immunity invisible="1"/>
    </immunities>
    <summons maxSummons="4">
        <summon name="Demon" interval="3000" chance="12"/>
    </summons>
    <voices interval="5000" chance="20">
        <voice sentence="NO ONE WILL STOP ME THIS TIME!" yell="1"/>
        <voice sentence="THE POWER IS MINE!" yell="1"/>
        <voice sentence="I returned from death and you dream about defeating me?"/>
        <voice sentence="Witness the first seconds of my eternal world domination!"/>
        <voice sentence="Even in my weakened state I will crush you all!"/>
    </voices>
    <loot>
        <item id="5903" chance="100000" unique="1"/>                <!-- ferumbras' hat -->
        <item id="2148" countmax="100" chance="98000"/>    <!-- gold coin -->
        <item id="2148" countmax="84" chance="98000"/>    <!-- gold coin -->
        <item id="9971" countmax="2" chance="75000"/>    <!-- gold ingot -->
        <item id="2522" chance="26000" unique="1"/>                <!-- great shield -->
        <item id="8903" chance="26000"/>                <!-- spellbook of lost souls -->
        <item id="2466" chance="24000"/>                <!-- golden armor -->
        <item id="2470" chance="22000"/>                <!-- golden legs -->
        <item id="8902" chance="22000"/>                <!-- spellbook of mind control -->
        <item id="8868" chance="22000"/>                <!-- velvet mantle -->
        <item id="2520" chance="20000"/>                <!-- demon shield -->
        <item id="8885" chance="20000"/>                <!-- divine plate -->
        <item id="7894" chance="20000"/>                <!-- magma legs -->
        <item id="2542" chance="20000"/>                <!-- tempest shield -->
        <item id="2127" chance="18000"/>                <!-- emerald bangle -->
        <item id="7896" chance="18000"/>                <!-- glacier kilt -->
        <item id="7895" chance="18000"/>                <!-- lightning legs -->
        <item id="2539" chance="18000"/>                <!-- phoenix shield -->
        <item id="8918" chance="18000"/>                <!-- spellbook of dark mysteries -->
        <item id="7885" chance="18000"/>                <!-- terra legs -->
        <item id="8930" chance="16000"/>                <!-- emerald sword -->
        <item id="7405" chance="16000"/>                <!-- havoc blade -->
        <item id="7451" chance="16000"/>                <!-- shadow sceptre -->
        <item id="2149" countmax="100" chance="16000"/>    <!-- gold ingot -->
        <item id="7632" countmax="5" chance="14000"/>    <!-- giant shimmering pearl -->
        <item id="7633" countmax="5" chance="14000"/>    <!-- giant shimmering pearl -->
        <item id="2472" chance="14000"/>                <!-- magic plate armor -->
        <item id="2514" chance="14000"/>                <!-- mastermind shield -->
        <item id="7417" chance="14000"/>                <!-- runed sword -->
        <item id="8904" chance="14000"/>                <!-- spellscroll of prophecies -->
        <item id="7427" chance="12000"/>                <!-- chaos mace -->
        <item id="8926" chance="12000"/>                <!-- demonwing axe -->
        <item id="8869" chance="12000"/>                <!-- greenwood coat -->
        <item id="2146" countmax="98" chance="12000"/>    <!-- small sapphire -->
        <item id="2143" countmax="88" chance="12000"/>    <!-- white pearl -->
        <item id="7407" chance="10000"/>                <!-- haunted blade -->
        <item id="8924" chance="10000"/>                <!-- hellforged axe -->
        <item id="7411" chance="10000"/>                <!-- ornamented axe -->
        <item id="2150" countmax="54" chance="10000"/>    <!-- small amethyst -->
        <item id="9970" countmax="87" chance="10000"/>    <!-- small topaz -->
        <item id="7382" chance="8000"/>                    <!-- demonrage sword -->
        <item id="7422" chance="8000"/>                    <!-- jade hammer -->
        <item id="2152" countmax="58" chance="8000"/>    <!-- platinum coin -->
        <item id="7423" chance="8000"/>                    <!-- skullcrusher -->
        <item id="5944" countmax="9" chance="8000"/>    <!-- soul orb -->
    </loot>
    <script>
            <event name="DodgeCritical"/>
    </script>
</monster>
 
Last edited:
Well, I tried several ways here and solved it my way, I don't know if it's the right way, but it's delivering more or less what I wanted.

change this:
Lua:
    local randvalue = math.random(0, 100000) / (getConfigInfo("rateLoot") * chance)
    if randvalue < lootBlock.chance then

to:
Code:
    local randvalue = math.random(0, 50000) / (getConfigInfo("rateLoot") * chance)   
    if randvalue > lootBlock.chance then
 
Back
Top