iv-pdhealth/scripts/paydayHealth.cs

104 lines
3.3 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
{
2018-04-17 19:16:20 +00:00
public pdHealth()
{
this.Tick += new EventHandler(this.doHealthTick);
}
2018-05-15 08:24:17 +00:00
//SETTINGS
2018-05-15 07:56:44 +00:00
//Regeneration
int armorRegen = 25; //How far to regenerate the armor. Set to 0 to disable regenaration entirely.
2018-05-20 05:41:31 +00:00
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.
2018-05-15 07:56:44 +00:00
//Max Armor/Health
2018-05-15 08:24:17 +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-15 07:56:44 +00:00
int overrideArmor = -1; //Set your max armor. Basically the same as above.
//Other armor options
2018-05-15 08:24:17 +00:00
bool allDamageArmor = true; //The armor soaks up all the damage, even fall and explosion-damage.
2018-05-15 07:56:44 +00:00
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 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-20 05:41:31 +00:00
float timeUntilRegen = 0.0f;
float armorDecimalRegen = 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-20 05:41:31 +00:00
timeUntilRegen = 0.0f;
armorDecimalRegen = 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-15 08:24:55 +00:00
if (armorRegen > 0) {
2018-05-20 05:41:31 +00:00
if (pl.Armor < armorVal) { armorDecimalRegen = 0.0f; timeUntilRegen = armorRegenDelay; }
if (pl.Health < healthVal) { armorDecimalRegen = 0.0f; timeUntilRegen = armorRegenDelay; }
2018-05-15 08:24:55 +00:00
if (timeUntilRegen > 0) {
2018-05-20 05:41:31 +00:00
timeUntilRegen = timeUntilRegen - ((1000.0f/GTA.Game.FPS)/1000.0f);
2018-05-15 08:24:55 +00:00
if (timeUntilRegen < 0) { timeUntilRegen = 0; }
} else {
if (pl.Armor < armorRegen) {
2018-05-20 05:41:31 +00:00
armorDecimalRegen = armorDecimalRegen + (((1000.0f/GTA.Game.FPS)*armorRegenSpeed)/1000.0f);
while (armorDecimalRegen >= 1.0f) {
pl.Armor = pl.Armor + 1;
armorDecimalRegen = armorDecimalRegen - 1.0f;
}
2018-05-15 08:24:55 +00:00
if (pl.Armor > armorRegen) { pl.Armor = armorRegen; }
}
2018-04-17 19:16:20 +00:00
}
}
armorVal = pl.Armor;
healthVal = pl.Health;
2018-05-20 05:41:31 +00:00
Game.DisplayText("Armor:\n " +pl.Armor.ToString(), 1000);
2018-04-17 19:16:20 +00:00
}
}
}