• 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 Npc system error

Azerty

Active Member
Joined
Apr 15, 2022
Messages
301
Solutions
4
Reaction score
31
Hi, does anyone know how to fix this error? I'm having trouble finding a solution

npc.JPG

npcHandler:

Lua:
    -- Calls the callback function represented by id for all modules added to this npchandler with the given arguments.
    function NpcHandler:processModuleCallback(id, ...)
        local ret = true
        for _, module in pairs(self.modules) do
            local tmpRet = true
            if id == CALLBACK_CREATURE_APPEAR and module.callbackOnCreatureAppear ~= nil then
                tmpRet = module:callbackOnCreatureAppear(...)
            elseif id == CALLBACK_CREATURE_DISAPPEAR and module.callbackOnCreatureDisappear ~= nil then
                tmpRet = module:callbackOnCreatureDisappear(...)
            elseif id == CALLBACK_CREATURE_SAY and module.callbackOnCreatureSay ~= nil then
                tmpRet = module:callbackOnCreatureSay(...)
            elseif id == CALLBACK_PLAYER_ENDTRADE and module.callbackOnPlayerEndTrade ~= nil then
                tmpRet = module:callbackOnPlayerEndTrade(...)
            elseif id == CALLBACK_PLAYER_CLOSECHANNEL and module.callbackOnPlayerCloseChannel ~= nil then
                tmpRet = module:callbackOnPlayerCloseChannel(...)
            elseif id == CALLBACK_ONBUY and module.callbackOnBuy ~= nil then
                tmpRet = module:callbackOnBuy(...)
            elseif id == CALLBACK_ONSELL and module.callbackOnSell ~= nil then
                tmpRet = module:callbackOnSell(...)  -- Line 270
            elseif id == CALLBACK_ONTRADEREQUEST and module.callbackOnTradeRequest ~= nil then
                tmpRet = module:callbackOnTradeRequest(...)
            elseif id == CALLBACK_ONADDFOCUS and module.callbackOnAddFocus ~= nil then
                tmpRet = module:callbackOnAddFocus(...)
            elseif id == CALLBACK_ONRELEASEFOCUS and module.callbackOnReleaseFocus ~= nil then
                tmpRet = module:callbackOnReleaseFocus(...)
            elseif id == CALLBACK_ONTHINK and module.callbackOnThink ~= nil then
                tmpRet = module:callbackOnThink(...)
            elseif id == CALLBACK_GREET and module.callbackOnGreet ~= nil then
                tmpRet = module:callbackOnGreet(...)
            elseif id == CALLBACK_FAREWELL and module.callbackOnFarewell ~= nil then
                tmpRet = module:callbackOnFarewell(...)
            elseif id == CALLBACK_MESSAGE_DEFAULT and module.callbackOnMessageDefault ~= nil then
                tmpRet = module:callbackOnMessageDefault(...)
            elseif id == CALLBACK_MODULE_RESET and module.callbackOnModuleReset ~= nil then
                tmpRet = module:callbackOnModuleReset(...)
            end
            if not tmpRet then
                ret = false
                break
            end
        end
        return ret
    end

Modules:
Lua:
    -- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
    function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreEquipped, _)
        local shopItem = self:getShopItem(itemid, subType)
        if shopItem == nil then
            error("[ShopModule.onSell] items[itemid] == nil")   --Line 1118
            return false
        end

        if shopItem.sell == -1 then
            error("[ShopModule.onSell] attempt to sell a non-sellable item")
            return false
        end

        local player = Player(cid)
        local parseInfo = {
            [TAG_PLAYERNAME] = player:getName(),
            [TAG_ITEMCOUNT] = amount,
            [TAG_TOTALCOST] = amount * shopItem.sell,
            [TAG_ITEMNAME] = shopItem.name
        }

        if not isItemFluidContainer(itemid) then
            subType = -1
        end

        if player:removeItem(itemid, amount, subType, ignoreEquipped) then
            local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
            player:addMoney(amount * shopItem.sell)
            self.npcHandler.talkStart[cid] = os.time()
            return true
        else
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            player:sendCancelMessage(msg)
            self.npcHandler.talkStart[cid] = os.time()
            return false
        end
    end
 
Back
Top