/* Andart if Beador is Alive, activate */
IF %BGT_VAR%
Global("X#JaheiraHealsB","GLOBAL",5) // was 20 to 23
InMyArea("jaheira")
!StateCheck("jaheira",CD_STATE_NOTVALID)
InMyArea(Player1)
THEN
RESPONSE #100
SetGlobal("X#JaheiraHealsB","GLOBAL",6)
END

/* Andart if Beador is Alive, initiate */
IF %BGT_VAR%
Global("X#JaheiraHealsB","GLOBAL",6)
InMyArea("jaheira")
!StateCheck("jaheira",CD_STATE_NOTVALID)
InMyArea(Player1)
See([PC])
THEN
RESPONSE #100
StartDialogNoSet([PC])
END

/* Andart if Beador is Dead, activate */
IF %BGT_VAR%
Global("X#JQBeadorDead","GLOBAL",2) // was 22 to 24
InMyArea("jaheira")
!StateCheck("jaheira",CD_STATE_NOTVALID)
InMyArea(Player1)
THEN
RESPONSE #100
SetGlobal("X#JQBeadorDead","GLOBAL",3)
END

/* Andarthe if Beador is Dead, initiate */
IF %BGT_VAR%
Global("X#JQBeadorDead","GLOBAL",3)
InMyArea("jaheira")
!StateCheck("jaheira",CD_STATE_NOTVALID)
InMyArea(Player1)
See([PC])
THEN
RESPONSE #100
StartDialogNoSet(Player1)
END

/* Andarthe Attacks */
IF %BGT_VAR%
	Global("X#JaheiraQuestAAttack","GLOBAL",1)
THEN
	RESPONSE #100
		StartCutSceneMode()
		CutSceneId(Player1)
		SetGlobal("X#JaheiraQuestAAttack","GLOBAL",2)
		ActionOverride("jadruid8a",Enemy())
		ActionOverride("takiyah",Enemy())
		JumpToPoint([874.2175])
		FaceObject(Player1)
		CreateCreature("%tutu_var%WOLFDR",[-1.-1],0)
		CreateCreature("%tutu_var%WOLFDR",[-1.-1],0)
		Enemy()
		EndCutSceneMode()
END

/* Combat Scripts and Surrender Script */
IF
  GlobalGT("X#ASL","LOCALS",0)
  HPPercentLT(Myself,50)
THEN
  RESPONSE #100
    SetGlobal("X#ASL","LOCALS",0)
    Spell(Myself,3122)
END

IF
  HasItem("X#ANSPER",Myself)
  HPPercentLT(Myself,50)
THEN
  RESPONSE #100
    DropItem("X#ANSPER",[-1.-1])
END

IF
Global("X#AndSurrender","GLOBAL",0)
HPPercentLT(Myself,50)
THEN
RESPONSE #100
SetGlobal("X#AndSurrender","GLOBAL",1)
ChangeEnemyAlly(Myself,NEUTRAL)
StartDialogNoSet([PC])
END

IF
  HaveSpell(CLERIC_HEAL)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  HPPercentLT(Myself,70)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_HEAL)
END

IF
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  HasItem("%tutu_var%POTN20",Myself)
THEN
  RESPONSE #100
    UseItem("%tutu_var%POTN20",Myself)
    SetGlobalTimer("X#ACA","LOCALS",6)
END

IF
  StateCheck(Myself,STATE_POISONED)
  HaveSpell(CLERIC_SLOW_POISON)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !HasItem("%tutu_var%POTN20",Myself)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_SLOW_POISON)
END

IF
  HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  HPPercentLT(Myself,80)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_CURE_SERIOUS_WOUNDS)
END

IF
  HaveSpell(CLERIC_CURE_MEDIUM_WOUNDS)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  HPPercentLT(Myself,85)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_CURE_MEDIUM_WOUNDS)
END

IF
  HaveSpell(CLERIC_CURE_LIGHT_WOUNDS)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  HPPercentLT(Myself,90)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_CURE_LIGHT_WOUNDS)
END

IF
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    NoAction()
END

IF
  Detect([GOODCUTOFF])
  HaveSpell(CLERIC_INVISIBILITY_PURGE)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !See(LastSeenBy())
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_INVISIBILITY_PURGE)
END

IF
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !GlobalGT("X#ASF","LOCALS",0)
  HasItem("X#ANSPER",Myself)
THEN
  RESPONSE #100
    UseItem("X#ANSPER",Myself)
    SetGlobal("X#ASF","LOCALS",1)
    SetGlobalTimer("X#ACA","LOCALS",6)
END

IF
  !See([GOODCUTOFF.0.0.FIGHTER_DRUID])
  !See([GOODCUTOFF.0.0.DRUID_ALL])
  !See([GOODCUTOFF.0.0.MAGE_ALL])
  !See([GOODCUTOFF.0.0.CLERIC_ALL])
  !See([GOODCUTOFF.0.0.BARD_ALL])
  !See([GOODCUTOFF])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_DISPEL_MAGIC)
END

IF
  HaveSpell(CLERIC_INSECT_PLAGUE)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_INSECT_PLAGUE)
END

IF
  HaveSpell(CLERIC_BARKSKIN)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_BARKSKIN)
END

IF
  HaveSpell(WIZARD_WEB)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
  !Range(LastSeenBy(),15)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_WEB)
END

IF
  HaveSpell(CLERIC_RESIST_FIRE)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_RESIST_FIRE)
END

IF
  HaveSpell(CLERIC_MISCAST_MAGIC)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  CheckStatLT(LastSeenBy(),80,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(),80,SPELLFAILUREPRIEST)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_MISCAST_MAGIC)
END

IF
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  HasItem("%tutu_var%POTN21",Myself)
THEN
  RESPONSE #100
    UseItem("%tutu_var%POTN21",Myself)
    SetGlobalTimer("X#ACA","LOCALS",6)
END

IF
  HaveSpell(CLERIC_CONJURE_FIRE_ELEMENTAL)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_CONJURE_FIRE_ELEMENTAL)
END

IF
  HaveSpell(CLERIC_CHARM_PERSON)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(LastSeenBy(),STATE_CHARMED)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_CHARM_PERSON)
END

IF
  HaveSpell(CLERIC_POISON)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_POISON)
END

IF
  HaveSpell(WIZARD_CHROMATIC_ORB)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREMAGE)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),WIZARD_CHROMATIC_ORB)
END

IF
  HaveSpell(CLERIC_ANIMAL_SUMMONING_1)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_ANIMAL_SUMMONING_1)
END

IF
  HaveSpell(CLERIC_ENTANGLE)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(LastSeenBy(),STATE_SLEEPING)
  !StateCheck(LastSeenBy(),STATE_HELPLESS)
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
  !Range(LastSeenBy(),15)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_ENTANGLE)
END

IF
  HaveSpell(CLERIC_CLOAK_OF_FEAR)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_CLOAK_OF_FEAR)
END

IF
  HaveSpell(CLERIC_SUMMON_INSECTS)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  !HasBounceEffects(LastSeenBy())
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_SUMMON_INSECTS)
END

IF
  HaveSpell(CLERIC_CAUSE_CRITICAL_WOUNDS)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  AttackedBy([0],DEFAULT)
  Range(LastAttackerOf(),6)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),CLERIC_CAUSE_CRITICAL_WOUNDS)
    Attack(LastSeenBy())
END

IF
  HaveSpell(CLERIC_FLAME_BLADE)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
  !StateCheck(Myself,STATE_SILENCED)
  !CheckStatGT(Myself,75,SPELLFAILUREPRIEST)
  AttackedBy([0],DEFAULT)
  Range(LastAttackerOf(),6)
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(Myself,CLERIC_FLAME_BLADE)
    Attack(LastSeenBy())
END

IF
  !GlobalGT("X#ASL","LOCALS",0)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    SetGlobal("X#ASL","LOCALS",1)
    Spell(Myself,4634)
END

IF
  HaveSpell(SALAMANDER_BREATHE_FIREBALL)
  !GlobalTimerNotExpired("X#ACA","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("X#ACA","LOCALS",6)
    Spell(LastSeenBy(),SALAMANDER_BREATHE_FIREBALL)
END

IF
  GlobalTimerNotExpired("X#ACA","LOCALS")
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy())
END

IF
  !GlobalTimerNotExpired("X#ACA","LOCALS")
THEN
  RESPONSE #100
    Attack(LastSeenBy())
END

IF
  AttackedBy([GOODCUTOFF],DEFAULT)
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    Enemy()
END

IF
  AttackedBy([0],DEFAULT)
THEN
  RESPONSE #100
    Attack(LastAttackerOf())
END