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

Lua Extra Loot script not dropping second item.

noshirtstan

New Member
Joined
Aug 2, 2020
Messages
68
Reaction score
2
Hey folks,

So my extra loot script won't drop the second item in the table.

Here is my code:

Lua:
local extra_loot = {
    {hasName = "odibrand", items = {
            {id = 26448, count = 10, chance = 100000, storage = 1, aid = 1}, -- 100% chance
        }},
        {items = {
            {id = 26384, count = 1, chance = 100000, storage = 1, aid = 1},            -- 5% chance to drop common recipe
            {id = 2160, count = 1, chance = 100000}
        }},
    }
    
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, titems[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 -- 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
                    
                    if rndm == 50502 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm2)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Alchemy Recipe")
                        return true
                    end
                    
                    if rndm == 50503 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm3)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Inscription Recipe")
                        return true
                    end
                    
                    if rndm == 50504 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm4)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Tailoring Recipe")
                        return true
                    end
                    
                    if rndm == 50505 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm5)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Leatherworking Recipe")
                        return true
                    end
                    
                    if rndm == 50506 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm6)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Engineering Recipe")
                        return true
                    end
            return true
            end
        return true
        end
    return true
    end   
return true   
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

Any thoughts?

TFS 1.3
 
@noshirtstan

This function is calling corpse:addExtraLoot(creature, extra_loot[i]
Lua:
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

Change it to:
Lua:
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
            Container:addExtraLoot(creature, extra_loot[i])
        end
    end
    return true
end

This is the first I can find in your code since there is nothing like corpse:addExtraLoot specified in your script.

Sincerely,
Ralumbi
 
bump
Post automatically merged:

The script has been edited but it still not working correctly, it will drop the first item in the list but not the second.

Lua:
local extra_loot = {
    {hasName = "dragon", items = {
            {id = 26448, count = 1, chance = 100000, storage = 1, aid = 1}, -- 100% chance
            {id = 2160, count = 1, chance = 100000}
        }},
        {items = {
            {id = 26384, count = 1, chance = 100000, storage = 1, aid = 1},            -- 5% chance to drop common recipe
            {id = 2160, count = 1, chance = 100000}
        }},
    }
    
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, titems[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 -- Common Recipe Formula
            local rndm = math.random(50501, 50501)
            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 then
                            item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(901, 906))
                            item:setAttribute(ITEM_ATTRIBUTE_NAME, "Boss Blacksmithing Recipe")
                            return true
                        end
                    end
                    
                    if rndm == 50502 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm2)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Alchemy Recipe")
                        return true
                    end
                    
                    if rndm == 50503 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm3)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Inscription Recipe")
                        return true
                    end
                    
                    if rndm == 50504 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm4)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Tailoring Recipe")
                        return true
                    end
                    
                    if rndm == 50505 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm5)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Leatherworking Recipe")
                        return true
                    end
                    
                    if rndm == 50506 then
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm6)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Common Engineering Recipe")
                        return true
                    end
            return true
            else
                self:addItem(t.items[i], count)
            return true
            end
            return true
            end
        return true
        end
    return true
    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
 
Last edited:
You need to tell people what the code is supposed to do man. This is a mess and i doubt it worked at all. I tried to put something together based on what you had.

Lua:
local professionType = {
    [50501] = {type = "Blacksmithing Recipe", items = {
        [26384] = {name = "Common", rand = {101, 110}},
        [26447] = {name = "Rare", rand = {101, 110}},
        [26448] = {name = "Boss", rand = {901, 906}}
        }},
    [50502] = {type = "Alchemy Recipe", items = {
        [26384] = {name = "Common", rand = {101, 110}},
        [26447] = {name = "Rare", rand = {101, 110}},
        [26448] = {name = "Boss", rand = {901, 906}}
        }},
    [50503] = {type = "Inscription Recipe", items = {
        [26384] = {name = "Common", rand = {101, 110}},
        [26447] = {name = "Rare", rand = {101, 110}},
        [26448] = {name = "Boss", rand = {901, 906}}
        }},
    [50504] = {type = "Tailoring Recipe", items = {
        [26384] = {name = "Common", rand = {101, 110}},
        [26447] = {name = "Rare", rand = {101, 110}},
        [26448] = {name = "Boss", rand = {901, 906}}
        }},
    [50505] = {type = "Leatherworking Recipe", items = {
        [26384] = {name = "Common", rand = {101, 110}},
        [26447] = {name = "Rare", rand = {101, 110}},
        [26448] = {name = "Boss", rand = {901, 906}}
        }},
    [50506] = {type = "Engineering Recipe", items = {
        [26384] = {name = "Common", rand = {101, 110}},
        [26447] = {name = "Rare", rand = {101, 110}},
        [26448] = {name = "Boss", rand = {901, 906}}
        }
    }
}

local lootTable = {
    [1] = {droppedBy = {"odibrand"}, items = {
        [1] = {itemid = 26448, count = 10, chance = 100000}
    }},
    [2] = {items = {
        [1] = {itemid = 26384, count = 1, chance = 10000},
        [1] = {itemid = 2160, count = 1, chance = 10000}
    }}
}

function Container:addExtraLoot(creature, loot)
    local continue = false
    if loot.droppedBy then
        for i = 1, #loot.droppedBy do
            if creature:getName():lower() == loot.droppedBy[i]:lower() then
                continue = true
                break
            end
        end
    end
    
    if not continue then return true end
    
    for i = 1, #loot.items do
        if math.random(1, 100000) <= loot.items[i].chance then
            local randProfession = math.random(50501, 50506)
            local professionName = professionType[randProfession]
            local rarity = professionName[loot.items[i].itemid]
            
            local item = self:addItem(loot.items[i].itemid, math.random(1, loot.items[i].count))
            item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, randProfession)
            if professionName and rarity then
                item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(rarity.rand[1], rarity.rand[2]))
                item:setAttribute(ITEM_ATTRIBUTE_NAME, rarity.name.." "..professionName.type)
            end
        end
    end
return true   
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, #lootTable do
            corpse:addExtraLoot(creature, lootTable[i])
        end
    end
    return true
end
 
Back
Top