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

TFS 1.X+ Error script

ZeroSkyer

New Member
Joined
May 17, 2019
Messages
31
Reaction score
4
Location
EEUU
Hi, can someone help me with this script? The truth is that I do not know much, this script works I extracted it from an actionid but it is giving an error in the console and I think it is causing me lag. Thanks in advance

This is the error

error.png

Code:
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 item = corpse:createLootItem(monsterLoot[i])
            if item < 0 then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse. itemId: '..monsterLoot[i].itemId)
            else


                if item > 0 then
                    local tmpItem = Item(item)

                    -- Testing
                    local logic, contlogic, bplogica = 1, {}, {}
                    if getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) then
                        for i = 0, getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) do
                            contlogic[logic] = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
                            if isContainer(contlogic[logic].uid) then
                                bplogica[logic] = contlogic[logic]
                                logic = logic + 1
                            end
                        end
                    end

                    local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
                    if resultId then
                        local bp_id = result.getNumber(resultId, 'cont_id')
                    end

                    local slotgg
                    local localizou
                    for i = 1, #bplogica do
                        local tempitem = Item(bplogica[i].uid)
                        if tempitem:getId() == result.getNumber(resultId, 'cont_id') and localizou ~= 1 then
                            local bp = bplogica[i].uid
                            local freeSlotsInBp = math.max(0, getContainerCap(bp) - getContainerSize(bp))
                            if freeSlotsInBp and freeSlotsInBp > 0 then
                                slotgg = bplogica[i].uid
                                localizou = 1
                            end
                        end
                    end

                    local destination = Item(slotgg)
                    if player and player:getAutoLootItem(tmpItem:getId()) and configManager.getNumber(configKeys.AUTOLOOT_MODE) == 1 then
                        if destination then
                            tmpItem:moveTo(destination)
                            autolooted = string.format("%s, %s", autolooted, tmpItem:getNameDescription())
                        else
                            local withcap = tmpItem:moveTo(player)
                            autolooted = string.format("%s, %s", autolooted, tmpItem:getNameDescription())
                    end
                end
            end
        end
    end

        if player then
            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
                if autolooted ~= "" then
                    text = string.format("%s by %s", text, player:getName())
                end
                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 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
 
Solution
Starting at line 38 change:
Lua:
local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
if resultId then
    local bp_id = result.getNumber(resultId, 'cont_id')
end
To:
Lua:
if player then
    local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
    if resultId then
        local bp_id = result.getNumber(resultId, 'cont_id')
    end
end

jacqen

Well-Known Member
Joined
Jul 10, 2017
Messages
61
Solutions
15
Reaction score
61
Starting at line 38 change:
Lua:
local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
if resultId then
    local bp_id = result.getNumber(resultId, 'cont_id')
end
To:
Lua:
if player then
    local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
    if resultId then
        local bp_id = result.getNumber(resultId, 'cont_id')
    end
end
 
Solution
OP
OP
ZeroSkyer

ZeroSkyer

New Member
Joined
May 17, 2019
Messages
31
Reaction score
4
Location
EEUU
Starting at line 38 change:
Lua:
local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
if resultId then
    local bp_id = result.getNumber(resultId, 'cont_id')
end
To:
Lua:
if player then
    local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. getPlayerGUID(player) .. ' AND `item_id` = ' .. tmpItem:getId() .. '')
    if resultId then
        local bp_id = result.getNumber(resultId, 'cont_id')
    end
end
Thanks! It works well.
 
Top