///////////////////////////////////////////////////////////
//	Author: Drammel										 //
//	Date: 5/15/2009										 //
//	Name: feat_diehard									 //
//	Description: When reduced to below 0 hitpoints the PC//
//	automatically heals one hit point.					 //
///////////////////////////////////////////////////////////

void Diehard()
{
	object oPC = OBJECT_SELF;
	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);
	int nHp = GetCurrentHitPoints(oPC);

	SetLocalInt(oToB, "DiehardActive", 1);

	if (nHp >= 0)
	{
		SetLocalInt(oToB, "DiehardFlag", 0);
	}

	if ((nHp < 0) && (GetLocalInt(oToB, "DiehardFlag") == 0))
	{
		effect eHeal = EffectHeal(1);
		ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oPC);
		SetLocalInt(oToB, "DiehardFlag", 1);
	}

	DelayCommand(6.0f, Diehard());
}

void main()
{
	object oPC = OBJECT_SELF;
	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);

	if (GetLocalInt(oToB, "DiehardActive") == 1)
	{
		return; // Prevents duplicate checks.
	}
	else if (GetLocalInt(oToB, "DiehardActive") == 0)
	{
		Diehard();
	}
}