From 1acc685861d0688df67f7388e32ed9ba083623ce Mon Sep 17 00:00:00 2001 From: Fierelier Date: Sun, 20 May 2018 07:41:31 +0200 Subject: [PATCH] Pseudo-float regeneration of armor --- scripts/paydayHealth.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/paydayHealth.cs b/scripts/paydayHealth.cs index fd3291d..ad3b9dc 100644 --- a/scripts/paydayHealth.cs +++ b/scripts/paydayHealth.cs @@ -18,8 +18,8 @@ namespace pdHealth //SETTINGS //Regeneration int armorRegen = 25; //How far to regenerate the armor. Set to 0 to disable regenaration entirely. - int armorRegenSpeed = 1; //How much armor to regenerate per second. - int armorRegenDelay = 5000; //Delay after damage before recharging armor. Set to 0 to disable delay. + float armorRegenSpeed = 5f; //How much armor to regenerate per second. + float armorRegenDelay = 5f; //Delay after damage before recharging armor. Set to 0 to disable delay. //Max Armor/Health int overrideHealth = 50; //Set your max health to balance the regenerating armor. Values over 100 don't do anything (unless max health is altered by a trainer). Set to -1 to use default health. @@ -32,7 +32,8 @@ namespace pdHealth //VARIABLES (DO NOT TOUCH) int armorVal = -1; int healthVal = -1; - int timeUntilRegen = 0; + float timeUntilRegen = 0.0f; + float armorDecimalRegen = 0.0f; private void doHealthTick(object sender, EventArgs e) { @@ -51,7 +52,8 @@ namespace pdHealth if (pl.isAlive == false) { armorVal = -1; healthVal = -1; - timeUntilRegen = 0; + timeUntilRegen = 0.0f; + armorDecimalRegen = 0.0f; return; } @@ -75,15 +77,20 @@ namespace pdHealth } if (armorRegen > 0) { - if (pl.Armor < armorVal) { timeUntilRegen = armorRegenDelay; } - if (pl.Health < healthVal) { timeUntilRegen = armorRegenDelay; } + if (pl.Armor < armorVal) { armorDecimalRegen = 0.0f; timeUntilRegen = armorRegenDelay; } + if (pl.Health < healthVal) { armorDecimalRegen = 0.0f; timeUntilRegen = armorRegenDelay; } if (timeUntilRegen > 0) { - timeUntilRegen = timeUntilRegen - 17; + timeUntilRegen = timeUntilRegen - ((1000.0f/GTA.Game.FPS)/1000.0f); if (timeUntilRegen < 0) { timeUntilRegen = 0; } } else { if (pl.Armor < armorRegen) { - pl.Armor = pl.Armor + armorRegenSpeed; + armorDecimalRegen = armorDecimalRegen + (((1000.0f/GTA.Game.FPS)*armorRegenSpeed)/1000.0f); + while (armorDecimalRegen >= 1.0f) { + pl.Armor = pl.Armor + 1; + armorDecimalRegen = armorDecimalRegen - 1.0f; + } + if (pl.Armor > armorRegen) { pl.Armor = armorRegen; } } } @@ -91,6 +98,7 @@ namespace pdHealth armorVal = pl.Armor; healthVal = pl.Health; + Game.DisplayText("Armor:\n " +pl.Armor.ToString(), 1000); } } } \ No newline at end of file