• 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] set not Refundable items

Status
Not open for further replies.

ricardodj

Member
hello, i made a topic some days ago to get help to make a list of items for a custom gossip, to complete a custom quest but now i see i need to Set NonRefundable to the items from the list, for example players need 10 items from a list of items to complete a custom quest, but now after players complete the quest. these players can sell (refund) these items again because players has 30 min to refund the items, i want to when players complete the quest then set Non Refundable these items, yes i know i can disable the 30 min refund from items but there is a season items and for me is a better idea to set the NonRefundable
i find something like this in transmogrifier
itemTransmogrifier->SetNotRefundable(player);
maybe i need something like this. if anyone know how i can do it I would be very grateful this is also my script


Code:
		    // has to have one item from the list on each row
			std::vector<std::vector<uint32>> itemLists =
			{
				{ 68530, 68531, 68532, 68533, 68534, 68535 }, // head
				{ 68540, 68541, 68542, 68543, 68544, 68545 }, // shoulder
				{ 68550, 68551, 68552, 68553, 68554, 68555 }, // Chest
                { 68560, 68561, 68562, 68563, 68564, 68565 }, // Gauntlets
				{ 68570, 68571, 68572, 68573, 68574, 68575 }, // Leg
				
			};
			
			// returns true if the player has at least one item from the list
			bool hasItemFrom(Player* player, std::vector<uint32>& list)
			{
				for (uint32 entry : list)
					if (player->HasItemCount(entry, 1))
						return true;
				return false;
			}

			// returns true if the player has at least one item from each list
			bool hasItems(Player* player, std::vector<std::vector<uint32>>& list)
			{
				for (std::vector<uint32>& list : itemLists)
					if (!hasItemFrom(player, list))
						return false;
				return true;
			}

class npc_quest_s10 : public CreatureScript
{
public:
	npc_quest_s10() : CreatureScript("npc_quest_s10") { }

	bool OnGossipHello(Player* player, Creature* creature)
	{
		AddGossipItemFor(player, 0, "Check if I have enough season 9 items to complete the quest.", GOSSIP_SENDER_MAIN, 1);
		player->PlayerTalkClass->SendGossipMenu(1, creature->GetGUID());
		return true;
	}	
	
	bool OnGossipSelect(Player *player, Creature *creature, uint32 sender, uint32 action)
	{

		player->PlayerTalkClass->ClearMenus();

		switch (action)
		{	

			// the case on gossip select, checks the player has the quest and items and then completes quest
		case 1:
				if  (!player->IsActiveQuest(108000))
                {
					CloseGossipMenuFor(player);
                    ChatHandler(player->GetSession()).PSendSysMessage("You need Arena Season 9 Quest..", player->GetGUID());
                    break;
                }
				
				if (hasItems(player, itemLists))
				{
					player->CompleteQuest(108000);
					CloseGossipMenuFor(player);
					ChatHandler(player->GetSession()).PSendSysMessage("Congratulations, Arena Season Completed!", player->GetGUID());
                }
		        else
		        {
					CloseGossipMenuFor(player);
					ChatHandler(player->GetSession()).PSendSysMessage("You don't have the required 5 pieces of season 8.", player->GetGUID());
			}


		}
 

Rochet2

Moderator / Eluna Dev
You need to get the items the player has, loop them through and see if they are in the list of items you have.
Then if they are, set them nonrefundable.
All this is done when the quest is completed I assume.

its not pretty, but there are only so many ways to get items the player has.
Im sure there can be clearner ways of doing this.
Code:
        std::unordered_set<uint32> items; // a set of item entries used for the refunding
        for (auto& list : itemLists) // itemLists was defined earlier
            for (uint32 entry : list)
                items.insert(entry);

        for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
            if (Item* pItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                if (items.find(pItem->GetEntry()) != items.end())
                    pItem->SetNotRefundable(player);

        for (uint8 i = KEYRING_SLOT_START; i < CURRENCYTOKEN_SLOT_END; ++i)
            if (Item* pItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                if (items.find(pItem->GetEntry()) != items.end())
                    pItem->SetNotRefundable(player);

        for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
            if (Bag* pBag = player->GetBagByPos(i))
                for (uint32 j = 0; j < pBag->GetBagSize(); ++j)
                    if (Item* pItem = pBag->GetItemByPos(j))
                        if (items.find(pItem->GetEntry()) != items.end())
                            pItem->SetNotRefundable(player);

        for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_END; ++i)
            if (Item* pItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                if (items.find(pItem->GetEntry()) != items.end())
                    pItem->SetNotRefundable(player);
 

ricardodj

Member
wow worked well thanks rochet2 you helped me again i am very very grateful with you thanks again made my day happy again :tongue (2):
topic is solved
 
Status
Not open for further replies.
Top