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

modules.lua:1229: attempt to compare boolean with number

waxo

New Member
Joined
Nov 20, 2023
Messages
4
Reaction score
0
When trying to buy from any NPC and click too fast on buy an item many times, the user gets a message saying "You can't buy it so fast" and the console shows this error:
Code:
[Error - NpcScript Interface]
(Unknown script file)
Description:
data/npc/lib/npcsystem/modules.lua:1229: attempt to compare boolean with number
stack traceback:
    data/npc/lib/npcsystem/modules.lua:1229: in function 'callbackOnBuy'
    data/npc/lib/npcsystem/npchandler.lua:298: in function 'processModuleCallback'
    data/npc/lib/npcsystem/npchandler.lua:504: in function 'onBuy'
    data/npc/lib/npcsystem/modules.lua:1346: in function <data/npc/lib/npcsystem/modules.lua:1345>

Function 'callbackOnBuy' in modules.lua goes as follows (being the line 1229 the one comparing if(a < amount), line 44 here):
Lua:
function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
        local shopItem = nil
        for _, item in ipairs(self.npcHandler.shopItems) do
            if(item.id == itemid and item.subType == subType) then
                shopItem = item
                break
            end
        end

        if(shopItem == nil) then
            print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Item not found on shopItems list')
            return false
        end

        if(shopItem.buy == -1) then
            print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Attempt to purchase an item which only sellable')
            return false
        end

        if(amount <= 0) then
            print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onBuy - Attempt to purchase ' .. amount .. ' items')
            return false
        end

        local subType, count = shopItem.subType or 0, amount
        local backpack, backpackPrice, totalCost = 1988, 20, amount * shopItem.buy
        if(inBackpacks) then
            totalCost = totalCost + (math.max(1, math.floor(count / getContainerCapById(backpack))) * backpackPrice)
        end

        local parseInfo = {
            [TAG_PLAYERNAME] = getPlayerName(cid),
            [TAG_ITEMCOUNT] = amount,
            [TAG_TOTALCOST] = totalCost,
            [TAG_ITEMNAME] = shopItem.name
        }
        if(getPlayerMoney(cid) < totalCost) then
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
            doPlayerSendCancel(cid, self.npcHandler:parseMessage(msg, parseInfo))
            return false
        end

        local a, b = doNpcSellItem(cid, itemid, count, subType, ignoreCap, inBackpacks, backpack)
        if(a < amount) then
            local msgId = MESSAGE_NEEDMORESPACE
            if(a == 0) then
                msgId = MESSAGE_NEEDSPACE
            end

            local msg = self.npcHandler:getMessage(msgId)
            parseInfo[TAG_ITEMCOUNT] = a

            doPlayerSendCancel(cid, self.npcHandler:parseMessage(msg, parseInfo))
            if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
                self.npcHandler.talkStart[cid] = os.time()
            else
                self.npcHandler.talkStart = os.time()
            end

            if(a > 0) then
                doPlayerRemoveMoney(cid, ((a * shopItem.buy) + (b * backpackPrice)))
                return true
            end

            return false
        end

        local msg = self.npcHandler:getMessage(MESSAGE_BOUGHT)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, self.npcHandler:parseMessage(msg, parseInfo))

        doPlayerRemoveMoney(cid, totalCost)
        if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
            self.npcHandler.talkStart[cid] = os.time()
        else
            self.npcHandler.talkStart = os.time()
        end

        return true
    end

I guess the boolean is a, being amount the number, but can't understand why this only happens when buying too fast.
 
Back
Top