SendListInventory with vendor entry

Hello,

I’m trying to send the items of any vendor NPC (with their entries) by interacting with a dummy NPC. I used the SendListInventory method and did some minor changes in it. Here is what I have :

void WorldSession::SendInventoryList(uint32 entry)
{
VendorItemData const* items = sObjectMgr->GetNpcVendorItemList(entry);
if (!items)
{
std::cout << “fail1” << std::endl;
return;
}

uint8 itemCount = items->GetItemCount();
uint8 count = 0;

WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + itemCount * 8 * 4);
// Player GUID here ?
data << uint64(_player->GetGUID());

size_t countPos = data.wpos();
data << uint8(count);

for (uint8 slot = 0; slot < itemCount; ++slot)
{
if (VendorItem const* item = items->GetItem(slot))
{
if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item->item))
{
uint32 leftInStock = 0xFFFFFFFF;
++count;

int32 price = item->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->BuyPrice)) : 0;

data << uint32(slot + 1);       // client expects counting to start at 1
data << uint32(item->item);
data << uint32(itemTemplate->DisplayInfoID);
data << int32(leftInStock);
data << uint32(price);
data << uint32(itemTemplate->MaxDurability);
data << uint32(itemTemplate->BuyCount);
data << uint32(item->ExtendedCost);
  }
}

}

if (count == 0)
{
std::cout << “fail2” << std::endl;
return;
}

data.put(countPos, count);
SendPacket(&data);
}

This code is almost working fine. I can retrieve the items of any vendor NPC I want, just by providing its entry, but there is a big issue :

I can neither buy any of the items nor sell mine to the vendor. It just says “You are too far away”.

What I am doing wrong ?

Thanks in advance.

PS : I found a similar topic, but it didn’t help me with my issue.

You need to edit the buyitemfromslot (buying packet handler) code

The multivendor modification does that.

Actually, you could just take the multivendor modification.

If you dont do it like I did there, you cant have more than 150 items in the NPC, no matter how many vendors you try to send. You will hit a wall when you try to buy the items and the client only can send slots up to 150 making you unable to identify which item in which list the player decided to buy and so.

You would need to save the vendor entry used by the player (same as I did) and then use the entry to get the vendor list later in the packet handler and then see if the item is real.

WIth the multivendor modification you can have unlimited amount of vendors in the NPC.

You could also try the same code /emoticons/default_smile.png (use the same idea, parts of code) Its not a big edit.

Around 9 lines needed for what you want. Unless you want to copy over the send function, which is pretty much a copy paste.

http://www.trinitycore.org/f/topic/7768-multi-vendor-core-mod/

Incase you are trying to just use the player to send the vendor, you need to do further edits to the buying part for example the check for if the NPC is interactable by the player (this is where you are atm)

etc.

Note that you also need to code buyback and selling and so also (modify the handlers)

I did not realize that I would have to modify that much stuff to make a fully working vendor /emoticons/default_sad.png.

So instead I took your patch and it works like a charm ! Thank you !

A last question, if I may, how can I remove the frame popping on the screen when you select a category (the one corresponding to the box_text field in gossip_menu_option) ?

Set the field in DB to NULL or ‘’ (empty string)

UPDATE `gossip_menu_option` SET `box_coded` = 0, `box_text` = NULL WHERE `menu_id` = 123 AND `id` = 12;

Okay, my bad, I put 0 instead of NULL.

Thanks a lot for your help and your work !