Jump to content

Character death event


Go to solution Solved by Zonni,

Recommended Posts

  • 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
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
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
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
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
Share on other sites

  • 10 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

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.