Using TFS 1.2
Cannot figure out how to make it so an NPC can sell more than 100 of an item. Here is the "doNpcSellItem" function from my npc.lua:
As you can see, I had added some prints in there as a sanity check to make sure that was the function being used.
After changing the "maxCount" variable in modules.lua
I can go to an NPC and say "buy 200 mana potions", and the NPC replies with the correct amount:
However, my output in the game console from the prints above is this:
And the NPC only gives me 100 mana potions. So the NPC is successfully getting the correct input of 200, but somewhere the output is capped at 100 and I cannot figure out why. Is this a problem with the function "Player(cid):addItemEx"?
Thanks in advance, please let me know if there are any other bits of code that need to be included.
Cannot figure out how to make it so an NPC can sell more than 100 of an item. Here is the "doNpcSellItem" function from my npc.lua:
Lua:
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
local amount = amount or 1
local subType = subType or 0
local item = 0
if ItemType(itemid):isStackable() then
if inBackpacks then
stuff = Game.createItem(backpack, 1)
item = stuff:addItem(itemid, math.min(100, amount))
else
stuff = Game.createItem(itemid, math.min(100, amount))
end
print(stuff)
print(amount)
print(itemid)
return Player(cid):addItemEx(stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0
end
local a = 0
if inBackpacks then
local container, b = Game.createItem(backpack, 1), 1
for i = 1, amount do
local item = container:addItem(itemid, subType)
if table.contains({(ItemType(backpack):getCapacity() * b), amount}, i) then
if Player(cid):addItemEx(container, ignoreCap) ~= RETURNVALUE_NOERROR then
b = b - 1
break
end
a = i
if amount > i then
container = Game.createItem(backpack, 1)
b = b + 1
end
end
end
return a, b
end
for i = 1, amount do -- normal method for non-stackable items
local item = Game.createItem(itemid, subType)
if Player(cid):addItemEx(item, ignoreCap) ~= RETURNVALUE_NOERROR then
break
end
a = i
end
return a, 0
end
As you can see, I had added some prints in there as a sanity check to make sure that was the function being used.
After changing the "maxCount" variable in modules.lua
Lua:
ShopModule = {
npcHandler = nil,
yesNode = nil,
noNode = nil,
noText = "",
maxCount = 500,
amount = 0
}
I can go to an NPC and say "buy 200 mana potions", and the NPC replies with the correct amount:
Code:
17:24 Test Player: buy 200 mana potion
17:24 Simon: Do you want to buy 200 mana potion for 15000 gold coins?
17:24 Test Player: yes
However, my output in the game console from the prints above is this:
Code:
userdata: 0x403189b8
100
5423
And the NPC only gives me 100 mana potions. So the NPC is successfully getting the correct input of 200, but somewhere the output is capped at 100 and I cannot figure out why. Is this a problem with the function "Player(cid):addItemEx"?
Thanks in advance, please let me know if there are any other bits of code that need to be included.