• 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+ Problem buying and selling NPCs

Dries390

Well-Known Member
Joined
Sep 8, 2007
Messages
91
Solutions
4
Reaction score
70
My NPC has the following luascript:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:onThink()           end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addSellableItem({'phoenix egg'}, 11400, 10000, 'phoenix egg')
shopModule:addSellableItem({'egg'}, 2695, 10, 'egg')
shopModule:addSellableItem({'hydra egg'}, 4850, 2000, 'hydra egg')
shopModule:addSellableItem({'tortoise egg'}, 5678, 250, 'tortoise egg')
shopModule:addSellableItem({'terramite egg'}, 11370, 50, 'terramite egg')
shopModule:addSellableItem({'tarantula egg'}, 11198, 75, 'tarantula egg')
shopModule:addSellableItem({'egg of the many'}, 10523, 3750, 'egg of the many')
shopModule:addSellableItem({'carniphila seeds'}, 11217, 175, 'carniphila seeds')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, "Calene") then
        selfSay("I just love animals, that's why I set up this {shelter}.",cid)
        selfSay("Just thinking about all the sad lonely creatures out there...",cid)
        selfSay("It's almost too much to bear.",cid)
        
    elseif(msgcontains(msg, "quest") or msgcontains(msg, "job") or msgcontains(msg, "mission"))  then
        selfSay("I'll have something to do for you later.",cid)
        
    elseif msgcontains(msg, "shelter")  then
        selfSay("These animals are my children.",cid)
    
    else
        selfSay("I don't know anything about that subject, sorry.", cid)
        
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

On trying to sell eggs the error included occurs but the other items sell fine. Even worse; none of my NPCs seem capable of selling items (also included).

I'm using Nekiro's TFS 1.3 for Tibia 8.60 with Delusion's Item abilities via lua.

Any help would be greatly appreciated :)
 

Attachments

Tiny update on the issue:

-I've tried adding other stackable (food items) such as dragon ham and meat. They are all perfectly sellable. As far as I know only an egg (id: 2695) gives an error. Eggs generated via /i 2695 function perfectly normal in all other regards.

-Items are buyable and sellable via talk-actions i.e. (buy X or sell Y), even eggs.

-Adding items to npc.xml results in the same, unbuyable, state as shown above. The slider cannot be moved from 0.
 
Last edited:
I think you are using corrupted npc module or this npc isn’t for 1.3 so if this npc is for 1.3 then try clean module for npc ( change your npcsystem with clean tfs 1.3 one idk if nekiro did changes in this file )
 
As far as I know items.xml has 2 egg ids, Can you try with this one?
2328 and see if you can sell/buy?
 
maybe your problem is in lib
data/npc/lib/npc/npcsystem >npchandler.lua:

below

Code:
CALLBACK_ONSELL = 11

add


CALLBACK_ONTRADEREQUEST = 15


search:

Code:
elseif(id == CALLBACK_FAREWELL and module.callbackOnFarewell ~= nil) then
    tmpRet = module:callbackOnFarewell(unpack(arg))

add below


Code:
elseif id == CALLBACK_ONTRADEREQUEST and module.callbackOnTradeRequest ~= nil then
    tmpRet = module:callbackOnTradeRequest(unpack(arg))


find the function NpcHandler: onSell (if the function has some differences from what I put below, without despair, inspire, exhale and follow):

Code:
function NpcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
  local callback = self:getCallback(CALLBACK_ONSELL)
  if(callback == nil or callback(cid, itemid, subType, amount, ignoreCap, inBackpacks)) then
    if(self:processModuleCallback(CALLBACK_ONSELL, cid, itemid, subType, amount, ignoreCap, inBackpacks)) then
      --
    end
  end
end



Add below:



Code:
function NpcHandler:onTradeRequest(cid)
  local callback = self:getCallback(CALLBACK_ONTRADEREQUEST)
  if callback == nil or callback(cid) then
    if self:processModuleCallback(CALLBACK_ONTRADEREQUEST, cid) then
      return true
    end
  end
  return false
end

now in data/npc/lib/npc/npcsystem >modules.lua

search for


Code:
function ShopModule.requestTrade(cid, message, keywords, parameters, node)
  local module = parameters.module
  if(not module.npcHandler:isFocused(cid)) then
    return false
  end

add below:


Code:
if not module.npcHandler:onTradeRequest(cid) then
    return false
end



Then look for:


Code:
function ShopModule.tradeItem(cid, message, keywords, parameters, node)
  local module = parameters.module
  if(not module.npcHandler:isFocused(cid)) then
    return false
  end

addbelow


Code:
if not module.npcHandler:onTradeRequest(cid) then
    return true
end



maybe this setting will help you resume your callback
 
As far as I know items.xml has 2 egg ids, Can you try with this one?
2328 and see if you can sell/buy?
@Dries390
Make sure you have another duplicate item with different id but same sprite, this may conflict with npc.
look in item editor, and object builder.

Looks like you guys might have been on to something. Guess I'll remove the second egg and just make the first one edible.

Edit: Eggs now functions -and- are sellable. Forgot to add that I added both egg IDs to the NPC and 2328/2695 registered as both for some reason. I just really hope this doesn't lead to problems with custom items down the line. Thanks to all of you! If anyone has any suggestions as to why I can't buy items that'd also be extremely appreciated!
 

Attachments

Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()         npcHandler:onThink()           end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addSellableItem({'meat'}, 2666, 3, 'meat')
shopModule:addSellableItem({'dragon ham'}, 2672, 10, 'dragon ham')
shopModule:addSellableItem({'phoenix egg'}, 11400, 10000, 'phoenix egg')
shopModule:addSellableItem({'egg'}, 2328, 10, 'egg')
shopModule:addSellableItem({'hydra egg'}, 4850, 2000, 'hydra egg')
shopModule:addSellableItem({'tortoise egg'}, 5678, 250, 'tortoise egg')
shopModule:addSellableItem({'terramite egg'}, 11370, 50, 'terramite egg')
shopModule:addSellableItem({'tarantula egg'}, 11198, 75, 'tarantula egg')
shopModule:addSellableItem({'egg of the many'}, 10523, 3750, 'egg of the many')
shopModule:addSellableItem({'carniphila seeds'}, 11217, 175, 'carniphila seeds')

shopModule:addBuyableItem({'phoenix egg'}, 11400, 100, 1, 'phoenix egg')


function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, "Calene") then
        selfSay("I just love animals, that's why I set up this {shelter}.",cid)
        selfSay("Just thinking about all the sad lonely creatures out there...",cid)
        selfSay("It's almost too much to bear.",cid)
        
    elseif(msgcontains(msg, "quest") or msgcontains(msg, "job") or msgcontains(msg, "mission"))  then
        selfSay("I'll have something to do for you later.",cid)
        
    elseif msgcontains(msg, "shelter")  then
        selfSay("These animals are my children.",cid)
    
    else
        selfSay("I don't know anything about that subject, sorry.", cid)
        
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I've tried all the obvious stuff, removing/adding the '1' for amount, switching sellable/buyable code around etc. There's no errors printed in the console.
 

Attachments

You are trying with GM account? If yes then use a normal player and retry.
 
Solution
You my friend, are brilliant. I never had any problems with this before I upgraded, hadn't even considered that GMs can't buy items. Thank you!
 

Attachments

Back
Top