• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Adding values to loot drops

noshirtstan

New Member
Joined
Aug 2, 2020
Messages
68
Reaction score
2
Hey folks, Im trying to add additional values to select items via a global looting system. Having an issue trying to get it to work properly though.

Here is what I have:

LUA:
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
            self:addItem(t.items[i].id, count)
                if t.items[i].id == 26384 then
                    local rndm = math.random(50501, 50506)
                    local rndm2 = math.random(1, #craftingProfessionsConfig[rndm].skillRecipes)
        
                        item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, rndm) [B][I][COLOR=rgb(184, 49, 47)]-- LINE 39 ITEM ERROR[/COLOR][/I][/B]
            
                    if rndm == 50501 then
        
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(101, 110))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Blacksmithing Recipe")
                                
                
                    elseif rndm == 50502 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(201, 211))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Alchemy Recipe")               
                
                
                    elseif rndm == 50503 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(301, 310))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Inscription Recipe")                   
                
                    
                    elseif rndm == 50504 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(401, 410))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Tailoring Recipe")
                                
                    
                    elseif rndm == 50505 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(501, 510))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Leatherworking Recipe")
                            
                    
                    elseif rndm == 50506 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(601, 610))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Engineering Recipe")
                                
                    
                    end
                    
                return true
            end
        end
    end   
        
end

Here is the error I get when the monster dies and the loot drops:


1599701632329.png

Any thoughts?
 
1599702993131.png

Now im getting this error. It doesnt like the setAttribute value
Post automatically merged:

Here is the entirety of the code.

LUA:
local extra_loot = {
    {hasName = "dragon", items = {
            {id = 26384, count = 1, chance = 100000}, -- 100% chance
        }},
        {items = {
            {id = 26382, 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
            self:addItem(t.items[i].id, count)
                if t.items[i].id == 26384 then
                    local item = t.items
                    local rndm = math.random(50501, 50506)
        
                        item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, rndm)
            
                    if rndm == 50501 then
        
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(101, 110))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Blacksmithing Recipe")
                                
                
                    elseif rndm == 50502 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(201, 211))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Alchemy Recipe")               
                
                
                    elseif rndm == 50503 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(301, 310))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Inscription Recipe")                   
                
                    
                    elseif rndm == 50504 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(401, 410))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Tailoring Recipe")
                                
                    
                    elseif rndm == 50505 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(501, 510))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Leatherworking Recipe")
                            
                    
                    elseif rndm == 50506 then
                
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, math.random(601, 610))
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Engineering Recipe")
                                
                    
                    end
                    
                return true
            end
        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
Post automatically merged:

I figured it out.

Here is the code. Test and working perfectly.

LUA:
if math.random(0, 100000) <= t.items[i].chance then
            local rndm = math.random(50501, 50506)
            local rndm1 = math.random(101, 110)
            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
                        item:setAttribute(ITEM_ATTRIBUTE_TEXT, rndm1)
                        item:setAttribute(ITEM_ATTRIBUTE_NAME, "Blacksmithing Recipe")
                        return true
                    end
            return true
            end
        return true
        end
    return true
    end   
return true   
end
 
Last edited:
Back
Top