// This script is run by the PCs every 6 seconds.
#include "inc_misc_tools"
void main()
    {
    int iHP = GetCurrentHitPoints();
    int iVoice, iTimer;
    object oSkin = GetItemInSlot(INVENTORY_SLOT_CARMOUR,OBJECT_SELF);
    //--------------------START MINUS TEN RULE--------------------------------
    if (GetIsDead(OBJECT_SELF))
        {
        if (iHP < -9)
            return;// Hes dead therefore no heartbeat.
        if (iHP == 0)
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(1+GetCurrentHitPoints()),OBJECT_SELF);
            iVoice = VOICE_CHAT_HEALME;
            }
        else if (d10() == 1)
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(1+GetCurrentHitPoints()),OBJECT_SELF);
            iVoice = VOICE_CHAT_REST;
            }
        else if (GetLocalInt(oSkin,"miscb049"))
            {
            iVoice = VOICE_CHAT_HEALME;
            }
        else
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(1,DAMAGE_TYPE_MAGICAL),OBJECT_SELF);
            ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_COM_BLOOD_CRT_RED),GetLocation(OBJECT_SELF));
            switch(d3())
                {
                case 1:{iVoice = VOICE_CHAT_PAIN1;break;}
                case 2:{iVoice = VOICE_CHAT_PAIN2;break;}
                case 3:{iVoice = VOICE_CHAT_PAIN3;break;}
                }
            }
        PlayVoiceChat(iVoice);
        }
    else // Else do normal heartbeat functions.
        {
        if (GetCurrentHitPoints() == 1)
            {
            if (!GetLocalInt(OBJECT_SELF,"Disabled"))
                {
                PlayVoiceChat(VOICE_CHAT_HELP);
                SetLocalInt(OBJECT_SELF,"Disabled",TRUE);
                }
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectMovementSpeedDecrease(40),OBJECT_SELF,10.0);
            }
        else if (GetLocalInt(OBJECT_SELF,"Disabled"))
            DeleteLocalInt(OBJECT_SELF,"Disabled");
//-------------------- END MINUS TEN RULE-------------------------------------

//---------------------PARTY LEADER EXTRA FUNCTIONS---------------------------
        if (GetFactionLeader(OBJECT_SELF) == OBJECT_SELF)
            {
            // Reset party rests.
            if (GetHasAllPartyRested(OBJECT_SELF))
                ResetPartyRests(OBJECT_SELF);
            // Wandering Monsters Check
            ExecuteScript("rdg_wand_monster",OBJECT_SELF);
            }
//------------------------- END PARTY LEADER FUNCTIONS----------------------
        // Detect Mode - Searching
        if (GetDetectMode(OBJECT_SELF) == DETECT_MODE_ACTIVE)
            DetectMode();
        // Check rest counter
        if (HasRestGivingItem(OBJECT_SELF))
            SetLocalInt(OBJECT_SELF,"Rest",TRUE);
        // Rest Button Flashing
        if (HasAvailableRest(OBJECT_SELF) && GetHasFood(OBJECT_SELF))
            SetPanelButtonFlash(OBJECT_SELF,PANEL_BUTTON_REST,FALSE);
        else
            SetPanelButtonFlash(OBJECT_SELF,PANEL_BUTTON_REST,TRUE);
        }
    }


