Jump to content

Character death event


Go to solution Solved by Zonni,

Recommended Posts

Is there a way to make a function to do this in quests?
 

when (player_die) begin
   -- Stuff to do when player_die event is triggered
end

lot of people say me to use a timer and to check pc.is_death, but i think this is not a correct solution..

Hope someone can help me :)

Thanks,

Lup.

Link to comment
https://metin2.dev/topic/5362-character-death-event/
Share on other sites

already exist a functions called pc.is_death, i have to check it every X seconds with a timer..

I Think working on game source we can make a better solution that trigger "death" event automatically so in quest we can use

 

when die begin
  -- Some stuff
End

Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-33773
Share on other sites

  • Premium
  • Solution

questmanager.cpp

- in bool CQuestManager::Initialize() add

m_mapEventName.insert(TEventNameMap::value_type("dead", QUEST_DEAD_EVENT));

 

- add

void CQuestManager::Dead(unsigned int pc, unsigned int npc)
{
PC * pPC;
 
sys_log(0, "CQuestManager::OnDead QUEST_DEAD_EVENT (pc=%d, npc=%d)", pc, npc);
 
if ((pPC = GetPC(pc)))
{
if (!CheckQuestLoaded(pPC))
return;
m_mapNPC[npc].OnDead(*pPC);
 
if (m_mapNPC[QUEST_NO_NPC].OnDead(*pPC))
return;
}
else
sys_err("QUEST: no such pc id : %d", pc);
}

 

quest.h

[second enum] (add after QUEST_ITEM_INFORMER_EVENT,)

QUEST_DEAD_EVENT,

 

questnpc.h

bool NPC::OnDead(PC & pc)
{
if (m_vnum)
return HandleEvent(pc, QUEST_DEAD_EVENT);
else
return HandleReceiveAllEvent(pc, QUEST_DEAD_EVENT);
}
 
char_battle.cpp
in CHARACTER::Dead add
if(pkKiller && IsPC()) {
pkKiller->SetQuestNPCID(GetVID());
quest::CQuestManager::instance().Dead(GetPlayerID(), pkKiller->GetPlayerID());
}

 

 

sorry for format but it should work if you add missing functions in .h files

 

btw. that's not my work, anyway it's really easy to create events like this.

  • Love 2
Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-33872
Share on other sites

Thanks for you help Zonni, i have just a little problem:

The event is triggeret 2 times, i try to explain better:

when dead begin
	syschat("You are death.")
end

I will get the text "You are death" 2 times.

 

Any ideas about?

 

In the code you give to me i dont understand this part : 

m_mapNPC[npc].OnDead(*pPC);
		 
if (m_mapNPC[QUEST_NO_NPC].OnDead(*pPC))
	return;
Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-33925
Share on other sites

You could do it with npc.get_vid()

quest dead begin
	state start begin
		when kill with npc.is_pc() begin
			local vid = npc.get_vid()
			local old_pc = pc.select(vid)
			if old_pc != 0 then
				chat("You die")
				pc.select(old_pc)
			end
		end
	end
end
Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-33936
Share on other sites

 

You could do it with npc.get_vid()

quest dead begin
	state start begin
		when kill with npc.is_pc() begin
			local vid = npc.get_vid()
			local old_pc = pc.select(vid)
			if old_pc != 0 then
				chat("You die")
				pc.select(old_pc)
			end
		end
	end
end

I Think this is not correct, the quest name is "dead" but you use the kill event..

All writed by Zonni is working good, but there is a bug, that the event "dead" is called two times, maybe is the same bug as "kill" counted twiche, i'll investigate on it and let you know

Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-34018
Share on other sites

  • Premium

I just recompiled whole source & quest and this works without any problem ^^

 

btw. i think you should correct your tabs :D (sorry, i know i give to you badly format of code but i haven't so much time to correct whitespaces)

 

	void CQuestManager::Dead(unsigned int pc, unsigned int npc)
	{
		PC * pPC;

		sys_log(0, "CQuestManager::OnDead QUEST_DEAD_EVENT (pc=%d, npc=%d)", pc, npc);

		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;
			m_mapNPC[npc].OnDead(*pPC);

			if (m_mapNPC[QUEST_NO_NPC].OnDead(*pPC))
				return;
		}
		else
			sys_err("QUEST: no such pc id : %d", pc);
	}
should work. :)
  • Love 1
Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-34024
Share on other sites

I just recompiled whole source & quest and this works without any problem ^^

 

btw. i think you should correct your tabs :D (sorry, i know i give to you badly format of code but i haven't so much time to correct whitespaces)

 

	void CQuestManager::Dead(unsigned int pc, unsigned int npc)
	{
		PC * pPC;

		sys_log(0, "CQuestManager::OnDead QUEST_DEAD_EVENT (pc=%d, npc=%d)", pc, npc);

		if ((pPC = GetPC(pc)))
		{
			if (!CheckQuestLoaded(pPC))
				return;
			m_mapNPC[npc].OnDead(*pPC);

			if (m_mapNPC[QUEST_NO_NPC].OnDead(*pPC))
				return;
		}
		else
			sys_err("QUEST: no such pc id : %d", pc);
	}
should work. :)

 

 

I have the problem explained with your code and i fixed it using this :

	void CQuestManager::Dead(unsigned int pc, unsigned int npc)
	{
		PC * pPC;
		sys_log(0, "CQuestManager::OnDead QUEST_DEAD_EVENT (pc=%d, npc=%d)", pc, npc);
		if (pPC = GetPC(pc))
		{
			if (!CheckQuestLoaded(pPC))
				return;

			if(npc > 0)
				m_mapNPC[npc].OnDead(*pPC);
			
			if (m_mapNPC[QUEST_NO_NPC].OnDead(*pPC))
				return;
		}
		else
			sys_err("QUEST: no such pc id : %d", pc);
	}

Anyway i really thank you for your reply on a my request and now i have learned something new :)

Thank 's you again,

Lup.

  • Love 1
Link to comment
https://metin2.dev/topic/5362-character-death-event/#findComment-34027
Share on other sites

  • 10 months later...

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.