• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 3.3.5 Donation Vendor - Base working, need assistance with alerts

entrailz

New member
Hi there,

I am using a mixture of code that is allowing me to get "donation items" from a database table, display it as a vendor, and allow users to buy.

My issue is I want to give users a confirmation box when they attempt to buy the item that says "Are you sure you want to purchase x" or something similar.

I cannot find a way to do this, I have tried gossip menu's, such as the below:
Code:
AddGossipItemFor(session->GetPlayer(), GOSSIP_ICON_INTERACT_1, "Test", 0, session->GetPlayer()->AddItem(item, count), "Are you sure you want to purchase\n\n", (0), false);

But it just adds the item without any alert.

Current code:

http://pastebin.com/a4EaTb3w

Thanks
 

Rochet2

Moderator / Eluna Dev
Are you sure the code that sends the gossip menu is reached? (does the NPC say stuff?)
The session->GetPlayer()->AddItem(item, count) in the gossip option is wrong. You cant do that.
You must have a number there (for example item entry). Then in ongossipselect you can add the item entry (action) to the player.

Later when stuff works, make sure the code does not have exploits. For example if the client sends any item entry in the packet for buying, it can add any item entry it wants, not just the ones in the vendor.


I tested a little by opening a vendor and using this lua code:
.eluna plr:GossipClearMenu()
.eluna plr:GossipMenuAddItem(1, "asd", 0, 0, false, "asd?")
.eluna plr:GossipSendMenu(1, plr, 2)
which should do about the same as your code. It seemed to work fine. It can be though that my tests were not similar enough to yours and thus failed to replicate the same situation.
 

entrailz

New member
Hi,

Sorry, I don't think I was clear.

I don't really want it as a gossip menu. I want it to work in the same way as when you exchange currency.

Security I already have ideas in mind, I will do a lot of checks to prevent it :)

Thanks.

EDIT:

If you could perhaps come up with some example code for Eluna, I would much rather use Eluna since I don't have to recompile all the time.

So, SQL query to select items from database to display.
When a user opens the vendor, it displays these items, with their price (Or any price, I could look into doing a SQL query to do this)
When they try to purchase, they are alerted to the cost.
The item is added to the user.
 
Last edited:

Rochet2

Moderator / Eluna Dev
Im not quite sure what you mean with "the same way as when you exchange currency".
I assume you mean this? https://youtu.be/VrBXgB_Zee8?t=58
If so, then that is probably client side (meaning nothing is sent to server between clicking to buy and getting the popup for confirmation) and would need you to use some token or honor or similar to trigger it. (extended cost)
If this is not it, then it is possible I have never seen it in game.

The way the gossip solution you seemed to have and I tested myself would work would be exactly the same as the popup in the video.
However the downside is that the vendor window will close.
( no gossip menu is ever visible when made in a specific way. Only the popup box would be visible. )
 

entrailz

New member
Hi there,

Yes that is what I was looking for. I did some testing and was able to trigger it with Extended Cost, but I am going to go down the route of Gossip.

This is what I have now:

Code:
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item);
				AddGossipItemFor(session->GetPlayer(), GOSSIP_ICON_INTERACT_1, "Purchase " + itemTemplate->Name1 + ", this is a non-refundable purchase!", 0, Melt(100, item), "Are you sure you want to purchase\n\n" + itemTemplate->Name1, (itemTemplate->SellPrice * GOLD), false);
				SendGossipMenuFor(session->GetPlayer(), DEFAULT_GOSSIP_MESSAGE, vendorguid);

bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 melt) override
	{
		ClearGossipMenuFor(player);

		uint8 menu, action;
		Unmelt(melt, menu, action);

		switch (menu)
		{
		case 100:
			player->AddItem(action, 1);
			OnGossipHello(player, creature);
			break;
		default:
			OnGossipHello(player, creature);
			break;
		}
		return true;
	}

This works in the way I want it to, albeit a little messy.

I was wondering if this is acheivable in LUA however? In the sense that I can have a vendor, populate items via LUA, and handle adding item via LUA.
 

Rochet2

Moderator / Eluna Dev
Yes, you can do it in lua. More or less the same way you do it with C++ from what I can see.
 
Top