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

CreatureEvent [TFS 1.1] Extra loot system

Ok, ty. Good night !
Tested it on my server TFS 1.1, I just changed this part:
Code:
if corpse and corpse:isContainer() then
    for i = 1, #extra_loot do
        corpse:addExtraLoot(creature, extra_loot[i])
    end
end
To:
Code:
if ((corpse > 0) and (Container(corpse):isContainer())) then
    for i = 1, #extra_loot do
        Container(corpse):addExtraLoot(creature, extra_loot[i])
    end
end

Full:
Code:
local extra_loot = {
    {hasName = "dragon", items = {
        {id = 2152, count = 2, chance = 40000}, -- 40%
        {id = 2160, countMax = 4, chance = 100000}
    }},
    {items = {
        {id = 2365, chance = 10000},
        {id = 2392, chance = 1000}
    }},
}

function Container:addExtraLoot(c, t)
    if t.hasName then
        local cn = c:getName():lower()
        local cm = t.hasName:lower()
        if not cn:match(cm) then
            return true
        end
    end
   
    for i = 1, #t.items do
        local count = 1
        if t.items[i].count then
            if t.items[i].countMax then
                count = math.random(t.items[i].count, t.items[i].countMax)
            else
                count = t.items[i].count
            end
        else
            if t.items[i].countMax then
                count = math.random(1, t.items[i].countMax)
            end
        end
       
        if math.random(0, 100000) <= t.items[i].chance then
            self:addItem(t.items[i].id, count)
        end
    end
end

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if not creature:isMonster() then return true end
    if ((corpse > 0) and (Container(corpse):isContainer())) then
        for i = 1, #extra_loot do
            Container(corpse):addExtraLoot(creature, extra_loot[i])
        end
    end
    return true
end
 
isContainer is only an ItemType method in TFS 1.2.
Perhaps this will work.
Code:
if corpse and Container(corpse) then
@bradette19
 
Code:
local extra_loot = {
    --{hasName = "dragon", items = {
        --{id = 2152, count = 2, chance = 40000}, -- 40%
        --{id = 2160, countMax = 4, chance = 10000}
    --}},
    {items = {
        {id = 8300, chance = 200}
    }},
}

function Container:addExtraLoot(c, t)
    if t.hasName then
        local cn = c:getName():lower()
        local cm = t.hasName:lower()
        if not cn:match(cm) then
            return true
        end
    end
  
    for i = 1, #t.items do
        local count = 1
        if t.items[i].count then
            if t.items[i].countMax then
                count = math.random(t.items[i].count, t.items[i].countMax)
            else
                count = t.items[i].count
            end
        else
            if t.items[i].countMax then
                count = math.random(1, t.items[i].countMax)
            end
        end
      
        if math.random(0, 100000) <= t.items[i].chance then
            self:addItem(t.items[i].id, count)
        end
    end
end

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if not creature:isMonster() then return true end
    if ((corpse > 0) and (Container(corpse):if corpse and Container(corpse) then())) then
        for i = 1, #extra_loot do
            Container(corpse):addExtraLoot(creature, extra_loot[i])
        end
    end
    return true
end

Still get error :S

 
@bradette19
replace
Code:
if ((corpse > 0) and (Container(corpse):if corpse and Container(corpse) then())) then
with just
Code:
if corpse and Container(corpse) then
 
With this script, does it have to have the full name Dragon or simply the sequence? If I named a mob Dragonling, would it fall under the "dragon" config? Or would it have to be "Dragon Ling" "Dragon Lord" etc?
 
I've done all the last steps, but I still have that same error, is there any solution?

I'm using 1.2.
 
I have the same problem as Blasphemy, using 1.2.
Any other tips?

Got it working with some changes:

Code:
math.randomseed(os.time())
local extra_loot = {
    {hasName = "dragon", items = {
        {id = 2152, count = 1, countMax = 2,chance = 90000}, -- 40%
        {id = 2160, countMax = 1, chance = 10000} -- 10%
    }},
    {items = {
        {id = 2365, chance = 90000},
        {id = 2392, chance = 1000}
    }},

    {hasName = "war wolf", items = {
        {id = 2152, count = 2, chance = 40000}, -- 40%
        {id = 2160, countMax = 4, chance = 10000}
    }},
    {items = {
        {id = 2365, chance = 10000},
        {id = 2392, chance = 1000}
    }},
}

function Container:addExtraLoot(c, t)
    if t.hasName then
        local cn = c:getName():lower()
        local cm = t.hasName:lower()
        if not cn:match(cm) then
            return true
        end
    end
   
    for i = 1, #t.items do
        local count = 1
        if t.items[i].count then
            if t.items[i].countMax then
                count = math.random(t.items[i].count, t.items[i].countMax)
            else
                count = t.items[i].count
            end
        else
            if t.items[i].countMax then
                count = math.random(1, t.items[i].countMax)
            end
        end
       
        if math.random(0, 100000) <= t.items[i].chance then
            self:addItem(t.items[i].id, count)
        end
    end
end

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if not creature:isMonster() then
    return true
    end

        if creature:getMaster() then
        return true
        end
           
            if corpse then
            local itemType = corpse:getType()
            if itemType:isCorpse() and itemType:isContainer() then
            for i = 1, #extra_loot do
            corpse:addExtraLoot(creature, extra_loot[i])
            end
       
        end
    return true
end
end
 
Last edited:
Hello guys,

Anyone using this on OTX?

Getting these errors paired with Ultimate Item Stat.

Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/stats.lua:2173: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/stats.lua:2173: in function 'improveChance'
        data/stats.lua:2247: in function <data/stats.lua:2222>

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/extra_loot.lua:onDeath
data/creaturescripts/scripts/extra_loot.lua:47: attempt to call method 'isContainer' (a nil value)
stack traceback:
        [C]: in function 'isContainer'
        data/creaturescripts/scripts/extra_loot.lua:47: in function <data/creaturescripts/scripts/extra_loot.lua:45>

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/extra_loot.lua:onDeath
data/creaturescripts/scripts/extra_loot.lua:47: attempt to call method 'isContainer' (a nil value)
stack traceback:
        [C]: in function 'isContainer'
        data/creaturescripts/scripts/extra_loot.lua:47: in function <data/creaturescripts/scripts/extra_loot.lua:45>

Anyone have any ideas? :)
Tryed the possible solutions posted before in this thread with no result.
 
sorry to revive the topic, but is there a possibility to modify this system so that it identifies and separates items by rarity?


Lua:
local extra_loot = {
    {hasName = "dragon", items = {
        {id = 2152, count = 2, chance = 40000}, -- Common
        {id = 2160, countMax = 4, chance = 10000} -- Rare
    }},
    {items = {
        {id = 2365, chance = 10000}, -- Epic
        {id = 2392, chance = 1000} -- Lendary
    }},
}

function Container:addExtraLoot(c, t)
    if t.hasName then
        local cn = c:getName():lower()
        local cm = t.hasName:lower()
        if not cn:match(cm) then
            return true
        end
    end
    
    for i = 1, #t.items do
        local count = 1
        if t.items[i].count then
            if t.items[i].countMax then
                count = math.random(t.items[i].count, t.items[i].countMax)
            else
                count = t.items[i].count
            end
        else
            if t.items[i].countMax then
                count = math.random(1, t.items[i].countMax)
            end
        end
        
        if math.random(0, 100000) <= t.items[i].chance then
            self:addItem(t.items[i].id, count)
        end
    end
end

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if not creature:isMonster() then return true end
    if corpse and corpse:isContainer() then
        for i = 1, #extra_loot do
            corpse:addExtraLoot(creature, extra_loot[i])
        end
    end
    return true
end

}

and when the item drops according to its rarity the player receives a default message!!
 
sorry to revive the topic, but is there a possibility to modify this system so that it identifies and separates items by rarity?


Lua:
local extra_loot = {
    {hasName = "dragon", items = {
        {id = 2152, count = 2, chance = 40000}, -- Common
        {id = 2160, countMax = 4, chance = 10000} -- Rare
    }},
    {items = {
        {id = 2365, chance = 10000}, -- Epic
        {id = 2392, chance = 1000} -- Lendary
    }},
}

function Container:addExtraLoot(c, t)
    if t.hasName then
        local cn = c:getName():lower()
        local cm = t.hasName:lower()
        if not cn:match(cm) then
            return true
        end
    end
   
    for i = 1, #t.items do
        local count = 1
        if t.items[i].count then
            if t.items[i].countMax then
                count = math.random(t.items[i].count, t.items[i].countMax)
            else
                count = t.items[i].count
            end
        else
            if t.items[i].countMax then
                count = math.random(1, t.items[i].countMax)
            end
        end
       
        if math.random(0, 100000) <= t.items[i].chance then
            self:addItem(t.items[i].id, count)
        end
    end
end

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if not creature:isMonster() then return true end
    if corpse and corpse:isContainer() then
        for i = 1, #extra_loot do
            corpse:addExtraLoot(creature, extra_loot[i])
        end
    end
    return true
end

}

and when the item drops according to its rarity the player receives a default message!!


I did it in the drop portion by changing it up a bit. Try a format like this:

Lua:
if math.random(0, 100000) <= t.items[i].chance then -- Common Recipe Formula
            local rndm = math.random(50501, 50506)
            local rndm1 = math.random(101, 110)
            local rndm2 = math.random(201, 211)
            local rndm3 = math.random(301, 310)
            local rndm4 = math.random(401, 410)
            local rndm5 = math.random(501, 510)
            local rndm6 = math.random(601, 610)
            local item = self:addItem(t.items[i].id, count)
            if t.items[i].storage and t.items[i].aid then
                item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, rndm)
                
                    if rndm == 50501 then
                        if t.items[i].id == 26384 then
                            item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm1)
                            item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Blacksmithing Recipe")
                            return true
                        elseif t.items[i].id == 26447 then
                            item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm1)
                            item:setAttribute(ITEM_ATTRIBUTE_NAME, "Rare Blacksmithing Recipe")
                            return true
                        elseif t.items[i].id == 26448 and t.items[i].hasName == "odibrand" then
                            item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(901, 906))
                            item:setAttribute(ITEM_ATTRIBUTE_NAME, "Boss Blacksmithing Recipe")
                            return true
                        end
                    end
 
Anyone can help me? I use otx 10.98

Lua:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/extra_loot.lua:onDeath
data/creaturescripts/scripts/extra_loot.lua:78: attempt to compare number with userdata
stack traceback:
        [C]: in function '__lt'
        data/creaturescripts/scripts/extra_loot.lua:78: in function <data/creaturescripts/scripts/extra_loot.lua:76>
 
Last edited:
Back
Top