Skip to content

Commit

Permalink
Fix % HP bar not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 6, 2024
1 parent 00275b8 commit 51b5cbb
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions Fika.Core/Coop/Custom/FikaHealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ private void CreateHealthBar()
currentPlayer.HealthController.HealthChangedEvent += HealthController_HealthChangedEvent;
currentPlayer.HealthController.BodyPartDestroyedEvent += HealthController_BodyPartDestroyedEvent;
currentPlayer.HealthController.BodyPartRestoredEvent += HealthController_BodyPartRestoredEvent;

UpdateHealth();
}

private void HealthController_BodyPartRestoredEvent(EBodyPart arg1, EFT.HealthSystem.ValueStruct arg2)
Expand All @@ -217,32 +219,29 @@ private void HealthController_HealthChangedEvent(EBodyPart arg1, float arg2, Dam
/// </summary>
private void UpdateHealth()
{
if (playerPlate.healthBarScreen.gameObject.activeSelf)
float currentHealth = currentPlayer.HealthController.GetBodyPartHealth(EBodyPart.Common, true).Current;
float maxHealth = currentPlayer.HealthController.GetBodyPartHealth(EBodyPart.Common, true).Maximum;
if (FikaPlugin.UseHealthNumber.Value)
{
float currentHealth = currentPlayer.HealthController.GetBodyPartHealth(EBodyPart.Common, true).Current;
float maxHealth = currentPlayer.HealthController.GetBodyPartHealth(EBodyPart.Common, true).Maximum;
if (FikaPlugin.UseHealthNumber.Value)
if (!playerPlate.healthNumberBackgroundScreen.gameObject.activeSelf)
{
if (!playerPlate.healthNumberBackgroundScreen.gameObject.activeSelf)
{
playerPlate.healthNumberBackgroundScreen.gameObject.SetActive(true);
playerPlate.healthBarBackgroundScreen.gameObject.SetActive(false);
}
int healthNumberPercentage = (int)Math.Round((currentHealth / maxHealth) * 100);
playerPlate.SetHealthNumberText($"{healthNumberPercentage}%");
playerPlate.healthNumberBackgroundScreen.gameObject.SetActive(true);
playerPlate.healthBarBackgroundScreen.gameObject.SetActive(false);
}
else
int healthNumberPercentage = (int)Math.Round((currentHealth / maxHealth) * 100);
playerPlate.SetHealthNumberText($"{healthNumberPercentage}%");
}
else
{
if (!playerPlate.healthBarBackgroundScreen.gameObject.activeSelf)
{
if (!playerPlate.healthBarBackgroundScreen.gameObject.active)
{
playerPlate.healthNumberBackgroundScreen.gameObject.SetActive(false);
playerPlate.healthBarBackgroundScreen.gameObject.SetActive(true);
}

float normalizedHealth = Mathf.Clamp01(currentHealth / maxHealth);
playerPlate.healthBarScreen.fillAmount = normalizedHealth;
UpdateHealthBarColor(normalizedHealth);
playerPlate.healthNumberBackgroundScreen.gameObject.SetActive(false);
playerPlate.healthBarBackgroundScreen.gameObject.SetActive(true);
}

float normalizedHealth = Mathf.Clamp01(currentHealth / maxHealth);
playerPlate.healthBarScreen.fillAmount = normalizedHealth;
UpdateHealthBarColor(normalizedHealth);
}
}

Expand Down

0 comments on commit 51b5cbb

Please sign in to comment.