• 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] how i can require items amounts in a gossip from a list of items.

Status
Not open for further replies.

ricardodj

Member
Hello guys, i have a little problem, i have a custom quest with name season 8 pre-quest
now i need a c++ script gossip to complete the Quest example if i have 8 pieces of Required season 7, then complete the quest. but the problem is, how i can require 8 items s7 example Head Shoulder chest gloves legguards fets waist wrist, but also ignore if for example head is a sp item, or dps, if someone know how to do something like this or similar, and can please tell me i will be happy.
this is my script is only a example.
Code:
 class npc_quests : public CreatureScript
{
public:
	npc_quests() : CreatureScript("npc_quests") { }

	bool OnGossipHello(Player* player, Creature* creature)
	{
		AddGossipItemFor(player, 1, "Nevermind", GOSSIP_SENDER_MAIN, 0);
		AddGossipItemFor(player, 1, "Check if can complet s8 quest", GOSSIP_SENDER_MAIN, 1);
		player->PlayerTalkClass->SendGossipMenu(1, creature->GetGUID());
		return true;
	}

	bool OnGossipSelect(Player* player, Creature* creature, uint32 /* Sender*/, uint32 Action)
	{

		uint32 Item_Entry[9] =
		{
			20537,
			30436,
			50453,
			60532,
			44059,
			24533,
			38060,
			55617,
			47502
			
		};

		player->PlayerTalkClass->ClearMenus();

		switch (Action)
		{
		case 0:
			CloseGossipMenuFor(player);
			break;
		case 1:
			for (uint32 i = 0; i < sizeof(Item_Entry) / sizeof(uint32); i++)
			{
				if  (player->HasItemCount(Item_Entry[i]) && player->hasQuest(108000))
					player->CompleteQuest(108000);
				ChatHandler(player->GetSession()).PSendSysMessage("Congratulations, s8 Quest Completed!", player->GetGUID());
				}
				CloseGossipMenuFor(player);
				break;
			}
			return true;
		}

	};

void AddSC_npc_quests()
{
	new npc_quests();
}



and again if anyone can help me to do this i will be happy
 

Rochet2

Moderator / Eluna Dev
Cant think of a cool way to do it, but here is one:

Code:
// has to have one item from the list on each row
std::vector<std::vector<uint32>> itemLists =
{
{1,2,3},     // head
{4,5,6,7,8}, // shoulder
// and so on
};

// 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(Item_Entry[i]))
            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;
}

// the case on gossip select, checks the player has the quest and items and then completes quest
case 1:
if (player->hasQuest(108000))
{
    if (hasItems(player, itemLists))
    {
        player->CompleteQuest(108000);
        ChatHandler(player->GetSession()).PSendSysMessage("Congratulations, s8 Quest Completed!", player->GetGUID());
    }
}
 

ricardodj

Member
ok
 

Attachments

  • aaaaa.jpg
    aaaaa.jpg
    22.4 KB · Views: 30
  • aaaaa.jpg
    aaaaa.jpg
    161.8 KB · Views: 31
Last edited:

Rochet2

Moderator / Eluna Dev
you cannot use functions like that. The hasitems and hasitemfrom need to be outside of OnGossipSelect
or otherwise you would need to use lambdas but I dont recommend that here.
Also you could move the item entry vector to the top of the script (after includes) and maybe make it static.
 

MrPixelMC

Member
Another way to handle it would be with Database support. You can create a new table which uses a Foreign Key (linked to 'entry' column inside item_template table), and then you can create a column called "season" or something like that, and make a list in there.
The script would then retrieve data directly from the DB table you've created. Imo it's a better way to handle it but it's up to you, of course.
 

ricardodj

Member
ok now i have last error haha, in if (player->HasItemCount(Item_Entry))
i dont know, what to put here
i can compile without errors with if (player->HasItemCount(entry, 2))
just to se if is my last error.
so i dont know what to put instead of Item_Entry and
sorry for waste your time rochet also the errors is Item_Entry and no is defined
 
Last edited:

Rochet2

Moderator / Eluna Dev
The call should be player->HasItemCount(entry, 1) instead of player->HasItemCount(Item_Entry)
because entry is the item entry and 1 is the amount (count) you want the player to have it.

I coded in the browser so there can be copy paste and other mistakes there.
 
Last edited:

ricardodj

Member
well i tried it yesterday with player->Has Item Count(entry, 2)
and i can compile without error but when i click in Check if i can complete s8 quest, doesn't happened nothing, i mean the gossip doesnt show me alerts like congratulations, s8 Quest Completed!
or You don't have the required 8 pieces of season 7. and also CloseGossipMenu doesnt close the gossip, maybe is caused by a return?
 
Last edited:

Rochet2

Moderator / Eluna Dev
No, the reason is the classic hasQuest mistake.
Instead of hasQuest you should use IsActiveQuest
hasQuest is meant for creatures and gameobjects etc for checking if the entity gives out the quest to the player.
 

ricardodj

Member
wow finally the cause was something very simple IsActive Quest as you say me
lol thanks for waste your time with me and my boring topic. you are the best, you can finally can close this boring topic made by me :p
and again thanks for all sir! and also thanks to google translator help me much to translate my commentaries to english, no is perfect but at least You understand at least a little to help me :p
 
Status
Not open for further replies.
Top