Jump to content
×
×
  • Create New...
  • 0

Question about delay of death


Klaus

Question

One problem I face is the delay for the player to actually die, in the example below, I took the total damage from the player and there is a delay until he actually dies. In wars, where kills are counted, I often kill a player and another character steals the "kill", is there any way to solve this problem?

115718New-Project.gif

Thank you for your attention!

Link to comment

8 answers to this question

Recommended Posts

  • 1

char.cpp --> remove that:

m_dwKillerPID = 0;

char.h --> remove that:

DWORD				m_dwKillerPID;

 

char_battle.cpp --> remove/change that:

if (!pkKiller && m_dwKillerPID)
		pkKiller = CHARACTER_MANAGER::instance().FindByPID(m_dwKillerPID);

	m_dwKillerPID = 0;

change that:

if (GetHP() <= 0)
	{
		Stun();

		if (pAttacker && !pAttacker->IsNPC())
			m_dwKillerPID = pAttacker->GetPlayerID();
		else
			m_dwKillerPID = 0;
	}

to this:

if (GetHP() <= 0)
	{
		Dead(pAttacker);
	}

 

Edited by DrTurk
  • Love 1
Link to comment
  • 0
5 hours ago, DrTurk said:

char.cpp --> remove that:

m_dwKillerPID = 0;

char.h --> remove that:

DWORD				m_dwKillerPID;

 

char_battle.cpp --> remove/change that:

if (!pkKiller && m_dwKillerPID)
		pkKiller = CHARACTER_MANAGER::instance().FindByPID(m_dwKillerPID);

	m_dwKillerPID = 0;

change that:

if (GetHP() <= 0)
	{
		Stun();

		if (pAttacker && !pAttacker->IsNPC())
			m_dwKillerPID = pAttacker->GetPlayerID();
		else
			m_dwKillerPID = 0;
	}

to this:

if (GetHP() <= 0)
	{
		Dead(pAttacker);
	}

 

Solved! (Is there any risk of causing an error/bug?)

Link to comment
  • 0
On 6/12/2021 at 12:56 PM, DrTurk said:

Had two servers with that change, didnt experienced any bugs

I just tried your code edits and it has at least one bug with removing char affect like poison. Try to kill the player with ninja char skill Poisoned Arrow, player will die with poison affect on yourself.

I tried to call Dead(); function instead of your changes, but there is still the same bug with affects. Dead(); is not removing the poison, bleed, etc. affects. I couldn't find differences between why Stun(); function removing the affects correctly and Dead(); function not.

Spoiler
if (GetHP() <= 0)
	{
		Stun(); or Dead(); can be called but only Stun(); removing the affects before death correctly

		if (pAttacker && !pAttacker->IsNPC())
			m_dwKillerPID = pAttacker->GetPlayerID();
		else
			m_dwKillerPID = 0;
	}

return false;

 

Would be really nice if someone can solve this problem.

Edited by ReFresh
Link to comment
  • 0
12 hours ago, ReFresh said:

I just tried your code edits and it has at least one bug with removing char affect like poison. Try to kill the player with ninja char skill Poisoned Arrow, player will die with poison affect on yourself.

I tried to call Dead(); function instead of your changes, but there is still the same bug with affects. Dead(); is not removing the poison, bleed, etc. affects. I couldn't find differences between why Stun(); function removing the affects correctly and Dead(); function not.

  Hide contents
if (GetHP() <= 0)
	{
		Stun(); or Dead(); can be called but only Stun(); removing the affects before death correctly

		if (pAttacker && !pAttacker->IsNPC())
			m_dwKillerPID = pAttacker->GetPlayerID();
		else
			m_dwKillerPID = 0;
	}

return false;

 

Would be really nice if someone can solve this problem.

Isnt that a normal m2 problem with bleed/poison/fire when you one shot someone with it?

I fixxed this before i did this change.

 

Just add

	if (ch->IsDead())
	{
		ch->RemovePoison();
	}

like that:

EVENTFUNC(poison_event)
{
	TPoisonEventInfo * info = dynamic_cast<TPoisonEventInfo *>( event->info );
	
	if ( info == NULL )
	{
		sys_err( "poison_event> <Factor> Null pointer" );
		return 0;
	}

	LPCHARACTER ch = info->ch;

	if (ch == NULL) 
	{
		return 0;
	}
	LPCHARACTER pkAttacker = CHARACTER_MANAGER::instance().FindByPID(info->attacker_pid);

	if (ch->IsDead())
	{
		ch->RemovePoison();
	}

	int dam = ch->GetMaxHP() * GetPoisonDamageRate(ch) / 1000;
	if (test_server) ch->ChatPacket(CHAT_TYPE_NOTICE, "Poison Damage %d", dam);

	if (ch->Damage(pkAttacker, dam, DAMAGE_TYPE_POISON))
	{
		ch->m_pkPoisonEvent = NULL;
		return 0;
	}

	--info->count;

	if (info->count)
		return PASSES_PER_SEC(3);
	else
	{
		ch->m_pkPoisonEvent = NULL;
		return 0;
	}
}

 

same thing with fire:

EVENTFUNC(fire_event)
{
	TFireEventInfo * info = dynamic_cast<TFireEventInfo *>( event->info );

	if ( info == NULL )
	{
		sys_err( "fire_event> <Factor> Null pointer" );
		return 0;
	}

	LPCHARACTER ch = info->ch;
	if (ch == NULL) 
	{
		return 0;
	}
	LPCHARACTER pkAttacker = CHARACTER_MANAGER::instance().FindByPID(info->attacker_pid);

	if (ch->IsDead())
	{
		ch->RemoveFire();
	}

	int dam = info->amount;
	if (test_server) ch->ChatPacket(CHAT_TYPE_NOTICE, "Fire Damage %d", dam);

	if (ch->Damage(pkAttacker, dam, DAMAGE_TYPE_FIRE))
	{
		ch->m_pkFireEvent = NULL;
		return 0;
	}

	--info->count;

	if (info->count)
		return PASSES_PER_SEC(3);
	else
	{
		ch->m_pkFireEvent = NULL;
		return 0;
	}
}

 

Link to comment
  • 0

@DrTurk Thanks I'll try. But why did you remove that functions instead of calling Dead(); function? It should be the same thing as we call the Stun(); am I right? But mystery is why Stun(); function is able to remove these affects without editing something.

Edited by ReFresh
Link to comment
  • 0
25 minutes ago, ReFresh said:

@DrTurk Thanks I'll try. But why did you remove that functions instead of calling Dead(); function? It should be the same thing as we call the Stun(); am I right? But mystery is why Stun(); function is able to remove these affects without editing something.

as i said i had this problem even before i modifyed the dead function, but only when you one shot someone with a poison skill.

i can redo my dead function modify and it will also bug when killed with one shot which has 100% poison rate

Link to comment
  • 0
On 8/3/2021 at 3:49 PM, DrTurk said:

as i said i had this problem even before i modifyed the dead function, but only when you one shot someone with a poison skill.

i can redo my dead function modify and it will also bug when killed with one shot which has 100% poison rate

Just call Dead(); instad of Stun(); and do the changes to affect events like you did, then change this:

Spoiler

m_pkDeadEvent = event_create(dead_event, pEventInfo, bImmediateDead ? 1 : PASSES_PER_SEC(3));

To this:

Spoiler

m_pkDeadEvent = event_create(dead_event, pEventInfo, bImmediateDead ? 1 : PASSES_PER_SEC(0));

And you are done, I think you don't need to remove something from source, just use the functions which are already done.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


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.