iv-pdhealth/scripts/paydayHealth.cs

134 lines
4.4 KiB
C#
Raw Normal View History

2018-05-15 09:38:25 +00:00
//Payday Health Script 1.0 by Fierelier
//Donate: https://www.paypal.me/Fierelier/
2018-04-17 19:16:20 +00:00
using System;
using System.Windows.Forms;
using GTA;
namespace pdHealth
{
public class pdHealth : Script
{
public pdHealth()
{
this.Tick += new EventHandler(this.doHealthTick);
}
2018-05-15 08:24:17 +00:00
//SETTINGS
2018-05-21 14:43:52 +00:00
//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.
2018-05-21 14:43:52 +00:00
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.
2018-05-15 07:56:44 +00:00
//Max Armor/Health
2018-05-21 14:44:36 +00:00
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.
2018-05-23 11:07:28 +00:00
int overrideArmor = -1; //Set your max armor. Basically the same as above.
2018-05-15 07:56:44 +00:00
//Other armor options
2018-05-21 14:44:36 +00:00
bool allDamageArmor = true; //The armor soaks up all the damage, even fall and explosion-damage.
float armorDefense = 1.0F; //How much damage should the armor soak up while active? Set to 1.0 (default) to make it soak up all damage, set to 0.5 to make it soak up half damage, etc.
2018-05-15 07:56:44 +00:00
2018-05-15 08:24:17 +00:00
//VARIABLES (DO NOT TOUCH)
2018-04-17 19:16:20 +00:00
int armorVal = -1;
int healthVal = -1;
2018-05-21 14:43:52 +00:00
float timeUntilArmorRegen = 0.0f;
2018-05-20 05:41:31 +00:00
float armorDecimalRegen = 0.0f;
2018-05-21 14:43:52 +00:00
float timeUntilHealthRegen = 0.0f;
float healthDecimalRegen = 0.0f;
2018-04-17 19:16:20 +00:00
private void doHealthTick(object sender, EventArgs e)
{
Ped pl = Player.Character;
2018-05-15 07:59:30 +00:00
if (overrideHealth != -1) {
//if (pl.Health > overrideHealth) { Player.MaxHealth = overrideHealth; pl.Health = overrideHealth; }
if (pl.Health > overrideHealth) { pl.Health = overrideHealth; }
}
2018-05-15 07:59:42 +00:00
if (overrideArmor != -1) {
//if (pl.Armor > overrideArmor) { Player.MaxArmor = overrideArmor; pl.Armor = overrideArmor; }
if (pl.Armor > overrideArmor) { pl.Armor = overrideArmor; }
}
2018-04-17 19:16:20 +00:00
if (pl.isAlive == false) {
armorVal = -1;
healthVal = -1;
2018-05-21 14:43:52 +00:00
timeUntilArmorRegen = 0.0f;
2018-05-20 05:41:31 +00:00
armorDecimalRegen = 0.0f;
2018-05-21 14:43:52 +00:00
timeUntilHealthRegen = 0.0f;
healthDecimalRegen = 0.0f;
2018-04-17 19:16:20 +00:00
return;
}
if (allDamageArmor == true) {
if (pl.Health < healthVal) {
int damageTaken = healthVal - pl.Health;
if (damageTaken < pl.Armor) {
pl.Health = pl.Health + damageTaken;
pl.Armor = pl.Armor - damageTaken;
} else {
2018-05-15 08:00:00 +00:00
pl.Health = pl.Health + pl.Armor;
pl.Armor = 0;
}
}
}
2018-05-15 08:00:30 +00:00
if (pl.Armor < armorVal) {
if (armorDefense < 1.0F) {
pl.Health = (int)Math.Round(pl.Health - ((armorVal - pl.Armor)*1.0f-armorDefense));
}
}
2018-05-15 08:00:56 +00:00
2018-05-21 14:43:52 +00:00
if (armorRegen > 0 || healthRegen > 0) {
if (pl.Armor < armorVal || pl.Health < healthVal) {
armorDecimalRegen = 0.0f;
timeUntilArmorRegen = armorRegenDelay;
healthDecimalRegen = 0.0f;
timeUntilHealthRegen = healthRegenDelay;
}
2018-05-15 08:24:55 +00:00
2018-05-21 14:43:52 +00:00
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) {
2018-05-21 19:26:53 +00:00
armorDecimalRegen = armorDecimalRegen + (((1000.0f/GTA.Game.FPS)/1000.0f)*armorRegenSpeed);
2018-05-21 14:43:52 +00:00
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) {
2018-05-21 19:26:53 +00:00
healthDecimalRegen = healthDecimalRegen + (((1000.0f/GTA.Game.FPS)/1000.0f)*healthRegenSpeed);
2018-05-21 14:43:52 +00:00
while (healthDecimalRegen >= 1.0f) {
pl.Health = pl.Health + 1;
healthDecimalRegen = healthDecimalRegen - 1.0f;
}
if (pl.Health > healthRegen) { pl.Health = healthRegen; }
2018-05-20 05:41:31 +00:00
}
2018-05-15 08:24:55 +00:00
}
2018-04-17 19:16:20 +00:00
}
}
armorVal = pl.Armor;
healthVal = pl.Health;
}
}
}