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 20:59:02 +00:00
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
//Script
2018-05-15 07:56:44 +00:00
int tickTime = 100 ; //Tick-Rate in ms.
2018-04-17 19:16:20 +00:00
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.
int armorRegenSpeed = 1 ; //How much armor to regenerate per tick.
int armorRegenDelay = 5000 ; //Delay after damage before recharging armor. Set to 0 to disable delay.
//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 ;
int timeUntilRegen = 0 ;
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 ;
timeUntilRegen = 0 ;
return ;
}
2018-04-17 20:59:02 +00:00
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 ;
2018-04-17 20:59:02 +00:00
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
if ( pl . Armor < armorVal ) { timeUntilRegen = armorRegenDelay ; }
if ( pl . Health < healthVal ) { timeUntilRegen = armorRegenDelay ; }
2018-04-17 19:16:20 +00:00
if ( timeUntilRegen > 0 ) {
timeUntilRegen = timeUntilRegen - tickTime ;
if ( timeUntilRegen < 0 ) { timeUntilRegen = 0 ; }
2018-04-17 20:59:02 +00:00
} 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 ;
2018-04-17 20:59:02 +00:00
Game . DisplayText ( "Health:\n " + pl . Health . ToString ( ) , 1000 ) ;
2018-04-17 19:16:20 +00:00
Wait ( tickTime ) ;
}
}
}