#include "clone_lib"
void main()
{
    if(GetLocalInt(OBJECT_SELF,"PC_CLONE_SYSTEM"))
    {


        if(!GetIsDead(OBJECT_SELF) && GetLocalInt(OBJECT_SELF,"PC_CLONE_SYSTEM_DeathRun"))
        {
            SetLocalInt(OBJECT_SELF,"PC_CLONE_SYSTEM_DeathRun",FALSE);
        }


        struct perceivedEvent  lastPerceptionEvent = GetLastPerceivedEvent();
        struct perceivedEvent  perceptionEvent     = PerceivedEvent();

        if( perceptionEvent.isValid                                                 &&
            (!lastPerceptionEvent.isValid || (lastPerceptionEvent != perceptionEvent)    )   )
        {

            SetLastPerceivedEvent(perceptionEvent);


            ExecuteScript("custom_percep",OBJECT_SELF);


        }


        if(GetLastSpell() >= 0)
        {


            ExecuteScript("custom_spellcast",OBJECT_SELF);

            SignalEvent(OBJECT_SELF,EventSpellCastAt(OBJECT_SELF,-1,FALSE));
        }

        if(GetUserDefinedEventNumber() >= 0)
        {

            ExecuteScript("custom_userdef",OBJECT_SELF);

            SignalEvent(OBJECT_SELF,EventUserDefined(-1));
        }

        struct attackedEvent  lastattackedEvent = GetLastAttackedEvent();
        struct attackedEvent  attackedEvent     = AttackedEvent();

        if( attackedEvent.isValid                                                 &&
            (!lastattackedEvent.isValid || (lastattackedEvent != attackedEvent)    )   )
        {
            SetLastAttackedEvent(attackedEvent);

            ExecuteScript("custom_physicald",OBJECT_SELF);
        }

        struct disturbedEvent lastDisturbedEvent    = GetLastDisturbedEvent();
        struct disturbedEvent disturbedEvent        = DisturbedEvent();

        if( disturbedEvent.isValid                                                 &&
            (!lastDisturbedEvent.isValid || (lastDisturbedEvent != disturbedEvent)    )   )
        {
            SetLastDisturbedEvent(disturbedEvent);

            ExecuteScript("custom_disturbed",OBJECT_SELF);
        }

        struct damagedEvent lastDamagegEvent = GetLastDamagedEvent();
        struct damagedEvent damagegEvent = DamagedEvent();

        if( damagegEvent.isValid                                                 &&
            (!lastDamagegEvent.isValid || (lastDamagegEvent != damagegEvent)    )   )
        {
            SetLastDamagedEvent(damagegEvent);

            ExecuteScript("custom_damage",OBJECT_SELF);
        }

        struct blockedEvent blockedEvent = BlockedEvent();
        struct blockedEvent lastBlockedEvent = GetLastBlockedEvent();

        if( blockedEvent.isValid                                                 &&
            (!lastBlockedEvent.isValid || (lastBlockedEvent != blockedEvent)    )   )
        {
            SetLastBlockedEvent(blockedEvent);


            ExecuteScript("custom_blocked",OBJECT_SELF);
        }

        if(GetIsDead(OBJECT_SELF) && !GetLocalInt(OBJECT_SELF,"PC_CLONE_SYSTEM_DeathRun"))
        {
            SetLocalInt(OBJECT_SELF,"PC_CLONE_SYSTEM_DeathRun",TRUE);



            ExecuteScript("custom_death",OBJECT_SELF);

        }

    }
}