IF
  Global("DeathScriptSend","AR6200",1)
  !Dead("finsend")
THEN
  RESPONSE #100
    SetGlobal("DeathScriptSend","AR6200",0)
END

IF
  Global("DeathScriptAbaz","AR6200",1)
  !Dead("finabaz")
THEN
  RESPONSE #100
    SetGlobal("DeathScriptAbaz","AR6200",0)
END

IF
  Global("DeathScriptIlla","AR6200",1)
  !Dead("finilla")
THEN
  RESPONSE #100
    SetGlobal("DeathScriptIlla","AR6200",0)
END

IF
  Global("DeathScriptSare","AR6200",1)
  !Dead("finsarev")
THEN
  RESPONSE #100
    SetGlobal("DeathScriptSare","AR6200",0)
END

IF
  Global("DeathScriptYaga","AR6200",1)
  !Dead("finyaga")
THEN
  RESPONSE #100
    SetGlobal("DeathScriptYaga","AR6200",0)
END

IF
  Global("DeathScriptGrom","AR6200",1)
  !Dead("fingrom")
THEN
  RESPONSE #100
    SetGlobal("DeathScriptGrom","AR6200",0)
END

IF
  Global("SpawnBalthAlly","AR6200",0)
  Global("BalthazarFights","GLOBAL",1)
  Global("DetectableSpells","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("SpawnBalthAlly","AR6200",1)
    SetGlobal("DetectableSpells","GLOBAL",1)
    CreateCreatureObject("balth2",Player1,0,0,0)
    ActionOverride("balth2",Ally())
    ActionOverride("balth2",Face(8))
    ReallyForceSpellRES("SPDETECT",Player1)
END

IF
  Global("SpawnBalthAlly","AR6200",0)
  Global("BalthazarFights","GLOBAL",1)
  Global("DetectableSpells","GLOBAL",1)
THEN
  RESPONSE #100
    SetGlobal("SpawnBalthAlly","AR6200",1)
    CreateCreatureObject("balth2",Player1,0,0,0)
    ActionOverride("balth2",Ally())
    ActionOverride("balth2",Face(8))
END

IF
  Global("BalthazarFights","GLOBAL",0)
  Global("DetectableSpells","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("DetectableSpells","GLOBAL",1)
    ReallyForceSpellRES("SPDETECT",Player1)
END

IF
  Dead("finiren")
  OR(2)
    Dead("finbodh")
    Global("BodhiFights","GLOBAL",1)
  Dead("finsolar")
  !Exists([ENEMY])
  Global("SetForceWalkwayTimer","AR6200",0)
  Global("FinalFight","AR6200",3)
THEN
  RESPONSE #100
    SetGlobal("SetForceWalkwayTimer","AR6200",1)
    SetGlobalTimer("ForceWalkway","AR6200",30)
END

IF
  GlobalTimerExpired("ForceWalkway","AR6200")
  Global("FinalFight","AR6200",3)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",5)
END

IF
  Delay(3)
  Dead("finiren")
  OR(2)
    Dead("finbodh")
    Global("BodhiFights","GLOBAL",1)
  Dead("finsolar")
  !Exists([ENEMY])
  Global("BalthazarFights","GLOBAL",1)
  !Dead("balth2")
  !StateCheck("balth2",STATE_STUNNED)
  !StateCheck("balth2",STATE_SLEEPING)
  !StateCheck("balth2",STATE_SILENCED)
  !StateCheck("balth2",STATE_CONFUSED)
  OR(2)
    Global("ImoenBackToHuman","GLOBAL",2)
    Dead("Imoen2")
  Global("FinalFight","AR6200",3)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",4)
    ActionOverride("balth2",Dialog(Player1))
END

IF
  Delay(3)
  Dead("finiren")
  OR(2)
    Dead("finbodh")
    Global("BodhiFights","GLOBAL",1)
  Dead("finsolar")
  !Exists([ENEMY])
  OR(6)
    Global("BalthazarFights","GLOBAL",0)
    Dead("balth2")
    StateCheck("balth2",STATE_STUNNED)
    StateCheck("balth2",STATE_SLEEPING)
    StateCheck("balth2",STATE_SILENCED)
    StateCheck("balth2",STATE_CONFUSED)
  OR(2)
    Global("ImoenBackToHuman","GLOBAL",2)
    Dead("Imoen2")
  Global("FinalFight","AR6200",3)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",4)
    ActionOverride(Player1,StartDialogue("player1",Player1))
END

IF
  OR(2)
    Global("SarevokFights","GLOBAL",1)
    Dead("sarevok")
  OR(2)
    Dead("balth2")
    Global("BalthazarFights","GLOBAL",0)
  Global("MelStillImmortal","AR6200",2)
  Delay(6)
THEN
  RESPONSE #100
    SetGlobal("MelStillImmortal","AR6200",3)
    ActionOverride(Player1,StartDialogue("player1",Player1))
END

IF
  Global("FinalFight","AR6200",5)
  Global("SetUpPools","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("SetUpPools","AR6200",1)
    AmbientActivate("AMB_Stream1",TRUE)
    SoundActivate("Bridge3",TRUE)
    OpenDoor("DOOR03")
    AmbientActivate("AMB_Stream2",TRUE)
    SoundActivate("Bridge1",TRUE)
    OpenDoor("DOOR02")
    SoundActivate("Bridge2",TRUE)
    AmbientActivate("AMB_Stream3",TRUE)
    OpenDoor("DOOR01")
END

IF
  Global("FinalFight","AR6200",5)
  GlobalTimerExpired("MelissanComes","AR6200")
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",6)
    ClearAllActions()
    StartCutSceneMode()
    StartCutScene("finmel2")
END

IF
  Global("FinalFight","AR6200",8)
  Global("BalthazarFights","GLOBAL",0)
  Global("IllaseraDead","AR6200",1)
  Global("AbazigalDead","AR6200",1)
  Global("YagaDead","AR6200",1)
  Global("SendaiDead","AR6200",1)
  Global("BalthDead","AR6200",1)
  OR(2)
    Global("SarevokDead","AR6200",1)
    Global("SarevokFights","GLOBAL",0)
  Global("allfive","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("allfive","GLOBAL",1)
END

IF
  Global("FinalFight","AR6200",8)
  Global("BalthazarFights","GLOBAL",1)
  !DifficultyLT(NORMAL)
  Global("IllaseraDead","AR6200",1)
  Global("AbazigalDead","AR6200",1)
  Global("YagaDead","AR6200",1)
  Global("SendaiDead","AR6200",1)
  OR(2)
    Global("SarevokDead","AR6200",1)
    Global("SarevokFights","GLOBAL",0)
  Global("GromnirDead","AR6200",1)
  Global("allfive","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("allfive","GLOBAL",1)
END

IF
  Global("FinalFight","AR6200",8)
  Global("BalthazarFights","GLOBAL",1)
  DifficultyLT(NORMAL)
  Global("IllaseraDead","AR6200",1)
  Global("AbazigalDead","AR6200",1)
  Global("YagaDead","AR6200",1)
  Global("SendaiDead","AR6200",1)
  OR(2)
    Global("SarevokDead","AR6200",1)
    Global("SarevokFights","GLOBAL",0)
  Global("allfive","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("allfive","GLOBAL",1)
END

IF
  Dead("finilla")
  Global("IllaseraDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("IllaseraDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",2)
END

IF
  !Dead("finilla")
  Global("IllaseraDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("IllaseraDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-2)
END

IF
  Dead("finabaz")
  Global("AbazigalDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("AbazigalDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",1)
END

IF
  !Dead("finabaz")
  Global("AbazigalDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("AbazigalDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-1)
END

IF
  Dead("finyaga")
  Global("YagaDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("YagaDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",1)
END

IF
  !Dead("finyaga")
  Global("YagaDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("YagaDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-1)
END

IF
  Dead("finsend")
  Global("SendaiDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("SendaiDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",2)
END

IF
  !Dead("finsend")
  Global("SendaiDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("SendaiDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-2)
END

IF
  Dead("finbalth")
  Global("BalthazarFights","GLOBAL",0)
  Global("BalthDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("BalthDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",2)
END

IF
  !Dead("finbalth")
  Global("BalthazarFights","GLOBAL",0)
  Global("BalthDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("BalthDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-2)
END

IF
  Dead("fingrom")
  Global("BalthazarFights","GLOBAL",1)
  DifficultyGT(EASY)
  Global("GromnirDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("GromnirDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",1)
END

IF
  !Dead("fingrom")
  Global("BalthazarFights","GLOBAL",1)
  DifficultyGT(EASY)
  Global("GromnirDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("GromnirDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-1)
END

IF
  Dead("finsarev")
  Global("SarevokFights","GLOBAL",1)
  Global("SarevokDead","AR6200",0)
THEN
  RESPONSE #100
    SetGlobal("SarevokDead","AR6200",1)
    IncrementGlobal("FiveDead","AR6200",1)
END

IF
  !Dead("finsarev")
  Global("SarevokFights","GLOBAL",1)
  Global("SarevokDead","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("SarevokDead","AR6200",0)
    IncrementGlobal("FiveDead","AR6200",-1)
END

IF
  Difficulty(EASIEST)
  GlobalGT("FiveDead","AR6200",3)
  Global("FinalFight","AR6200",7)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",8)
    ClearAllActions()
    StartCutSceneMode()
    StartCutScene("melcomes")
END

IF
  Difficulty(EASY)
  GlobalGT("FiveDead","AR6200",2)
  Global("FinalFight","AR6200",7)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",8)
    ClearAllActions()
    StartCutSceneMode()
    StartCutScene("melcomes")
END

IF
  Difficulty(NORMAL)
  GlobalGT("FiveDead","AR6200",1)
  Global("FinalFight","AR6200",7)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",8)
    ClearAllActions()
    StartCutSceneMode()
    StartCutScene("melcomes")
END

IF
  DifficultyGT(NORMAL)
  GlobalGT("FiveDead","AR6200",0)
  Global("FinalFight","AR6200",7)
THEN
  RESPONSE #100
    SetGlobal("FinalFight","AR6200",8)
    ClearAllActions()
    StartCutSceneMode()
    StartCutScene("melcomes")
END

IF
  Global("StartEndBios","AR6200",1)
THEN
  RESPONSE #100
    SetCutSceneLite(TRUE)
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Aerie")
  Gender(Player1,FEMALE)
  OR(2)
    !Global("AerieRomanceActive","GLOBAL",2)
    Global("PlayerChoseEssence","GLOBAL",1)
  Global("AerieBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("AerieBio","GLOBAL",1)
    TextScreen("AERIFND1")
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Nalia")
  Global("NaliaBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("NaliaBio","GLOBAL",1)
    TextScreen("NALIAND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Anomen")
  OR(2)
    !Global("AnomenRomanceActive","GLOBAL",2)
    Global("PlayerChoseEssence","GLOBAL",1)
  Global("AnomenBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("AnomenBio","GLOBAL",1)
    TextScreen("ANOMEND1")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Anomen")
  Global("PlayerChoseEssence","GLOBAL",0)
  Global("AnomenRomanceActive","GLOBAL",2)
  Global("AnomenBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("AnomenBio","GLOBAL",1)
    TextScreen("ANOMEND2")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Viconia")
  !Gender(Player1,FEMALE)
  OR(2)
    !Global("ViconiaRomanceActive","GLOBAL",2)
    Global("PlayerChoseEssence","GLOBAL",1)
  !Alignment("Viconia",MASK_EVIL)
  Global("ViconiaBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ViconiaBio","GLOBAL",1)
    TextScreen("VICONND3")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Viconia")
  OR(2)
    !Global("ViconiaRomanceActive","GLOBAL",2)
    Global("PlayerChoseEssence","GLOBAL",1)
  Global("ViconiaBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ViconiaBio","GLOBAL",1)
    TextScreen("VICONND1")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Viconia")
  Global("PlayerChoseEssence","GLOBAL",0)
  Global("ViconiaRomanceActive","GLOBAL",2)
  Global("ViconiaBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ViconiaBio","GLOBAL",1)
    TextScreen("VICONND2")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Valygar")
  Gender(Player1,FEMALE)
  Global("ValygarBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ValygarBio","GLOBAL",1)
    TextScreen("VALYGFND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Valygar")
  Global("ValygarBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ValygarBio","GLOBAL",1)
    TextScreen("VALYGND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Haerdalis")
  Global("HaerdalisBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("HaerdalisBio","GLOBAL",1)
    TextScreen("HAERND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Cernd")
  Global("CerndBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("CerndBio","GLOBAL",1)
    TextScreen("CERNDND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Sarevok")
  Alignment("Sarevok",MASK_GOOD)
  Gender(Player1,FEMALE)
  Global("SarevokGoodBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("SarevokGoodBio","GLOBAL",1)
    TextScreen("SAREVFND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Sarevok")
  Global("SarevokBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("SarevokBio","GLOBAL",1)
    TextScreen("SAREVND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Minsc")
  Global("MinscBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("MinscBio","GLOBAL",1)
    TextScreen("MINSCND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Edwin")
  Global("EdwinBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("EdwinBio","GLOBAL",1)
    TextScreen("EDWINND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  OR(2)
    InParty("Imoen2")
    Global("ImoenEpilogueAnyway","GLOBAL",1)
  Gender(Player1,FEMALE)
  Global("ImoenBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ImoenBio","GLOBAL",1)
    TextScreen("IMOENFND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Jaheira")
  OR(2)
    !Global("JaheiraRomanceActive","GLOBAL",2)
    Global("PlayerChoseEssence","GLOBAL",1)
  Global("JaheiraBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("JaheiraBio","GLOBAL",1)
    TextScreen("JAHEIND1")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Jaheira")
  Global("PlayerChoseEssence","GLOBAL",0)
  Global("JaheiraRomanceActive","GLOBAL",2)
  Global("JaheiraBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("JaheiraBio","GLOBAL",1)
    TextScreen("JAHEIND2")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Mazzy")
  Gender(Player1,FEMALE)
  Global("MazzyBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("MazzyBio","GLOBAL",1)
    TextScreen("MAZZYFND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Jan")
  Global("JanBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("JanBio","GLOBAL",1)
    TextScreen("JANND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Korgan")
  Global("KorganBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("KorganBio","GLOBAL",1)
    TextScreen("KORGAND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Keldorn")
  Global("KeldornBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("KeldornBio","GLOBAL",1)
    TextScreen("KELDORND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  Global("BalthazarFights","GLOBAL",1)
  Gender(Player1,FEMALE)
  Global("BalthazarBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("BalthazarBio","GLOBAL",1)
    TextScreen("BALTHFND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  InParty("Sarevok")
  Alignment("Sarevok",MASK_EVIL)
  Global("SarevokBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("SarevokBio","GLOBAL",1)
    TextScreen("SAREVND2")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  !InParty("Imoen2")
  !Gender(Player1,FEMALE)
  Global("ImoenEpilogueAnyway","GLOBAL",1)
  Global("ImoenBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("ImoenBio","GLOBAL",1)
    TextScreen("IMOENND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  Global("BalthazarFights","GLOBAL",1)
  !Gender(Player1,FEMALE)
  Global("BalthazarBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("BalthazarBio","GLOBAL",1)
    TextScreen("BALTHAND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
  Global("BodhiFights","GLOBAL",2)
  Global("BodhiBio","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobal("BodhiBio","GLOBAL",1)
    TextScreen("BODHIND")
    SmallWait(1)
    Continue()
END

IF
  Global("StartEndBios","AR6200",1)
THEN
  RESPONSE #100
    SetGlobal("StartEndBios","AR6200",2)
    SetCutSceneLite(FALSE)
    EndCredits()
END

