IF
  Global("GB_DoOnce","LOCALS",0)
  !GlobalTimerNotExpired("GB_SpellPrep","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_SpellPrep","LOCALS",2880)
    SetGlobal("GB_DoOnce","LOCALS",1)
END

IF
  Global("GB_DoOnce","LOCALS",1)
  !GlobalTimerNotExpired("GB_SpellPrep","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_SpellPrep","LOCALS",2880)
    Rest()
END

IF
  TookDamage()
  !See([PC])
  HPPercentLT(Myself,25)
  !StateCheck(Myself,STATE_BLIND)
  RandomNum(3,1)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,22589)  // ~Bah!  This is what I get for dealing with rabble!~
    AddexperienceParty(500)
    ApplySpell(Myself,SWOOSH_GONE)
    EscapeArea()
END

IF
  HasItem("POTN55",Myself)
  !GlobalTimerNotExpired("GB_Cast","LOCALS")
  OR(2)
    HPPercentLT(Myself,50)
    DamageTakenGT(39)
  OR(3)
    !Detect([PC])
    StateCheck(Myself,STATE_INVISIBLE)
    HPPercentLT(Myself,35)
THEN
  RESPONSE #100
    ActionOverride(Myself,UseItem("POTN55",Myself))  // ~Potion of Extra Healing~
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  Global("GB_Attacked","LOCALS",0)
  OR(6)
    Heard([EVILCUTOFF],10000)
    Heard([EVILCUTOFF],10001)
    SpellCastOnMe([GOODCUTOFF],0)
    See(NearestEnemyOf(Myself))
    TookDamage()
    Allegiance(Myself,EVILCUTOFF)
THEN
  RESPONSE #100
    GlobalShout(10000)
    SetGlobal("GB_Attacked","LOCALS",1)
END

IF
  Heard([EVILCUTOFF],10000)
  !See([PC])
  !Range(LastHeardBy(Myself),0)
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_OnMyWay","LOCALS",24)
    MoveToObject(LastHeardBy(Myself))
    MoveToObject(LastSeenBy(LastHeardBy(Myself)))
END

IF
  Heard([EVILCUTOFF],10001)
  !See([PC])
  !Range(LastHeardBy(Myself),0)
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GB_OnMyWay","LOCALS",24)
    MoveToObject(LastHeardBy(Myself))
    MoveToObject(LastSeenBy(LastHeardBy(Myself)))
END

IF
  StateCheck(Myself,STATE_BLIND)
  !See([PC])
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  Global("GB_Attacked","LOCALS",0)
THEN
  RESPONSE #100
END

IF
  !See([PC])
  !StateCheck(Player1,STATE_INVISIBLE)
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
  OR(4)
    See([GOODCUTOFF])
    SpellCastOnMe([GOODCUTOFF],0)
    TookDamage()
    Exists(Player1)
THEN
  RESPONSE #100
    GlobalShout(10000)
    MoveToObject(Player1)
END

IF
  Delay(18)
  !See([PC])
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  Delay(18)
  See([PC])
  !GlobalTimerNotExpired("GB_OnMyWay","LOCALS")
THEN
  RESPONSE #100
    GlobalShout(10001)
    Continue()
END

IF
  GlobalTimerNotExpired("GB_Cast","LOCALS")
  See([PC])
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  GlobalTimerNotExpired("GB_Cast","LOCALS")
  See(TenthNearest([PC]))
  HasItemSlot(Myself,SLOT_WEAPON1)
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  GlobalTimerNotExpired("GB_Cast","LOCALS")
  See(TenthNearest([PC]))
  !HasItemSlot(Myself,SLOT_WEAPON1)
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    GlobalShout(10001)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  HPPercentLT(Myself,50)
  HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
THEN
  RESPONSE #100
    ActionOverride(Myself,UseItem("POTN55",Myself))  // ~Potion of Superior Healing~
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  HasItem("POTN14",Myself)  // ~Oil of Speed~
  !StateCheck(Myself,STATE_HASTED)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN14",Myself)  // ~Oil of Speed~
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  HasItem("POTN14",Myself)  // ~Oil of Speed~
  HasItem("BOOT01",Myself)  // ~Boots of Speed~
  !GlobalTimerNotExpired("GB_OilofSpeed","LOCALS")
THEN
  RESPONSE #100
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN14",Myself)  // ~Oil of Speed~
    SetGlobalTimer("GB_OilofSpeed","LOCALS",180)
    SetGlobalTimer("GB_Cast","LOCALS",6)
END

IF
  See([PC])
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #75
    GlobalShout(10001)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    GlobalShout(10001)
    EquipMostDamagingMelee()
    Attack(LastSeenBy(Myself))
END

IF
  See(TenthNearest([PC]))
  HasItemSlot(Myself,SLOT_WEAPON1)
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #75
    GlobalShout(10001)
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    GlobalShout(10001)
    SelectWeaponAbility(SLOT_WEAPON1,0)
    Attack(LastSeenBy(Myself))
END

IF
  See(TenthNearest([PC]))
  !HasItemSlot(Myself,SLOT_WEAPON1)
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #75
    GlobalShout(10001)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    GlobalShout(10001)
    EquipRanged()
    Attack(LastSeenBy(Myself))
END

IF
  See([GOODCUTOFF])
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #75
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    EquipMostDamagingMelee()
    Attack(LastSeenBy(Myself))
END

IF
  See(TenthNearest([GOODCUTOFF]))
  HasItemSlot(Myself,SLOT_WEAPON1)
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #75
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    SelectWeaponAbility(SLOT_WEAPON1,0)
    Attack(LastSeenBy(Myself))
END

IF
  See(TenthNearest([GOODCUTOFF]))
  !HasItemSlot(Myself,SLOT_WEAPON1)
  !Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #75
    GlobalShout(10001)
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    GlobalShout(10001)
    EquipRanged()
    Attack(LastSeenBy(Myself))
END

