• 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 FIX erro on autoloot

jel

Member
Joined
Mar 22, 2014
Messages
207
Reaction score
8
fix?
Lua:
function Monster:onDropLoot(corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local mType = self:getType()
    if mType:isRewardBoss() then
        corpse:registerReward()
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    local autolooted = ""
    
    if not player or player:getStamina() > 840 then
        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.')
            end
        end

        if player then
        local items = corpse:getItems()
            local autolooted = Game.createItem(1987, 1)

            for _, item in ipairs(items) do
                if (player:getAutoLootItem(item.itemid)) then
                    item:moveTo(autolooted)
                end
            end
            local text = ("Loot of %s: "):format(mType:getNameDescription())
            -- autoloot
            local lootMsg = corpse:getContentDescription()
            if autolooted ~= "" and corpse:getContentDescription() == "nothing" then
                lootMsg = autolooted:gsub(",", "", 1) .. " that was autolooted"
            elseif autolooted ~= "" then
                lootMsg = corpse:getContentDescription() .. " and " .. autolooted:gsub(",", "", 1) .. " was auto looted"
            end
            text = string.format("%s%s", text, lootMsg)

            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

    if configManager.getNumber(configKeys.AUTOLOOT_MODE) == 2 then
        corpse:setActionId(500)
    end
end

function Monster:onSpawn(position)
    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

Lua Script Error: [Event Interface]
data/events/scripts/monster.lua:[email protected]
data/events/scripts/monster.lua:38: attempt to call method 'gsub' (a nil value)
stack traceback:
[C]: in function 'gsub'
data/events/scripts/monster.lua:38: in function <data/events/scripts/monster.lua:1>
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
546
Location
Hell
Lua:
local autolooted = Game.createItem(1987, 1)

...

lootMsg = autolooted:gsub(",", "", 1) .. " that was autolooted"

Item has no method called gsub.
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
546
Location
Hell
what should i change?
EDIT:
Lua:
local lootMsg = corpse:getContentDescription()
local autoLootDescr = autolooted:getContentDescription()

if autolooted and autolooted:getItems() > 0 then
    if corpse:getContentDescription() == "nothing" then
        lootMsg = autoLootDescr:gsub(",", "", 1) .. " that was autolooted"
    else
        lootMsg = corpse:getContentDescription() .. " and " .. autoLootDescr:gsub(",", "", 1) .. " was auto looted"
    end
end
 
Last edited:
OP
J

jel

Member
Joined
Mar 22, 2014
Messages
207
Reaction score
8
EDIT:
Lua:
local lootMsg = corpse:getContentDescription()
local autoLootDescr = autolooted:getContentDescription()

if autolooted and autolooted:getItems() > 0 then
    if corpse:getContentDescription() == "nothing" then
        lootMsg = autoLootDescr:gsub(",", "", 1) .. " that was autolooted"
    else
        lootMsg = corpse:getContentDescription() .. " and " .. autoLootDescr:gsub(",", "", 1) .. " was auto looted"
    end
end
unsuccessfully, am trying to make these changes can help me?
autoloot

in my monsters.lua file
Lua:
function Monster:onDropLoot(corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local mType = self:getType()
    if mType:isRewardBoss() then
        corpse:registerReward()
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local autolooted = ""
    if not player or player:getStamina() > 840 then
        local monsterLoot = mType:getLoot()
        for i = 1, #monsterLoot do
            local boolCharm = false
            if player then
                local charmType = player:getCharmMonsterType(CHARM_GUT)
                if charmType and charmType:raceId() == mType:raceId() then
                    boolCharm = true
                end
            end
        
            local item = corpse:createLootItem(monsterLoot[i], boolCharm)
            if self:getName():lower() == (Game.getBoostedCreature()):lower() then
                local itemBoosted = corpse:createLootItem(monsterLoot[i], boolCharm)
            end
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
        end

        if player then
            local text = {}
            local oldClientText = ""
            local version = player:getClient().version
            if self:getName():lower() == (Game.getBoostedCreature()):lower() then
                 text = ("Loot of %s: %s (boosted loot)"):format(mType:getNameDescription(), corpse:getContentDescription())
                 if party or version < 1200 then
                    oldClientText = ("Loot of %s: %s (boosted loot)"):format(mType:getNameDescription(), corpse:getContentDescription(true))
                 end
            else
                 text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
                 if party or version < 1200 then
                    oldClientText = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription(true))
                 end           
            end
            
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text, oldClientText)
            else
                player:sendTextMessage(MESSAGE_LOOT, version >= 1200 and text or oldClientText)
                if version < 1200 then
                    player:sendTextMessage(MESSAGE_LOOT, oldClientText, 9)
                end
            end
            player:updateKillTracker(self, corpse)
        end
    else
        local text = ("Loot of %s: nothing (due to low stamina)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
        if autolooted ~= "" then
                    text = string.format("%s by %s", text, player:getName())
                end
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_LOOT, text)
        end
    end
    if configManager.getNumber(configKeys.AUTOLOOT_MODE) == 2 then
        corpse:setActionId(500)
    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
 
Top