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

Multiple shopModules

OperatorMopa

Member
Joined
Feb 10, 2014
Messages
127
Reaction score
6
Hello guys :)
Is there any way to make few shopModules for one npc?
Instead of making 2 npc i wonder if its possible to make a shop which shows different items for knights and different for sorcerers.
 
I propably understand something wrong.
Ofc i can check storage in requestTrade, but what would it give to me if buyable items are loaded when the npc is created. How can i change the item price in requestTrade ? it just loads shopItems table which is created with npc.

The only problem in @HalfAway idea is that i would have to remake all npcs
You change that:

Code:
for i = 1, #module.npcHandler.shopItems do
       table.insert(itemWindow, module.npcHandler.shopItems[i])
     end

To that:

Code:
for i = 1, #module.npcHandler.shopItems do
    local index = #itemWindow
    itemWindow[index+1] = table.copy(module.npcHandler.shopItems[i])
    local player = Player(cid)
    if itemWindow[index+1].buy > 0 and player then
        itemWindow[index+1].buy = 100 -- whatever you want here with player
    end
end

Here is table.copy:
Code:
function table.copy(tab)
    local ret = {}
    for i, v in pairs(tab) do
        if type(v) == "table" then
            ret[i] = table.copy(v)
        else
            ret[i] = v
        end
    end
    return ret
end

Ideally you would only do that when you have to change the price so you would put an if to check if it has or not to change it to avoid copying too many tables. (It will get collected anyway but if you can avoid it why not)
 
It works !
Thanks @MatheusMkalo you saved me a lot of time.
I still need to learn so much :)

EDIT.
To make it work you also need to change callbackOnBuy to consume correct ammount of money
 
Last edited:
It works !
Thanks @MatheusMkalo you saved me a lot of time.
I still need to learn so much :)

EDIT.
To make it work you also need to change callbackOnBuy to consume correct ammount of money
True, forgot to mention that. (as the first post was just about displaying different offers to each vocation not about changing the price)

Edit: Maybe for the prices you could edit the functions on npc system to check if the price is a function or a number and if its a function use it as a callback to get the price. Something like

Code:
local function priceCallback(cid, itemid) -- you could add more here
    local player = Player(cid)
    if player and player:getVocation():getId() == 1 then
        return 10
    else
        return 20
    end
end

and then:

shopModule:addBuyableItem({'spellbook'}, 2175, priceCallback, 'spellbook')

And inside requestTrade and onBuy/onSell you would call the function with cid and itemid to get the price.
 
Last edited:
True, forgot to mention that. (as the first post was just about displaying different offers to each vocation not about changing the price)

Edit: Maybe for the prices you could edit the functions on npc system to check if the price is a function or a number and if its a function use it as a callback to get the price.
I've done it by changing totalCost in callbackOnBuy by adding same restrictions as in requestTrade - easy way :)
 
Back
Top