iv-pdhealth/paydayHealth.cs

95 lines
2.4 KiB
C#
Raw Normal View History

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);
//this.KeyDown += new GTA.KeyEventHandler(this.keyDownHandler);
}
//Settings:
2018-04-18 20:04:16 +00:00
int tickTime = 100; //Tick-Rate in ms
int armorRegen = 25; //How far to regenerate the armor
int armorRegenSpeed = 1; //How much armor to regenerate per tick
int armorRegenDelay = 5000; //Delay before recharging armor
2018-04-19 20:01:18 +00:00
int overrideHealth = 50; //Set your max health to balance the regenerating armor. This will override any max health values set via trainer. Set to -1 to disable.
2018-04-18 20:04:16 +00:00
bool allDamageArmor = true; //The armor soaks up all the health, even fall and explosion-damage.
bool ditchDamage = false; //Ditch damage, if hit depletes armor
2018-04-17 19:16:20 +00:00
//Vars
int armorVal = -1;
int healthVal = -1;
int timeUntilRegen = 0;
private void doHealthTick(object sender, EventArgs e)
{
Ped pl = Player.Character;
2018-04-19 20:01:18 +00:00
if (overrideHealth != -1) {
if (pl.Health > overrideHealth) { pl.Health = overrideHealth; } //MaxHealth not functional?
}
2018-04-17 19:16:20 +00:00
if (pl.isAlive == false) {
armorVal = -1;
healthVal = -1;
timeUntilRegen = 0;
return;
}
2018-04-17 19:55:04 +00:00
if (pl.Armor < armorVal) { timeUntilRegen = armorRegenDelay; }
if (pl.Health < healthVal) { timeUntilRegen = armorRegenDelay; }
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-04-18 14:08:43 +00:00
pl.Health = pl.Health + pl.Armor;
pl.Armor = 0;
}
}
}
2018-04-17 19:16:20 +00:00
if (timeUntilRegen > 0) {
timeUntilRegen = timeUntilRegen - tickTime;
if (timeUntilRegen < 0) { timeUntilRegen = 0; }
} else {
2018-04-17 19:16:20 +00:00
if (pl.Armor < armorRegen) {
pl.Armor = pl.Armor + armorRegenSpeed;
if (pl.Armor > armorRegen) { pl.Armor = armorRegen; }
}
}
armorVal = pl.Armor;
healthVal = pl.Health;
Game.DisplayText("Health:\n " +pl.Health.ToString(), 1000);
2018-04-17 19:16:20 +00:00
Wait(tickTime);
}
//Testing
private void keyDownHandler(object sender, GTA.KeyEventArgs e)
{
if (e.Key == Keys.B) {
Ped pl = Player.Character;
pl.Invincible = true;
pl.Health = -1;
return;
}
if (e.Key == Keys.N) {
Ped pl = Player.Character;
pl.Invincible = false;
pl.Health = -100;
return;
}
}
}
}