From ba1da9afa246bd1e2702415cc33503d43cf13feb Mon Sep 17 00:00:00 2001 From: zaCade Date: Sun, 2 Mar 2025 10:25:42 +0100 Subject: [PATCH] [BossHP] Add boss health percentage display --- BossHP/scripting/BossHP.sp | 16 ++++++++++++++++ BossHP/scripting/include/BossHP/CBoss.inc | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/BossHP/scripting/BossHP.sp b/BossHP/scripting/BossHP.sp index da0db88b..f81885be 100644 --- a/BossHP/scripting/BossHP.sp +++ b/BossHP/scripting/BossHP.sp @@ -1314,6 +1314,7 @@ bool BossProcess(CBoss _Boss) bool bInvalid = false; int iHealth = 0; int iLastHealth = _Boss.iHealth; + int iMaxHealth = _Boss.iMaxHealth; int iLastChange = _Boss.iLastChange; if(_Boss.IsBreakable) @@ -1396,6 +1397,12 @@ bool BossProcess(CBoss _Boss) if(iHealth < 0) iHealth = 0; + if(iMaxHealth < iHealth) + { + iMaxHealth = iHealth; + _Boss.iMaxHealth = iHealth; + } + if(iHealth != iLastHealth) { iLastChange = GetTime(); @@ -1440,6 +1447,15 @@ bool BossProcess(CBoss _Boss) sFormat[FormatLen++] = ' '; FormatLen += IntToString(iHealth, sFormat[FormatLen], sizeof(sFormat) - FormatLen); + + sFormat[FormatLen++] = ' '; + sFormat[FormatLen++] = '['; + + FormatLen += IntToString(RoundToNearest(float(iHealth) / float(iMaxHealth) * 100), sFormat[FormatLen], sizeof(sFormat) - FormatLen); + + FormatLen += StrCat(sFormat[FormatLen], sizeof(sFormat) - FormatLen, "%%%%"); // No idea why this needs 4 percents, but it works. + + sFormat[FormatLen++] = ']'; sFormat[FormatLen] = 0; StrCat(g_sHUDText, sizeof(g_sHUDText), sFormat); diff --git a/BossHP/scripting/include/BossHP/CBoss.inc b/BossHP/scripting/include/BossHP/CBoss.inc index 577539b7..daae661e 100644 --- a/BossHP/scripting/include/BossHP/CBoss.inc +++ b/BossHP/scripting/include/BossHP/CBoss.inc @@ -15,6 +15,7 @@ methodmap CBoss < Basic myclass.SetBool("bShow", true); myclass.SetInt("iTemplateNum", -1); myclass.SetInt("iHealth", 0); + myclass.SetInt("iMaxHealth", 0); myclass.SetInt("iLastChange", 0); myclass.SetFloat("fWaitUntil", 0.0); myclass.SetFloat("fShowAt", 0.0); @@ -95,6 +96,18 @@ methodmap CBoss < Basic } } + property int iMaxHealth + { + public get() + { + return this.GetInt("iMaxHealth"); + } + public set(int value) + { + this.SetInt("iMaxHealth", value); + } + } + property int iLastChange { public get()