forgottenserver icon indicating copy to clipboard operation
forgottenserver copied to clipboard

sell Items with subtype [2 bugs]

Open GoularPink opened this issue 6 years ago • 9 comments

Bug 1: How is it: The vials that have subtype are appearing to sell in npc, but when we click to sell, npc says that we do not have the item.

Fix would be: Or do not show these items or be able to sell them.

Print: https://imgur.com/vR7fhTT

script inside some seller/buyer npc: <parameter key="shop_sellable" value="Spellwand,7735,299; Vial,2006,5" />

Bug 2: How it is: The item appears in npc for sell, but we don't have any items in our backpack

print: http://prntscr.com/k2vuow

script: <?xml version="1.0" encoding="UTF-8"?> <npc name="Satsu" script="Satsu.lua" walkinterval="2000" floorchange="0"> <health now="100" max="100" /> <look type="158" head="78" body="96" legs="118" feet="96" addons="0" /> <parameters> <parameter key="module_shop" value="1" /> <parameter key="shop_buyable" value=" wine,2006,10,15; cocktail glass of beer,10150,52,3; cocktail glass of fruit juice,10150,52,21; cocktail glass of lemonade,10150,52,5; cocktail glass of mead,10150,52,43; cocktail glass of milk,10150,52,6; cocktail glass of rum,10150,52,27; cocktail glass of tea,10150,52,35; cocktail glass of water,10150,52,1; cocktail glass of wine,10150,52,15;" /> <parameter key="shop_sellable" value="cocktail glass,10150,50;" /> </parameters> </npc>

GoularPink avatar Jul 05 '18 13:07 GoularPink

can confirm this. The error is in npc buy/sell module, I don't recall exactly but it checks for specific type if it's given, otherwise it only buys for type = 0

Another bug is that if you put a golden cup in a monster's drop, it will drop with type = 1 (water). When you try to sell to the npc, since the golden cup isn't empty, it will say you don't have the item.

andersonfaaria avatar Jul 05 '18 14:07 andersonfaaria

The second bug no need put in monster, just create this npc script and say trade without any item in your backpack.

GoularPink avatar Jul 05 '18 16:07 GoularPink

yea, that was exactly what I've said, that's why I put

Another bug is that if you put a golden cup in a monster's drop, it will drop with type = 1 (water)`

andersonfaaria avatar Jul 06 '18 10:07 andersonfaaria

Do you intend to submit a PR to fix this?

DSpeichert avatar Jul 06 '18 23:07 DSpeichert

@DSpeichert I don't have the solution, I found this bug on my own server but didn't fixed it yet, just cataloged it. But as far as I tracked it, it's an error in buy/sell module because it have a weird logic when it comes to subtype:

if the subtype is given in npc xml, everything ok, it will only buy/sell from the specific subtype. else, it just buy/sells from subtype 0 (empty).

what should be changed is for the else case, it accepts the item regardless of subtype but I didn't know if it could have any side-effect.

andersonfaaria avatar Jul 13 '18 12:07 andersonfaaria

And the other bug I've mentioned: items in monster's drop behave a little differently, when the subtype is not specified they are added like "doCreateItem(item, count/subtype)" and therefore when there's no subtype specified they come with subtype 1 (water) because the count is always 1 when not specified.

This has to be re-made in source (I don't really know where) to check if item can hold a fluid, then the subtype is always 0 unless specified otherwise.

andersonfaaria avatar Jul 13 '18 12:07 andersonfaaria

It's a client limitation bound to client id of the items. There isn't much that can be done besides writing a new protocol for npc trading in otclient.

Zbizu avatar Dec 04 '20 00:12 Zbizu

did the merged PR fix the bugs?

Zbizu avatar Mar 28 '22 00:03 Zbizu

@Zbizu Not really. After these changes, it shows that you have '20 might rings' on sell window, when you have 0 of them. I don't know why there is different if, when we check for 5+ items.

There is really a lot of code in NPC Lua lib not compatible with C++ code of Trade window. It looks like it's impossible to restrict items with charges to be sellable only with given charges count (ex. not used might ring). Even, if you fix it in C++, you can still sell used rings using OTC with modified packet, as Lua code ignores subType for items that are not fluids: image

I've replaced:

				uint32_t count;
				if (itemType.isFluidContainer() || itemType.isSplash()) {
					count = player->getItemTypeCount(shopInfo.itemId, subtype); // This shop item requires extra checks
				} else {
					count = subtype;
				}

with:

				uint32_t count = player->getItemTypeCount(shopInfo.itemId, subtype); // This shop item requires extra checks

and it looks like it works fine now on C++ side [count of sellable items on Trade window].

Other Lua trading problem: 'chat trade' totally ignores subType in 'sell'. It's not even passed as parameter. With that C++ fix above. I can set might ring to by sellable by Trade Window only with 20 charges:

shopModule:addSellableItem({'might ring'}, 2164, 5000, 'might ring', 20)

but if I say sell might ring, it will still accept might ring with 1 charge. [spoofed 'sell by trade window' packet will also let me sell 1 charge might ring, as it's not fluid and subType is ignored]

// WORKING ON FIX

gesior avatar Mar 28 '22 17:03 gesior