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

[SOLVED] ExtendedCost doesn't work

Status
Not open for further replies.

Blazeqts

Enthusiast
What function do you have your code in, in Player.cpp? As far as I see, removing both returns will solve the forcing value to boolean. If your function was VendorItemData and not bool you could return VendorItemData. Probably have to think of some other way to return what you want.

It did solve the forcing value to boolean.

However, server crashes.

I don't quite understand what you mean by "What function do you have your code in".
What part of the code is a function, or what are you reffering to?
 

Tommy

Founder
It did solve the forcing value to boolean.

However, server crashes.

I don't quite understand what you mean by "What function do you have your code in".
What part of the code is a function, or what are you reffering to?

Not sure how clear I can get. :/

Your code is in a function being called somewhere else, what function is it in, inside Player.cpp? Is your code under "bool Player::BuyItemFromVendorSlot" or some other function?
 

Blazeqts

Enthusiast
Not sure how clear I can get. :/

Your code is in a function being called somewhere else, what function is it in, inside Player.cpp? Is your code under "bool Player::BuyItemFromVendorSlot" or some other function?

Haha, I see.

I believe it is in ObjectMgr.cpp or ObjectMgr.h or Creature.cpp.

Here it is in Creature:

Code:
VendorItemData const* Creature::GetVendorItems(Player const* player) const
{
	uint32 const entry = GetEntry();
	uint32 title = sObjectMgr->GetCreatureTemplate(entry)->SkinLootId;
	std::cout << player->GetName() << " - has title : " << player->HasTitle(title) << std::endl;
	if (title == 0 || player->HasTitle(title)) {
        return sObjectMgr->GetNpcVendorItemList(entry);
    }
	return sObjectMgr->GetNpcVendorItemListShowOnly(entry);
}

edit: https://github.com/immvp/ngen/commit/dea0e112a89c99ef25789b397de9f1f11d710ed4

^ Commit that added it into Creature.cpp
 

Rochet2

Moderator / Eluna Dev
You said yourself that you edited it to have the code
Code:
	    VendorItemData const* vItems = creature->GetVendorItems();
	{
	uint32 const entry = GetEntry();
		uint32 title = sObjectMgr->GetCreatureTemplate(entry)->SkinLootId;
		std::cout << GetName() << " - has title : " << HasTitle(title) << std::endl;
		if (title == 0 || HasTitle(title)) {
			return sObjectMgr->GetNpcVendorItemList(entry);
		}
		return sObjectMgr->GetNpcVendorItemListShowOnly(entry);
}
And this code is wrong.
The function returns a boolean (true or false) and you ar returning sObjectMgr->GetNpcVendorItemListShowOnly(entry); and sObjectMgr->GetNpcVendorItemList(entry);
You should ONLY be doing VendorItemData const* vItems = creature->GetVendorItems(this);
But you added all the function contents for some reason as well, which was not intended at all.

http://emudevs.com/showthread.php/4471-ExtendedCost-doesn-t-work?p=31199&viewfull=1#post31199
 

Blazeqts

Enthusiast
You said yourself that you edited it to have the code
Code:
	    VendorItemData const* vItems = creature->GetVendorItems();
	{
	uint32 const entry = GetEntry();
		uint32 title = sObjectMgr->GetCreatureTemplate(entry)->SkinLootId;
		std::cout << GetName() << " - has title : " << HasTitle(title) << std::endl;
		if (title == 0 || HasTitle(title)) {
			return sObjectMgr->GetNpcVendorItemList(entry);
		}
		return sObjectMgr->GetNpcVendorItemListShowOnly(entry);
}
And this code is wrong.
The function returns a boolean (true or false) and you ar returning sObjectMgr->GetNpcVendorItemListShowOnly(entry); and sObjectMgr->GetNpcVendorItemList(entry);
You should ONLY be doing VendorItemData const* vItems = creature->GetVendorItems(this);
But you added all the function contents for some reason as well, which was not intended at all.

http://emudevs.com/showthread.php/4471-ExtendedCost-doesn-t-work?p=31199&viewfull=1#post31199

Really? So ..

It should just look like this?
Code:
VendorItemData const* vItems = creature->GetVendorItems(this);
    if (!vItems || vItems->Empty())
    {
        SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, item, 0);
        return false;
    }

- - - Updated - - -

wtf how did this work? You fixed it Rochet, but can you explain to me WHY? I mean writing simply "this", how can it be that simple
 

Tommy

Founder
Really? So ..

It should just look like this?
Code:
VendorItemData const* vItems = creature->GetVendorItems(this);
    if (!vItems || vItems->Empty())
    {
        SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, item, 0);
        return false;
    }

- - - Updated - - -

wtf how did this work? You fixed it Rochet, but can you explain to me WHY? I mean writing simply "this", how can it be that simple

I was going to recommend that specific code to you but I wasn't sure what you were trying to do with your custom code. To be completely honest; it looks like all of your code came from: https://github.com/TrinityCore/Trin...game/Entities/Player/Player.cpp#L21731-L21808 those lines, given that "creature->GetVendorItems(this)" is different.
 

Rochet2

Moderator / Eluna Dev
wtf how did this work? You fixed it Rochet, but can you explain to me WHY? I mean writing simply "this", how can it be that simple

Likely you forgot to replace one GetVendorItems call. Check the buy item code for it.
There it will most likely take the original list where the item was free and thus not charge you for anything.

Before you only checked the title when you displayed the item to the player.
But you had not replaced the GetVendorItems function call with the new function that checks the title.
This means that the item was free because it is free in the database as well and the original database list was used when buying, no matter if you had the title or not.
Now the function you coded that takes a player checks the title and returns the fake list if the player didnt have the title.
 

Blazeqts

Enthusiast
Thank you guys so much, both of you. I was struggling with this code for 2 days trying to find a solution. Much love. :)
 
Status
Not open for further replies.
Top