Jump to content

Event Handler For Client


Recommended Posts

  • Honorable Member

M2 Download Center

This is the hidden content, please
( Internal )

This is the hidden content, please
( GitHub )

An event handler without thread and sleep for client source. You can add many things etc.

Example:

		EventHandler::Instance().AddEvent("exampletest",[]() 
		{
			IAbstractChat::GetSingleton().AppendChat(CHAT_TYPE_INFO, "Test Message");
		}, 5, 10 ); // ten time, delay 5 sec.

 

  • Metin2 Dev 34
  • Think 1
  • Scream 1
  • Good 8
  • Love 1
  • Love 12

 

Link to comment
Share on other sites

7 hours ago, Mali61 said:

An event handler without thread and sleep for client source. You can add many things etc.

This is the hidden content, please

Example:


		EventHandler::Instance().AddEvent("exampletest",[]() 
		{
			IAbstractChat::GetSingleton().AppendChat(CHAT_TYPE_INFO, "Test Message");
		}, 5, 10 ); // ten time, delay 5 sec.

 

I don't fully understand what we can do with it.

  • Metin2 Dev 1
  • Good 1
Link to comment
Share on other sites

  • Honorable Member
59 minutes ago, glosteng4141 said:

I don't fully understand what we can do with it.

Think about like game src LPEVENT. For better understanding. I have add examples.

Example "You are active x minute in this map" message:

Spoiler

PythonNetworkStreamPhaseLoading.cpp add:


#if defined(CLIENT_PLAYTIME)
#include "EventHandler.h"
auto SendMessageEvent()
{
	const auto &hndl = EventHandler::Instance().GetHandler("PlayMessage");
	if (!hndl)
		return;
	char msg[128];
	int count = hndl->get()->bind;
	_snprintf(msg, sizeof(msg), "You are active %d minute(s) in this map!", count);
	if (count)
		IAbstractChat::GetSingleton().AppendChat(CHAT_TYPE_INFO, msg);
}
#endif

//Find:


__SendInternalBuffer();

///Add


#if defined(CLIENT_PLAYTIME)
	EventHandler::Instance().AddEvent("PlayMessage", std::bind(&SendMessageEvent), 60, -1); // 60-> 1 min, -1 ->endless event
	//EventHandler::Instance().AddEvent("PlayMessage", [&] {SendMessageEvent; }, 60, -1); // 60-> 1 min, -1 ->endless event
#endif

 

Result:

Ekran-Al-nt-s.png

Edited by Metin2 Dev
Core X - External 2 Internal

 

Link to comment
Share on other sites

30 minutes ago, Mali61 said:

Think about like game src LPEVENT. For better understanding. I have add examples.

Example "You are active x minute in this map" message:

  Hide contents

PythonNetworkStreamPhaseLoading.cpp add:



#if defined(CLIENT_PLAYTIME)
#include "EventHandler.h"
auto SendMessageEvent()
{
	const auto &hndl = EventHandler::Instance().GetHandler("PlayMessage");
	if (!hndl)
		return;
	char msg[128];
	int count = hndl->get()->bind;
	_snprintf(msg, sizeof(msg), "You are active %d minute(s) in this map!", count);
	if (count)
		IAbstractChat::GetSingleton().AppendChat(CHAT_TYPE_INFO, msg);
}
#endif

//Find:



__SendInternalBuffer();

///Add



#if defined(CLIENT_PLAYTIME)
	EventHandler::Instance().AddEvent("PlayMessage", std::bind(&SendMessageEvent), 60, -1); // 60-> 1 min, -1 ->endless event
	//EventHandler::Instance().AddEvent("PlayMessage", [&] {SendMessageEvent; }, 60, -1); // 60-> 1 min, -1 ->endless event
#endif

 

Result:

Ekran-Al-nt-s.png

Thank you bro ❤️

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
Share on other sites

Announcements



×
×
  • 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.