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

Error on Auto Bank Gold from Monster

ulaobr

New Member
Joined
Jun 11, 2021
Messages
3
Reaction score
0
Hello Guys, im having this error on my monster script(data/event/script/monster.lua), im a beginner in coding, so i was hoping that someone could help me.

the error that in having is this:

[error] Lua script error:
scriptInterface: [Event Interface]
scriptId: [data/events/scripts/monster.lua:Monster@onDropLoot]
timerEvent: []
callbackId:[]
function: []
error [data/events/scripts/monster.lua:23: attempt to index global 'itemType' (a nil value)
stack traceback:
[C]: in function '__index'
data/events/scripts/monster.lua:23: in function <data/events/scripts/monster.lua:1>]

Here are the two folders that i've changed monster.lua and container.lua.

Lua:
function Monster:onDropLoot(corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local currencies = {
        [3031] = 1,
        [3035] = 100,
        [3043] = 10000
    }

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    if not player or player:getStamina() > 840 then
        local currencyTransferAmount = 0
        
        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.')
            else
                if currencies[itemType:getId()] then
                    if player and player:isPremium() then
                        currencyTransferAmount = currencyTransferAmount + (item:getCount() * currencies[item:getType():getId()])
                        item:remove()
                    end
                end
            end
        end

        if player then
            if player:isPremium() and currencyTransferAmount > 0 then
                player:setBankBalance(player:getBankBalance() + currencyTransferAmount)
                player:sendTextMessage(MESSAGE_LOOT, "Premium: " .. currencyTransferAmount .. " gp was automatically looted and transferred to your bank account.")
            end
            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_LOOT, 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_LOOT, text)
        end
    end
end

function Monster:onSpawn(position)
    if self:getType():isRewardBoss() then
        self:setReward(true)
    end

    if self:getName():lower() == "cobra scout" or
        self:getName():lower() == "cobra vizier" or
        self:getName():lower() == "cobra assassin" then
        if getGlobalStorageValue(GlobalStorage.CobraBastionFlask) >= os.time() then
            self:setHealth(self:getMaxHealth() * 0.75)
        end
    end

    if not self:getType():canSpawn(position) then
        self:remove()
    else
        local spec = Game.getSpectators(position, false, false)
        for _, pid in pairs(spec) do
            local monster = Monster(pid)
            if monster and not monster:getType():canSpawn(position) then
                monster:remove()
            end
        end

        if self:getName():lower() == 'iron servant replica' then
            local chance = math.random(100)
            if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismDiamond) >= 1
            and Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismGolden) >= 1 then
                if chance > 30 then
                    local chance2 = math.random(2)
                    if chance2 == 1 then
                        Game.createMonster('diamond servant replica', self:getPosition(), false, true)
                    elseif chance2 == 2 then
                        Game.createMonster('golden servant replica', self:getPosition(), false, true)
                    end
                    self:remove()
                end
                return true
            end
            if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismDiamond) >= 1 then
                if chance > 30 then
                    Game.createMonster('diamond servant replica', self:getPosition(), false, true)
                    self:remove()
                end
            end
            if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismGolden) >= 1 then
                if chance > 30 then
                    Game.createMonster('golden servant replica', self:getPosition(), false, true)
                    self:remove()
                end
            end
            return true
        end
    end
end

Code:
function Container.isContainer(self)
    return true
end

function Container.createLootItem(self, item)
    if self:getEmptySlots() == 0 then
        return true
    end

    local itemCount = 0
    local randvalue = getLootRandom()
    local itemType = ItemType(item.itemId)
    
    if randvalue < item.chance then
        if itemType:isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

    while itemCount > 0 do
        local count = math.min(100, itemCount)
        
        local subType = count
        if itemType:isFluidContainer() then
            subType = math.max(0, item.subType)
        end
        
        local tmpItem = Game.createItem(item.itemId, subType)
        if not tmpItem then
            return false
        end

        if tmpItem:isContainer() then
            for i = 1, #item.childLoot do
                if not tmpItem:createLootItem(item.childLoot[i]) then
                    tmpItem:remove()
                    return false
                end
            end

            if #item.childLoot > 0 and tmpItem:getSize() == 0 then
                tmpItem:remove()
                return true
            end
        end

        if item.subType ~= -1 then
            tmpItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, item.subType)
        end

        if item.actionId ~= -1 then
            tmpItem:setActionId(item.actionId)
        end

        if item.text and item.text ~= "" then
            tmpItem:setText(item.text)
        end

        local ret = self:addItemEx(tmpItem)
        if ret ~= RETURNVALUE_NOERROR then
            tmpItem:remove()
        end

        itemCount = itemCount - count
    end
    return true
end
 
I didn't test, but in line 23 from monster.lua I think it should be "item" instead of itemType. You haven't declared itemType anywhere, and you already have the item object (created in line 19)
 
I didn't test, but in line 23 from monster.lua I think it should be "item" instead of itemType. You haven't declared itemType anywhere, and you already have the item object (created in line 19)
I’ve changed to item:getType():getId()] ~= nil then

But now shows another error in the same line(23): attempt to index local ‘item’ (a boolean value)
 
Back
Top