Skip to content

Fix NPC damage condition#246

Open
ShadowDash2000 wants to merge 1 commit into
Facepunch:mainfrom
ShadowDash2000:npc-health-damage
Open

Fix NPC damage condition#246
ShadowDash2000 wants to merge 1 commit into
Facepunch:mainfrom
ShadowDash2000:npc-health-damage

Conversation

@ShadowDash2000

Copy link
Copy Markdown

There is a chance that the OnDamage() method can be called twice (or more). For example, in the CombatNpc component this may cause a repeat call of Speech.Say() and Die() methods. So, I added an early return condition if NPC's health is below 1.
The Player component is already does this in OnDamage() method:

public void OnDamage( in DamageInfo dmg )
	{
		if ( Health < 1 ) return;
		if ( !PlayerData.IsValid() ) return;
		if ( PlayerData.IsGodMode ) return;
...

I think that Health should ideally be a separate component to avoid repetitive code. Like this one, which I've implemented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant