Jump to content

Recommended Posts

  • Honorable Member
This is the hidden content, please

Alternative download links →

This is the hidden content, please

I couldn't find any of the events on the forum to avoid a double post so I decided to post it anyway in case it could be of use to someone.
I will also update this topic with new events as needed and if requested.

Quest Events / Triggers

  • Fishing
  • Mining
  • Selling
  • Buying
  • Crafting
  • Emoting

See example below of how to use them.

Usage Example

Spoiler
quest new_event_test begin
	state start begin
		when mine begin
			notice("You are mining.")
		end

		when fish begin
			notice("You are fishing.")
		end

		when buy begin
			notice("HandleReceiveAllEvent")
			notice(string.format("You bought item %d from NPC %d", item.get_vnum(), npc.get_race()))
		end
		when 9003.buy begin -- General Store Saleswoman
			notice("HandleEvent")
			notice(string.format("You bought item %d from NPC %d", item.get_vnum(), npc.get_race()))
		end

		when sell begin
			notice("HandleReceiveAllEvent")
			notice(string.format("You sold item %d to NPC %d", item.get_vnum(), npc.get_race()))
		end
		when 9003.sell begin -- General Store Saleswoman
			notice("HandleEvent")
			notice(string.format("You sold item %d to NPC %d", item.get_vnum(), npc.get_race()))
		end

		when craft begin
			notice("HandleReceiveAllEvent")
			notice(string.format("You crafted item %d from NPC %d", item.get_vnum(), npc.get_race()))
		end
		when 20018.craft begin -- Baek-Go NPC
			notice("HandleEvent")
			notice(string.format("You crafted item %d from NPC %d", item.get_vnum(), npc.get_race()))
		end

		when emotion begin
			notice("HandleReceiveAllEvent")
			if npc.is_pc() then
				notice(string.format("You are emoting / acting with %s", npc.get_name()))
			else
				notice("You are emoting / acting alone.")
			end
		end
	end
end

 

 

  • Metin2 Dev 132
  • kekw 1
  • Eyes 1
  • Good 20
  • muscle 1
  • Love 7
  • Love 93
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Honorable Member
1 hour ago, Owsap said:
, npc.get_race()

To do so you have to select the NPC first, but you didn't.

You need to set ch->SetQuestNPCID(npc->GetVID()); first.

otherwise you're calling an ambiguous npc (nullptr, another npc, or a deleted npc which makes it a dangling pointer) when you use this function:


	LPCHARACTER CQuestManager::GetCurrentNPCCharacterPtr()
	{
		return GetCurrentCharacterPtr() ? GetCurrentCharacterPtr()->GetQuestNPC() : nullptr;
	}

I'll send a pull request on github later, and I'll add the npc for the mine event too. (and the emotion one if time allows me)

Thanks for sharing.

Edited by martysama0134
  • Good 1
  • Love 1
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154455
Share on other sites

  • Honorable Member
2 hours ago, martysama0134 said:

To do so you have to select the NPC first, but you didn't.

You need to set ch->SetQuestNPCID(npc->GetVID()); first.

otherwise you're calling an ambiguous npc (nullptr, another npc, or a deleted npc which makes it a dangling pointer) when you use this function:


	LPCHARACTER CQuestManager::GetCurrentNPCCharacterPtr()
	{
		return GetCurrentCharacterPtr() ? GetCurrentCharacterPtr()->GetQuestNPC() : nullptr;
	}

I'll send a push request on github later, and I'll add the npc for the mine event too. (and the emotion one if time allows me)

I get what you mean, I didn't need to do that for the specific events because OnClick did that for me.

Edited by Owsap
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154456
Share on other sites

  • Honorable Member
22 minutes ago, Owsap said:

I didn't need to do that for the specific events because OnClick did that for me, so in this case there isn't any problem at all

::OnClick is called when you click on the npc to open the shop, but not when you buy/sell. If you battle a mob, touch anything else, the selected npc gets swapped. Easy exploit/bug.

Edited by martysama0134
  • Good 1
  • Love 1
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154457
Share on other sites

  • Honorable Member
1 minute ago, martysama0134 said:

::OnClick is called when you click on the npc to open the shop, but not when you buy/sell. If you battle a mob, touch anything else, the selected npc get swapped. Easy exploit/bug.

I will correct that, I just noticed.

  • Love 1
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154458
Share on other sites

  • Honorable Member

Lovely.

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154460
Share on other sites

  • Honorable Member

Updated

  • Fixed issue with quest NPC VID reported by @ martysama0134.
  • Added emotion event by request.

 

  • Metin2 Dev 1
  • Good 1
  • Love 1
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154461
Share on other sites

  • Active+ Member

First of all, thank you for this release!

There are few details, which I have to say:

1. You can get error when compiling:

File: questmanager.cpp:

LC_STRING("Äù½ºÆ®¸¦ ·ÎµåÇÏ´Â ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁֽʽÿÀ.")

Should be like this by default:

LC_TEXT("Äù½ºÆ®¸¦ ·ÎµåÇÏ´Â ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁֽʽÿÀ.")

And what does it mean? I couldn't find any translation in my locale_string.txt. It's something like: Quests aren't loaded?

2. You probably won't find this line:

File: shop_manager.cpp:

// search
DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), iPrice);

Should be like this by default:

// search
DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), dwPrice);

Because iPrice is by default dwPrice, if I'm not mistaken.

  • Good 1

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154473
Share on other sites

  • Honorable Member
Quote
15 minutes ago, ReFresh said:

First of all, thank you for this release!

There are few details, which I have to say:

1. You can get error when compiling:

File: questmanager.cpp:

LC_STRING("Äù½ºÆ®¸¦ ·ÎµåÇÏ´Â ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁֽʽÿÀ.")

Should be like this by default:

LC_TEXT("Äù½ºÆ®¸¦ ·ÎµåÇÏ´Â ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁֽʽÿÀ.")

And what does it mean? I couldn't find any translation in my locale_string.txt. It's something like: Quests aren't loaded?

2. You probably won't find this line:

File: shop_manager.cpp:

// search
DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), iPrice);

Should be like this by default:

// search
DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), dwPrice);

Because iPrice is by default dwPrice, if I'm not mistaken.

 

Thanks @ ReFresh, I fixed the tutorial.

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154474
Share on other sites

  • Honorable Member
2 minutes ago, ReFresh said:

And one more thing. I don't get notice when I start mining with pickaxe. I'm 100% sure that I didn't do mistake in my files. Can you check it?

It's working for me.

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154481
Share on other sites

  • Developer

Thank you for sharing, I appreciate these types of additions because they came about to facilitate other types of scripts. I find them very useful

  • Love 1

Villains are not born, they are made.
Join

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154482
Share on other sites

  • Active+ Member
On 1/16/2023 at 6:18 PM, Owsap said:

It's working for me.

I followed the github tutorial again to check for possible mistakes and no mistakes were found. The mine event still doesn't work. I can't see any reason why it doesn't work. No errors, syssers, syslogs... Everything is added correctly and I still can't get the notice output when I start the mine event. It's only the mine event, so it's really weird. Looks like I'm the only one who added and completely tested these events.

Here I can prove that everything is added correctly:

Spoiler
//cmd_emotion.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
#include "questmanager.h"
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
	ch->SetQuestNPCID(victim ? victim->GetVID() : 0);
	quest::CQuestManager::instance().Emotion(ch->GetPlayerID(), victim ? victim->GetRaceNum() : quest::QUEST_NO_NPC);
#endif
  
//cube.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
#include "questmanager.h"
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
		ch->SetQuestNPCID(npc->GetVID());
		quest::CQuestManager::instance().CraftItem(ch->GetPlayerID(), npc->GetRaceNum(), new_item);
#endif
  
//char.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	quest::CQuestManager::instance().Mine(GetPlayerID());
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
	quest::CQuestManager::instance().Fish(GetPlayerID());
#endif
  
//quest.h
#ifdef ENABLE_NEW_QUEST_EVENTS
		QUEST_FISH_EVENT,
		QUEST_MINE_EVENT,
		QUEST_ITEM_BUY_EVENT,
		QUEST_ITEM_SELL_EVENT,
		QUEST_ITEM_CRAFT_EVENT,
		QUEST_EMOTION_EVENT,
#endif
  
//questmanager.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
		m_mapEventName.insert(TEventNameMap::value_type("fish", QUEST_FISH_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("mine", QUEST_MINE_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("buy", QUEST_ITEM_BUY_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("sell", QUEST_ITEM_SELL_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("craft", QUEST_ITEM_CRAFT_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("emotion", QUEST_EMOTION_EVENT));
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
	void CQuestManager::Fish(unsigned int pc)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			m_mapNPC[QUEST_NO_NPC].OnFish(*pPC);
		}
		else
		{
			sys_err("QUEST FISH_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::Mine(unsigned int pc)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			m_mapNPC[QUEST_NO_NPC].OnMine(*pPC);
		}
		else
		{
			sys_err("QUEST MINE_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::BuyItem(unsigned int pc, unsigned int npc, LPITEM item)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
			{
				LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc);
				if (ch)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Quests aren't loaded."));
				}
				return;
			}

			SetCurrentItem(item);

			if (npc != QUEST_NO_NPC)
				m_mapNPC[npc].OnBuyItem(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnBuyItem(*pPC);
		}
		else
		{
			sys_err("QUEST ITEM_BUY_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::SellItem(unsigned int pc, unsigned int npc, LPITEM item)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
			{
				LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc);
				if (ch)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Quests aren't loaded."));
				}
				return;
			}

			SetCurrentItem(item);

			if (npc != QUEST_NO_NPC)
				m_mapNPC[npc].OnSellItem(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnSellItem(*pPC);
		}
		else
		{
			sys_err("QUEST ITEM_SELL_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::CraftItem(unsigned int pc, unsigned int npc, LPITEM item)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
			{
				LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc);
				if (ch)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Quests aren't loaded."));
				}
				return;
			}

			SetCurrentItem(item);

			if (npc != QUEST_NO_NPC)
				m_mapNPC[npc].OnCraftItem(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnCraftItem(*pPC);
		}
		else
		{
			sys_err("QUEST ITEM_CRAFT_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::Emotion(unsigned int pc, unsigned int target)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			if (target != QUEST_NO_NPC)
				m_mapNPC[target].OnEmotion(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnEmotion(*pPC);
		}
		else
		{
			sys_err("QUEST EMOTION_EVENT no such pc id : %d", pc);
		}
	}
#endif
  
//questmanager.h
#ifdef ENABLE_NEW_QUEST_EVENTS
			void		Fish(unsigned int pc);
			void		Mine(unsigned int pc);
			void		BuyItem(unsigned int pc, unsigned int npc, LPITEM item);
			void		SellItem(unsigned int pc, unsigned int npc, LPITEM item);
			void		CraftItem(unsigned int pc, unsigned int npc, LPITEM item);
			void		Emotion(unsigned int pc, unsigned int target);
#endif

//questnpc.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	bool NPC::OnFish(PC& pc)
	{
		return HandleReceiveAllEvent(pc, QUEST_FISH_EVENT);
	}

	bool NPC::OnMine(PC& pc)
	{
		return HandleReceiveAllEvent(pc, QUEST_MINE_EVENT);
	}

	bool NPC::OnBuyItem(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_ITEM_BUY_EVENT);
		else
			return HandleEvent(pc, QUEST_ITEM_BUY_EVENT);
	}

	bool NPC::OnSellItem(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_ITEM_SELL_EVENT);
		else
			return HandleEvent(pc, QUEST_ITEM_SELL_EVENT);
	}

	bool NPC::OnCraftItem(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_ITEM_CRAFT_EVENT);
		else
			return HandleEvent(pc, QUEST_ITEM_CRAFT_EVENT);
	}

	bool NPC::OnEmotion(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_EMOTION_EVENT);
		else
			return HandleEvent(pc, QUEST_EMOTION_EVENT);
	}
#endif
  
//questnpc.h
#ifdef ENABLE_NEW_QUEST_EVENTS
			bool	OnFish(PC& pc);
			bool	OnMine(PC& pc);
			bool	OnBuyItem(PC& pc);
			bool	OnSellItem(PC& pc);
			bool	OnCraftItem(PC& pc);
			bool	OnEmotion(PC& pc);
#endif
  
//shop.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	ch->SetQuestNPCID(ch->GetShopOwner() ? ch->GetShopOwner()->GetVID() : 0);
	quest::CQuestManager::instance().BuyItem(ch->GetPlayerID(), GetNPCVnum(), item);
#endif
  
//shop_manager.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	if (pkChr->GetShop())
		return false;
#endif

#ifdef ENABLE_NEW_QUEST_EVENTS
	CShop* pkShop = ch->GetShop();

	if (pkShop)
	{
		ch->SetQuestNPCID(ch->GetShopOwner() ? ch->GetShopOwner()->GetVID() : 0);
		quest::CQuestManager::instance().SellItem(ch->GetPlayerID(), pkShop->GetNPCVnum(), item);
	}
#endif
  
//service.h
#define ENABLE_NEW_QUEST_EVENTS
  

//quest
quest new_event_test begin
	state start begin
		when mine begin
			notice("You are mining.")
		end

		when fish begin
			notice("You are fishing.")
		end

		when 20018.craft begin -- Baek-Go NPC
			notice(string.format("You have crafted something from NPC %d", npc.get_race()))
			notice(string.format("You crafted item %d", item.get_vnum()))
		end

		when 9003.buy begin
			notice(string.format("You have bought something from NPC %d", npc.get_race()))
			notice(string.format("You bought item %d", item.get_vnum()))
		end

		when 9003.sell begin
			notice(string.format("You have sold something to NPC %d", npc.get_race()))
			notice(string.format("You sold item %d", item.get_vnum()))
		end

		when emotion begin
			notice("HandleReceiveAllEvent")
			if npc.is_pc() then
				notice(string.format("You are emoting / acting with %s", pc.get_name()))
			else
				notice("You are emoting / acting alone.")
			end
		end
	end
end

Do you have some ideas why it doesn't work? Is there another person who tested the notice output when you start the mine event?

Thanks for possible suggestions, corrections.

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154585
Share on other sites

  • Active+ Member
21 minutes ago, WeedHex said:

You changed the macro's name, be sure on visual studio with CTRL+SHIFT+F.

Check the spoiler, it's directly copied from the files, which I edited.

21 minutes ago, WeedHex said:

Try to change on lua notice() to chat()

Already tried and still 0 output when the mine event starts.

Edited by ReFresh

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154588
Share on other sites

  • Honorable Member
On 1/21/2023 at 6:15 PM, ReFresh said:

Check the spoiler, it's directly copied from the files, which I edited.

Already tried and still 0 output when the mine event starts.

Try to rename the event to another thing for example, "minning".
Also, try to see if you have any npc called "mine" in npclist.txt

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154643
Share on other sites

  • Active+ Member
20 hours ago, Owsap said:

Try to rename the event to another thing for example, "minning".

I tried to rename to minning. It had no effect.

20 hours ago, Owsap said:

Also, try to see if you have any npc called "mine" in npclist.txt

No mines were found in npclist.txt

Exist some way how to debug it, to find why it's not working?

  • Good 1

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-154662
Share on other sites

  • 1 month later...
  • 1 month later...
On 1/21/2023 at 8:15 PM, ReFresh said:

Check the spoiler, it's directly copied from the files, which I edited.

Already tried and still 0 output when the mine event starts.

In test mode there's an error message:

Quote

HandleReceiveAllEvent: QUEST There's suspended quest state, can't run new quest state (quest: mining pc: Admin)

Btw since the pc.mining() triggers the mining event (from the quest) you don't need to create a new  event for it, you can run your code directly from mining.quest ?

Here is an example what i am talking about:

new_event_test.quest

quest new_event_test begin
	state start begin
		function mine()
			notice("You are mining :)")
		end
		when fish begin
				...

mining.quest

		...
		when 20047.click or 20048.click or 20049.click or 20050.click or 20051.click or 20052.click
			or 20053.click or 20054.click or 20055.click or 20056.click or 20057.click or 20058.click 
			or 20059.click or 30301.click or 30302.click or 30303.click or 30304.click or 30305.click 
		begin
			if pc.is_mount() != true then
				new_event_test.mine()
				pc.mining()
			end
		end
		...

You have to add new_event_test.mine to quest_functions, and it works like a charm ?

Edited by ATAG
  • Metin2 Dev 1
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-156876
Share on other sites

  • 1 month later...
On 1/21/2023 at 8:03 PM, ReFresh said:

I followed the github tutorial again to check for possible mistakes and no mistakes were found. The mine event still doesn't work. I can't see any reason why it doesn't work. No errors, syssers, syslogs... Everything is added correctly and I still can't get the notice output when I start the mine event. It's only the mine event, so it's really weird. Looks like I'm the only one who added and completely tested these events.

Here I can prove that everything is added correctly:

  Reveal hidden contents
//cmd_emotion.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
#include "questmanager.h"
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
	ch->SetQuestNPCID(victim ? victim->GetVID() : 0);
	quest::CQuestManager::instance().Emotion(ch->GetPlayerID(), victim ? victim->GetRaceNum() : quest::QUEST_NO_NPC);
#endif
  
//cube.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
#include "questmanager.h"
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
		ch->SetQuestNPCID(npc->GetVID());
		quest::CQuestManager::instance().CraftItem(ch->GetPlayerID(), npc->GetRaceNum(), new_item);
#endif
  
//char.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	quest::CQuestManager::instance().Mine(GetPlayerID());
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
	quest::CQuestManager::instance().Fish(GetPlayerID());
#endif
  
//quest.h
#ifdef ENABLE_NEW_QUEST_EVENTS
		QUEST_FISH_EVENT,
		QUEST_MINE_EVENT,
		QUEST_ITEM_BUY_EVENT,
		QUEST_ITEM_SELL_EVENT,
		QUEST_ITEM_CRAFT_EVENT,
		QUEST_EMOTION_EVENT,
#endif
  
//questmanager.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
		m_mapEventName.insert(TEventNameMap::value_type("fish", QUEST_FISH_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("mine", QUEST_MINE_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("buy", QUEST_ITEM_BUY_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("sell", QUEST_ITEM_SELL_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("craft", QUEST_ITEM_CRAFT_EVENT));
		m_mapEventName.insert(TEventNameMap::value_type("emotion", QUEST_EMOTION_EVENT));
#endif
  
#ifdef ENABLE_NEW_QUEST_EVENTS
	void CQuestManager::Fish(unsigned int pc)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			m_mapNPC[QUEST_NO_NPC].OnFish(*pPC);
		}
		else
		{
			sys_err("QUEST FISH_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::Mine(unsigned int pc)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			m_mapNPC[QUEST_NO_NPC].OnMine(*pPC);
		}
		else
		{
			sys_err("QUEST MINE_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::BuyItem(unsigned int pc, unsigned int npc, LPITEM item)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
			{
				LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc);
				if (ch)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Quests aren't loaded."));
				}
				return;
			}

			SetCurrentItem(item);

			if (npc != QUEST_NO_NPC)
				m_mapNPC[npc].OnBuyItem(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnBuyItem(*pPC);
		}
		else
		{
			sys_err("QUEST ITEM_BUY_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::SellItem(unsigned int pc, unsigned int npc, LPITEM item)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
			{
				LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc);
				if (ch)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Quests aren't loaded."));
				}
				return;
			}

			SetCurrentItem(item);

			if (npc != QUEST_NO_NPC)
				m_mapNPC[npc].OnSellItem(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnSellItem(*pPC);
		}
		else
		{
			sys_err("QUEST ITEM_SELL_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::CraftItem(unsigned int pc, unsigned int npc, LPITEM item)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
			{
				LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc);
				if (ch)
				{
					ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Quests aren't loaded."));
				}
				return;
			}

			SetCurrentItem(item);

			if (npc != QUEST_NO_NPC)
				m_mapNPC[npc].OnCraftItem(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnCraftItem(*pPC);
		}
		else
		{
			sys_err("QUEST ITEM_CRAFT_EVENT no such pc id : %d", pc);
		}
	}

	void CQuestManager::Emotion(unsigned int pc, unsigned int target)
	{
		PC* pPC;
		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			if (target != QUEST_NO_NPC)
				m_mapNPC[target].OnEmotion(*pPC);

			m_mapNPC[QUEST_NO_NPC].OnEmotion(*pPC);
		}
		else
		{
			sys_err("QUEST EMOTION_EVENT no such pc id : %d", pc);
		}
	}
#endif
  
//questmanager.h
#ifdef ENABLE_NEW_QUEST_EVENTS
			void		Fish(unsigned int pc);
			void		Mine(unsigned int pc);
			void		BuyItem(unsigned int pc, unsigned int npc, LPITEM item);
			void		SellItem(unsigned int pc, unsigned int npc, LPITEM item);
			void		CraftItem(unsigned int pc, unsigned int npc, LPITEM item);
			void		Emotion(unsigned int pc, unsigned int target);
#endif

//questnpc.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	bool NPC::OnFish(PC& pc)
	{
		return HandleReceiveAllEvent(pc, QUEST_FISH_EVENT);
	}

	bool NPC::OnMine(PC& pc)
	{
		return HandleReceiveAllEvent(pc, QUEST_MINE_EVENT);
	}

	bool NPC::OnBuyItem(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_ITEM_BUY_EVENT);
		else
			return HandleEvent(pc, QUEST_ITEM_BUY_EVENT);
	}

	bool NPC::OnSellItem(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_ITEM_SELL_EVENT);
		else
			return HandleEvent(pc, QUEST_ITEM_SELL_EVENT);
	}

	bool NPC::OnCraftItem(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_ITEM_CRAFT_EVENT);
		else
			return HandleEvent(pc, QUEST_ITEM_CRAFT_EVENT);
	}

	bool NPC::OnEmotion(PC& pc)
	{
		if (m_vnum == 0)
			return HandleReceiveAllEvent(pc, QUEST_EMOTION_EVENT);
		else
			return HandleEvent(pc, QUEST_EMOTION_EVENT);
	}
#endif
  
//questnpc.h
#ifdef ENABLE_NEW_QUEST_EVENTS
			bool	OnFish(PC& pc);
			bool	OnMine(PC& pc);
			bool	OnBuyItem(PC& pc);
			bool	OnSellItem(PC& pc);
			bool	OnCraftItem(PC& pc);
			bool	OnEmotion(PC& pc);
#endif
  
//shop.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	ch->SetQuestNPCID(ch->GetShopOwner() ? ch->GetShopOwner()->GetVID() : 0);
	quest::CQuestManager::instance().BuyItem(ch->GetPlayerID(), GetNPCVnum(), item);
#endif
  
//shop_manager.cpp
#ifdef ENABLE_NEW_QUEST_EVENTS
	if (pkChr->GetShop())
		return false;
#endif

#ifdef ENABLE_NEW_QUEST_EVENTS
	CShop* pkShop = ch->GetShop();

	if (pkShop)
	{
		ch->SetQuestNPCID(ch->GetShopOwner() ? ch->GetShopOwner()->GetVID() : 0);
		quest::CQuestManager::instance().SellItem(ch->GetPlayerID(), pkShop->GetNPCVnum(), item);
	}
#endif
  
//service.h
#define ENABLE_NEW_QUEST_EVENTS
  

//quest
quest new_event_test begin
	state start begin
		when mine begin
			notice("You are mining.")
		end

		when fish begin
			notice("You are fishing.")
		end

		when 20018.craft begin -- Baek-Go NPC
			notice(string.format("You have crafted something from NPC %d", npc.get_race()))
			notice(string.format("You crafted item %d", item.get_vnum()))
		end

		when 9003.buy begin
			notice(string.format("You have bought something from NPC %d", npc.get_race()))
			notice(string.format("You bought item %d", item.get_vnum()))
		end

		when 9003.sell begin
			notice(string.format("You have sold something to NPC %d", npc.get_race()))
			notice(string.format("You sold item %d", item.get_vnum()))
		end

		when emotion begin
			notice("HandleReceiveAllEvent")
			if npc.is_pc() then
				notice(string.format("You are emoting / acting with %s", pc.get_name()))
			else
				notice("You are emoting / acting alone.")
			end
		end
	end
end

Do you have some ideas why it doesn't work? Is there another person who tested the notice output when you start the mine event?

Thanks for possible suggestions, corrections.

i have the same problem , did u find a fix?

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-157596
Share on other sites

  • 1 year later...
  • Active+ Member

I just tested that and the guy is right:

On 4/12/2023 at 1:27 AM, ATAG said:

Btw since the pc.mining() triggers the mining event (from the quest) you don't need to create a new  event for it, you can run your code directly from mining.quest ?

Here is an example what i am talking about:

new_event_test.quest

quest new_event_test begin
	state start begin
		function mine()
			notice("You are mining :)")
		end
		when fish begin
				...

mining.quest

		...
		when 20047.click or 20048.click or 20049.click or 20050.click or 20051.click or 20052.click
			or 20053.click or 20054.click or 20055.click or 20056.click or 20057.click or 20058.click 
			or 20059.click or 30301.click or 30302.click or 30303.click or 30304.click or 30305.click 
		begin
			if pc.is_mount() != true then
				new_event_test.mine()
				pc.mining()
			end
		end
		...

You have to add new_event_test.mine to quest_functions, and it works like a charm ?

Exist some other way how to make it working trough the source without editing the quest and then use it like the author of this topic said? We know we have to call it before pc.mining() is called, but what we have to change to make it working like that? I tried to move it higher before creating the event in source, but it didn't work.

Edited by ReFresh

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-169868
Share on other sites

21 hours ago, ReFresh said:

I just tested that and the guy is right:

Exist some other way how to make it working trough the source without editing the quest and then use it like the author of this topic said? We know we have to call it before pc.mining() is called, but what we have to change to make it working like that? I tried to move it higher before creating the event in source, but it didn't work.

Idk how to fix it in source, the quest “event handling” is too chaotic to me 🤣

Mining is a coroutine if i’m right, kind of child process, there’s no “pc is mining” in other quests… you can only trigger something before/after it

  • Lmao 1
Link to comment
https://metin2.dev/topic/30201-new-quest-events-triggers/#findComment-169876
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.