Added health-regeneration

This commit is contained in:
Fierelier 2018-05-21 16:43:52 +02:00
parent c310e17754
commit b385983a6e
1 changed files with 52 additions and 21 deletions

View File

@ -9,21 +9,25 @@ namespace pdHealth
{
public class pdHealth : Script
{
public pdHealth()
{
this.Tick += new EventHandler(this.doHealthTick);
}
//SETTINGS
//Regeneration
int armorRegen = 25; //How far to regenerate the armor. Set to 0 to disable regenaration entirely.
//Armor Regeneration
int armorRegen = 25; //How far to regenerate the armor. Set to 0 to disable armor-regenaration entirely.
float armorRegenSpeed = 10f; //How much armor to regenerate per second.
float armorRegenDelay = 5f; //Delay after damage before recharging armor. Set to 0 to disable delay.
float armorRegenDelay = 5f; //Delay after damage before recharging armor. Set to 0 to disable delay.
//Health Regeneration
int healthRegen = 0; //How far to regenerate health. Set to 0 to disable health-regenaration entirely.
float healthRegenSpeed = 0.2f; //How much health to regenerate per second.
float healthRegenDelay = 30f; //Delay after damage before recharging health. 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.
int overrideArmor = -1; //Set your max armor. Basically the same as above.
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.
//Other armor options
bool allDamageArmor = true; //The armor soaks up all the damage, even fall and explosion-damage.
@ -32,8 +36,10 @@ namespace pdHealth
//VARIABLES (DO NOT TOUCH)
int armorVal = -1;
int healthVal = -1;
float timeUntiArmorlRegen = 0.0f;
float timeUntilArmorRegen = 0.0f;
float armorDecimalRegen = 0.0f;
float timeUntilHealthRegen = 0.0f;
float healthDecimalRegen = 0.0f;
private void doHealthTick(object sender, EventArgs e)
{
@ -52,8 +58,10 @@ namespace pdHealth
if (pl.isAlive == false) {
armorVal = -1;
healthVal = -1;
timeUntiArmorlRegen = 0.0f;
timeUntilArmorRegen = 0.0f;
armorDecimalRegen = 0.0f;
timeUntilHealthRegen = 0.0f;
healthDecimalRegen = 0.0f;
return;
}
@ -76,22 +84,45 @@ namespace pdHealth
}
}
if (armorRegen > 0) {
if (pl.Armor < armorVal) { armorDecimalRegen = 0.0f; timeUntiArmorlRegen = armorRegenDelay; }
if (pl.Health < healthVal) { armorDecimalRegen = 0.0f; timeUntiArmorlRegen = armorRegenDelay; }
if (armorRegen > 0 || healthRegen > 0) {
if (pl.Armor < armorVal || pl.Health < healthVal) {
armorDecimalRegen = 0.0f;
timeUntilArmorRegen = armorRegenDelay;
healthDecimalRegen = 0.0f;
timeUntilHealthRegen = healthRegenDelay;
}
if (timeUntiArmorlRegen > 0) {
timeUntiArmorlRegen = timeUntiArmorlRegen - ((1000.0f/GTA.Game.FPS)/1000.0f);
if (timeUntiArmorlRegen < 0) { timeUntiArmorlRegen = 0; }
} else {
if (pl.Armor < armorRegen) {
armorDecimalRegen = armorDecimalRegen + (((1000.0f/GTA.Game.FPS)*armorRegenSpeed)/1000.0f);
while (armorDecimalRegen >= 1.0f) {
pl.Armor = pl.Armor + 1;
armorDecimalRegen = armorDecimalRegen - 1.0f;
if (armorRegen > 0) {
if (timeUntilArmorRegen > 0) {
timeUntilArmorRegen = timeUntilArmorRegen - ((1000.0f/GTA.Game.FPS)/1000.0f);
if (timeUntilArmorRegen < 0) { timeUntilArmorRegen = 0; }
} else {
if (pl.Armor < armorRegen) {
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; }
}
}
}
if (healthRegen > 0) {
if (timeUntilHealthRegen > 0) {
timeUntilHealthRegen = timeUntilHealthRegen - ((1000.0f/GTA.Game.FPS)/1000.0f);
if (timeUntilHealthRegen < 0) { timeUntilHealthRegen = 0; }
} else {
if (pl.Health < healthRegen) {
healthDecimalRegen = healthDecimalRegen + (((1000.0f/GTA.Game.FPS)*healthRegenSpeed)/1000.0f);
while (healthDecimalRegen >= 1.0f) {
pl.Health = pl.Health + 1;
healthDecimalRegen = healthDecimalRegen - 1.0f;
}
if (pl.Health > healthRegen) { pl.Health = healthRegen; }
}
if (pl.Armor > armorRegen) { pl.Armor = armorRegen; }
}
}
}