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

Item Gossip

Rochet2

Moderator / Eluna Dev
Hmm, shouldnt probably use FOREACH_SCRIPT for item script?
GET_SCRIPT would be better I think.
 

arlyon

Enthusiast
Help

I've been looking through this, and I was wondering if anyone was able to give some sort of complete start to finish guide on this? Not anything extremely in depth, as I know somewhat how, just an overview.

I haven't done scripting aside from game scripts (allowing flight anywhere, and adding new races/factions) but not applied scripts such as npcs and items.

Any help is appreciated :)

EDIT: I thought I'd give some extra info, I followed this part here: http://emudevs.com/showthread.php/1518-Item-Gossip?p=9539&viewfull=1#post9539 and applied all that to the core.

I then added this script: http://pastebin.com/XGrYHksH to the src/server/script/custom folder and added it to cmakelists.

I then followed this guide: http://collab.kpsn.org/display/tc/How-to_CustomScript and it all seems to be working together.

Although, I get met with this on compile:

Code:
3>..\..\..\..\TrinityCore\src\server\scripts\Custom\gossipitem.cpp(15): error C2065: 'DEFAULT_GOSSIP_MENU' : undeclared identifier
3>..\..\..\..\TrinityCore\src\server\scripts\Custom\gossipitem.cpp(16): error C2562: 'PlayerGossipTest::OnPlayerLeaveCombat' : 'void' function returning a value
3>          ..\..\..\..\TrinityCore\src\server\scripts\Custom\gossipitem.cpp(8) : see declaration of 'PlayerGossipTest::OnPlayerLeaveCombat'

I'm pretty sure it's from the script, not any of the other parts, but I'm not exactly sure.
 
Last edited:

Rochet2

Moderator / Eluna Dev
Edit: For future, I suggest using this:
http://rochet2.github.io/?page=Player_and_Item_Gossip



Old post contents for reference:
Here is the patch fixed:
http://pastebin.com/LEQJLGzZ
Here are example scripts on how to use:
http://pastebin.com/n27GVrKU


I had not tested the script I made before and it had basic variable errors.
Also the patch had issues as I tried to note on my earlier post.

Note. Above patch and scripts are also untested, but they compile.


If you have any questions about it, ask a question about your issue, dont ask a general guide about everything about the patch.
 
Last edited:

arlyon

Enthusiast
Thanks for the quick reply, Rochet. I appreciate it.

It seems I got it working now, it was a problem with caps (used referenced gossipnpc in one place, and GossipNpc in others).

I'll make sure to keep it topic specific next time :) thanks.
 

Rochet2

Moderator / Eluna Dev
I suggest you remove the patch you have now and apply the patch I wrote just now if you are going to use item gossip.
The item gossip was using wrong way to trigger the scripts and will not work properly on the main release patch.
 

Shonik

Enthusiast
Hi, i'm new here :).
Is there a way to do the same thing but with WorldScript, like using gossip with OnUpdate hook for example ?
 

Shonik

Enthusiast
Ok, thanks rochet, i'll try so :)

Edit : I added your patch, then tried to add gossip in my OnUpdate hook but I always get this error when i connect
WorldSocket::SendPacket enqueue_tail failed
Are you familiar with it ?
 
Last edited:

Rochet2

Moderator / Eluna Dev
Ok, thanks rochet, i'll try so :)

Edit : I added your patch, then tried to add gossip in my OnUpdate hook but I always get this error when i connect
WorldSocket::SendPacket enqueue_tail failed
Are you familiar with it ?

How does the gossip code look like?
 

Shonik

Enthusiast
I'm a wery begginer in c++ coding, so it may not be perfect code at all ^^
Code:
#include "ScriptMgr.h"

#define TIME 30 //total time played you want for the reward. (in seconds)
#define ITEM_ID_1 6256 //the item id you want as a reward.
#define ITEM_QUANTITY_1 1 //the quantity you want for your reward.
#define ITEM_ID_2 44050 //the item id you want as a reward.
#define ITEM_QUANTITY_2 1 //the quantity you want for your reward.

uint32 HasItem = 0;

class totaltimeplayed_reward : public WorldScript
{

public :

	totaltimeplayed_reward() : WorldScript("totaltimeplayed_reward") { }

	void OnUpdate(uint32 /*diff*/)
	{
		SessionMap ss = sWorld->GetAllSessions();
		for(SessionMap::iterator itr = ss.begin(); itr != ss.end(); ++itr)
		{
			if (!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld())
                                continue;

			Player* player = itr->second->GetPlayer();
			uint32 total_played_time = player->GetTotalPlayedTime();
			if (total_played_time >= TIME)
			{
				while (HasItem != 1)
				{
					player->PlayerTalkClass->ClearMenus();
					player->ADD_GOSSIP_ITEM(0, "Choisir l'item 1", GOSSIP_SENDER_MAIN, 1);
					player->ADD_GOSSIP_ITEM(0, "Choisir l'item 2", GOSSIP_SENDER_MAIN, 2);
					player->PlayerTalkClass->GetGossipMenu().SetMenuId(123);
					player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, player->GetGUID());
				}
			}
		}
	}

	void OnGossipSelect(Player* player, uint32 menu_id, uint32 sender, uint32 action)
	{
		if(menu_id != 123)
			return;

		player->PlayerTalkClass->ClearMenus();

		switch(action)
		{
		case 1 :
			player->AddItem(ITEM_ID_1, ITEM_QUANTITY_1);
			player->SaveToDB();
			++HasItem;
			break;

		case 2 :
			player->AddItem(ITEM_ID_2, ITEM_QUANTITY_2);
			player->SaveToDB();
			++HasItem;
			break;
		}
		player->CLOSE_GOSSIP_MENU();
	}

};

void AddSC_totaltimeplayed_reward()
{
	new totaltimeplayed_reward();
}
 

Rochet2

Moderator / Eluna Dev
I'm a wery begginer in c++ coding, so it may not be perfect code at all ^^
Code:
#include "ScriptMgr.h"

#define TIME 30 //total time played you want for the reward. (in seconds)
#define ITEM_ID_1 6256 //the item id you want as a reward.
#define ITEM_QUANTITY_1 1 //the quantity you want for your reward.
#define ITEM_ID_2 44050 //the item id you want as a reward.
#define ITEM_QUANTITY_2 1 //the quantity you want for your reward.

uint32 HasItem = 0;

class totaltimeplayed_reward : public WorldScript
{

public :

	totaltimeplayed_reward() : WorldScript("totaltimeplayed_reward") { }

	void OnUpdate(uint32 /*diff*/)
	{
		SessionMap ss = sWorld->GetAllSessions();
		for(SessionMap::iterator itr = ss.begin(); itr != ss.end(); ++itr)
		{
			if (!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld())
                                continue;

			Player* player = itr->second->GetPlayer();
			uint32 total_played_time = player->GetTotalPlayedTime();
			if (total_played_time >= TIME)
			{
				while (HasItem != 1)
				{
					player->PlayerTalkClass->ClearMenus();
					player->ADD_GOSSIP_ITEM(0, "Choisir l'item 1", GOSSIP_SENDER_MAIN, 1);
					player->ADD_GOSSIP_ITEM(0, "Choisir l'item 2", GOSSIP_SENDER_MAIN, 2);
					player->PlayerTalkClass->GetGossipMenu().SetMenuId(123);
					player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, player->GetGUID());
				}
			}
		}
	}

	void OnGossipSelect(Player* player, uint32 menu_id, uint32 sender, uint32 action)
	{
		if(menu_id != 123)
			return;

		player->PlayerTalkClass->ClearMenus();

		switch(action)
		{
		case 1 :
			player->AddItem(ITEM_ID_1, ITEM_QUANTITY_1);
			player->SaveToDB();
			++HasItem;
			break;

		case 2 :
			player->AddItem(ITEM_ID_2, ITEM_QUANTITY_2);
			player->SaveToDB();
			++HasItem;
			break;
		}
		player->CLOSE_GOSSIP_MENU();
	}

};

void AddSC_totaltimeplayed_reward()
{
	new totaltimeplayed_reward();
}

I had the same error once with my code and someone noticed I had an infinite loop.
You seem to have one too:

while (HasItem != 1)
{
player->PlayerTalkClass->ClearMenus();
player->ADD_GOSSIP_ITEM(0, "Choisir l'item 1", GOSSIP_SENDER_MAIN, 1);
player->ADD_GOSSIP_ITEM(0, "Choisir l'item 2", GOSSIP_SENDER_MAIN, 2);
player->PlayerTalkClass->GetGossipMenu().SetMenuId(123);
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, player->GetGUID());
}

- - - Updated - - -

I'm a wery begginer in c++ coding, so it may not be perfect code at all ^^
Code:
#include "ScriptMgr.h"

#define TIME 30 //total time played you want for the reward. (in seconds)
#define ITEM_ID_1 6256 //the item id you want as a reward.
#define ITEM_QUANTITY_1 1 //the quantity you want for your reward.
#define ITEM_ID_2 44050 //the item id you want as a reward.
#define ITEM_QUANTITY_2 1 //the quantity you want for your reward.

uint32 HasItem = 0;

class totaltimeplayed_reward : public WorldScript
{

public :

	totaltimeplayed_reward() : WorldScript("totaltimeplayed_reward") { }

	void OnUpdate(uint32 /*diff*/)
	{
		SessionMap ss = sWorld->GetAllSessions();
		for(SessionMap::iterator itr = ss.begin(); itr != ss.end(); ++itr)
		{
			if (!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld())
                                continue;

			Player* player = itr->second->GetPlayer();
			uint32 total_played_time = player->GetTotalPlayedTime();
			if (total_played_time >= TIME)
			{
				while (HasItem != 1)
				{
					player->PlayerTalkClass->ClearMenus();
					player->ADD_GOSSIP_ITEM(0, "Choisir l'item 1", GOSSIP_SENDER_MAIN, 1);
					player->ADD_GOSSIP_ITEM(0, "Choisir l'item 2", GOSSIP_SENDER_MAIN, 2);
					player->PlayerTalkClass->GetGossipMenu().SetMenuId(123);
					player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, player->GetGUID());
				}
			}
		}
	}

	void OnGossipSelect(Player* player, uint32 menu_id, uint32 sender, uint32 action)
	{
		if(menu_id != 123)
			return;

		player->PlayerTalkClass->ClearMenus();

		switch(action)
		{
		case 1 :
			player->AddItem(ITEM_ID_1, ITEM_QUANTITY_1);
			player->SaveToDB();
			++HasItem;
			break;

		case 2 :
			player->AddItem(ITEM_ID_2, ITEM_QUANTITY_2);
			player->SaveToDB();
			++HasItem;
			break;
		}
		player->CLOSE_GOSSIP_MENU();
	}

};

void AddSC_totaltimeplayed_reward()
{
	new totaltimeplayed_reward();
}

I had the same error once with my code and someone noticed I had an infinite loop.
You seem to have one too:

while (HasItem != 1)
{
player->PlayerTalkClass->ClearMenus();
player->ADD_GOSSIP_ITEM(0, "Choisir l'item 1", GOSSIP_SENDER_MAIN, 1);
player->ADD_GOSSIP_ITEM(0, "Choisir l'item 2", GOSSIP_SENDER_MAIN, 2);
player->PlayerTalkClass->GetGossipMenu().SetMenuId(123);
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, player->GetGUID());
}

Otherwise the code is rather massive I guess to be ran on every tick?
Could delay it to be run every 5 seconds etc.
The idea with hasitem variable is not working well.

The gossip select hook needs to be in a playerscript class.
 

Shonik

Enthusiast
I'll try to fix that, thanks again

Edit : It works like a charm ! But you're right, I don't have a single idea how to do this, but i need to execute the script like every 5 seconds, otherwise it creates a bit of lags.
Should i use diff variable to do this ?
 
Last edited:

Rochet2

Moderator / Eluna Dev
I'll try to fix that, thanks again

Edit : It works like a charm ! But you're right, I don't have a single idea how to do this, but i need to execute the script like every 5 seconds, otherwise it creates a bit of lags.
Should i use diff variable to do this ?

I suggest you create a support thread.
In there you should show the current script you have so far.
You should also tell, in detail, what you want to do.

Then it will not bloat this topic and you may get more replies. Also telling what you are after may give ideas of different approaches etc.

And yes. You could use the diff variable.
 

Shonik

Enthusiast
I suggest you create a support thread.
In there you should show the current script you have so far.
You should also tell, in detail, what you want to do.

Then it will not bloat this topic and you may get more replies. Also telling what you are after may give ideas of different approaches etc.

And yes. You could use the diff variable.

Of course, i'll do this
 
Top