// Break-up talk
IF
Global("O#XanRT15","GLOBAL",0)
OR(2)
GlobalGT("AsylumPlot","GLOBAL",54)
GlobalGT("Chapter","GLOBAL",4)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1) 
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT15","GLOBAL",1)
END

IF
Global("O#XanRT15","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Moonblade death warning - bonded
IF
Global("Chapter","GLOBAL",6)
GlobalGT("O#XanRicarQuest","GLOBAL",1)
!Global("O#XanBondedPathAlive","GLOBAL",2)
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanHappyEnding1","GLOBAL",0)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanHappyEnding1","GLOBAL",2)
END

IF
Global("O#XanHappyEnding1","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Moonblade, survived Bodhi's ambush  - bonded
IF
Global("O#XanBondedPathAlive","GLOBAL",2)
Global("O#XanRomanceActive","GLOBAL",2) 
Global("O#XanHappyEnding2","GLOBAL",0)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanHappyEnding2","GLOBAL",2)
END

IF
Global("O#XanHappyEnding2","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Weather talks
// Dark dungeon
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherDark","GLOBAL",0)
AreaType(DUNGEON)
!Global("Chapter","GLOBAL",5)
!Global("Chapter","GLOBAL",4)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherDark","GLOBAL",1)
RealSetGlobalTimer("O#XanWeatherDarkTimer","GLOBAL",50)
END

IF
RealGlobalTimerExpired("O#XanWeatherDarkTimer","GLOBAL")
Global("O#XanWeatherDark","GLOBAL",1)
AreaType(DUNGEON)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherDark","GLOBAL",2)
END

IF
Global("O#XanWeatherDark","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Sunrise
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherSunrise","GLOBAL",0)
TimeOfDay(MORNING)
AreaType(OUTDOOR)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherSunrise","GLOBAL",1)
END

IF
Global("O#XanWeatherSunrise","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Sunset
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherSunset","GLOBAL",0)
TimeOfDay(DUSK)
AreaType(OUTDOOR)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherSunset","GLOBAL",1)
END

IF
Global("O#XanWeatherSunset","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Night
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherNight","GLOBAL",0)
TimeOfDay(NIGHT)
AreaType(OUTDOOR)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherNight","GLOBAL",1)
END

IF
Global("O#XanWeatherNight","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Day sun
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherSun","GLOBAL",0)
TimeOfDay(DAY)
AreaType(OUTDOOR)
!Global("O#XanWeatherRain","GLOBAL",1)
!Global("O#XanWeatherRain","GLOBAL",2)
!Global("O#XanWeatherRainbow","GLOBAL",1)
!Global("O#XanWeatherRainbow","GLOBAL",2)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherSun","GLOBAL",1)
RealSetGlobalTimer("O#XanWeatherSunTimer","GLOBAL",5)
Weather(NOWEATHER)
END

IF
RealGlobalTimerExpired("O#XanWeatherSunTimer","GLOBAL")
Global("O#XanWeatherSun","GLOBAL",1)
TimeOfDay(DAY)
AreaType(OUTDOOR)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherSun","GLOBAL",2)
END

IF
Global("O#XanWeatherSun","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Rain
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherRain","GLOBAL",0)
TimeOfDay(DAY)
AreaType(OUTDOOR)
!Global("O#XanWeatherSun","GLOBAL",1)
!Global("O#XanWeatherSun","GLOBAL",2)
!Global("O#XanWeatherRainbow","GLOBAL",1)
!Global("O#XanWeatherRainbow","GLOBAL",2)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherRain","GLOBAL",1)
RealSetGlobalTimer("O#XanWeatherRainTimer","GLOBAL",15)
Weather(RAIN)
END

IF
RealGlobalTimerExpired("O#XanWeatherRainTimer","GLOBAL")
Global("O#XanWeatherRain","GLOBAL",1)
TimeOfDay(DAY)
AreaType(OUTDOOR)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherRain","GLOBAL",2)
END

IF
Global("O#XanWeatherRain","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Rainbow
IF
RealGlobalTimerExpired("O#XanWeatherTimer","GLOBAL")
Global("O#XanWeatherRainbow","GLOBAL",0)
TimeOfDay(DAY)
AreaType(OUTDOOR)
!Global("O#XanWeatherSun","GLOBAL",1)
!Global("O#XanWeatherSun","GLOBAL",2)
!Global("O#XanWeatherRain","GLOBAL",1)
!Global("O#XanWeatherRain","GLOBAL",2)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherRainbow","GLOBAL",1)
RealSetGlobalTimer("O#XanWeatherRainbowTimer","GLOBAL",5)
Weather(NOWEATHER)
END

IF
RealGlobalTimerExpired("O#XanWeatherRainbowTimer","GLOBAL")
Global("O#XanWeatherRainbow","GLOBAL",1)
TimeOfDay(DAY)
AreaType(OUTDOOR)
Global("O#XanRomanceActive","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanWeatherRainbow","GLOBAL",2)
END

IF
Global("O#XanWeatherRainbow","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Quest talks
IF
Global("O#XanTairaTalks","GLOBAL",0)
OR(2)
Global("O#XanTairaAsks","GLOBAL",1)
Global("O#XanTairaAsks","GLOBAL",2)
InParty(Myself)
!See("O#Taira")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanTairaTalks","GLOBAL",1)
END

IF
Global("O#XanTairaTalks","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

IF
Global("O#XanTairaAsks","GLOBAL",5)
InParty(Myself)
!See("O#Taira")
!See("O#Rotan")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanTairaAsks","GLOBAL",6)
END

IF
Global("O#XanTairaAsks","GLOBAL",6)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

IF
Global("O#XanSeliaFlightTalked","GLOBAL",0)
Global("O#XanSeliaAttacked","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
!PartyHasItem("Ring37")
GlobalLT("O#XanTairaAsks","GLOBAL",5)
THEN
RESPONSE #100
SetGlobal("O#XanSeliaFlightTalked","GLOBAL",1)
END

IF
Global("O#XanSeliaFlightTalked","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

IF
Global("O#XanStolenRobeTalk","GLOBAL",0)
GlobalGT("O#XanStolenRobe","GLOBAL",0)
InParty(Myself)
!AreaCheck("AR2001")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanStolenRobeTalk","GLOBAL",1)
END

IF
Global("O#XanStolenRobeTalk","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

IF
Global("O#XanDrowSeductionDone","GLOBAL",1)
InParty(Myself)
!See("O#DrowF")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanDrowSeductionDone","GLOBAL",2)
END

IF
Global("O#XanDrowSeductionDone","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Vampire-premonition talk, Bodhi's lair
IF
InParty(Myself)
AreaCheck("AR0801")
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanBondedBodhiPrem","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanBondedBodhiPrem","GLOBAL",1)
END

IF
Global("O#XanBondedBodhiPrem","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Brynnlaw talk 2
IF
InParty(Myself)
AreaCheck("AR1600")
GlobalGT("AsylumPlot","GLOBAL",60)
!Global("O#XanRT15","GLOBAL",2)
Global("O#XanBrynnQuestTalk2","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanBrynnQuestTalk2","GLOBAL",1)
END

IF
Global("O#XanBrynnQuestTalk2","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END
 
// DC talk
IF
InParty(Myself)
AreaCheck("ARO#01")
Global("O#XanDCArea","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanDCArea","GLOBAL",1)
END

IF
Global("O#XanDCArea","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Assassinations
IF
InParty(Myself)
AreaType(OUTDOOR)
!AreaCheck("AR0500")
Global("O#CrLynnBetrayed","GLOBAL",0)
Global("O#CrLynnAmbush","GLOBAL",0) 
GlobalGT("O#CrLynnQuest","GLOBAL",4)
GlobalLT("O#CrLynnQuest","GLOBAL",9)
Global("O#XanAssassinationsTalk1","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanAssassinationsTalk1","GLOBAL",1)
END

IF
Global("O#XanAssassinationsTalk1","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Tower of Deception
IF
InParty(Myself)
AreaCheck("VA#003")
Global("O#XanTowerDeceptionTalk1","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanTowerDeceptionTalk1","GLOBAL",1)
END

IF
Global("O#XanTowerDeceptionTalk1","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// The Deep Gardens
IF
InParty(Myself)
AreaCheck("arldv1")
Global("O#XanColorQuestBeenThere","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("O#XanColorQuestBeenThere","GLOBAL",1)
END

IF
InParty(Myself)
PartyHasItem("DGIAmbe")
AreaCheck("AR1000")
Global("O#XanColorQuestBeenThere","GLOBAL",1)
Global("O#XanColorQuestTalk","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanColorQuestTalk","GLOBAL",1)
END

IF
Global("O#XanColorQuestTalk","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// First friend talk
IF 
Global("O#XanFriendTalk","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanFriendTimer","GLOBAL",1000)
SetGlobal("O#XanFriendTalk","GLOBAL",1)
END

// First romance talk
IF 
Global("O#XanLoveTalk","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanRomanceTimer","GLOBAL",1000)
SetGlobal("O#XanLoveTalk","GLOBAL",1)
END

// Friend talks, sequential
IF
RealGlobalTimerExpired("O#XanFriendTimer","GLOBAL")
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
GlobalLT("O#XanFriendTalk","GLOBAL",31)
!AreaType(DUNGEON)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
OR(15)
Global("O#XanFriendTalk","GLOBAL",1)
Global("O#XanFriendTalk","GLOBAL",3)
Global("O#XanFriendTalk","GLOBAL",5)
Global("O#XanFriendTalk","GLOBAL",7)
Global("O#XanFriendTalk","GLOBAL",9)
Global("O#XanFriendTalk","GLOBAL",11)
Global("O#XanFriendTalk","GLOBAL",13)
Global("O#XanFriendTalk","GLOBAL",15)
Global("O#XanFriendTalk","GLOBAL",17)
Global("O#XanFriendTalk","GLOBAL",19)
Global("O#XanFriendTalk","GLOBAL",21)
Global("O#XanFriendTalk","GLOBAL",23)
Global("O#XanFriendTalk","GLOBAL",25)
Global("O#XanFriendTalk","GLOBAL",27)
Global("O#XanFriendTalk","GLOBAL",29)
THEN
RESPONSE #100
IncrementGlobal("O#XanFriendTalk","GLOBAL",1)
END

IF
RealGlobalTimerExpired("O#XanFriendTimer","GLOBAL")
Global("O#XanFriendship","GLOBAL",1)
InParty(Myself)
GlobalLT("O#XanFriendTalk","GLOBAL",31)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
OR(15)
Global("O#XanFriendTalk","GLOBAL",2)
Global("O#XanFriendTalk","GLOBAL",4)
Global("O#XanFriendTalk","GLOBAL",6)
Global("O#XanFriendTalk","GLOBAL",8)
Global("O#XanFriendTalk","GLOBAL",10)
Global("O#XanFriendTalk","GLOBAL",12)
Global("O#XanFriendTalk","GLOBAL",14)
Global("O#XanFriendTalk","GLOBAL",16)
Global("O#XanFriendTalk","GLOBAL",18)
Global("O#XanFriendTalk","GLOBAL",20)
Global("O#XanFriendTalk","GLOBAL",22)
Global("O#XanFriendTalk","GLOBAL",24)
Global("O#XanFriendTalk","GLOBAL",26)
Global("O#XanFriendTalk","GLOBAL",28)
Global("O#XanFriendTalk","GLOBAL",30)
THEN
RESPONSE #100
Interact(Player1)
END

// Romance talks, sequential
IF
RealGlobalTimerExpired("O#XanRomanceTimer","GLOBAL")
GlobalLT("O#XanLoveTalk","GLOBAL",31)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
!AreaType(DUNGEON)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
OR(15)
Global("O#XanLoveTalk","GLOBAL",1)
Global("O#XanLoveTalk","GLOBAL",3)
Global("O#XanLoveTalk","GLOBAL",5)
Global("O#XanLoveTalk","GLOBAL",7)
Global("O#XanLoveTalk","GLOBAL",9)
Global("O#XanLoveTalk","GLOBAL",11)
Global("O#XanLoveTalk","GLOBAL",13)
Global("O#XanLoveTalk","GLOBAL",15)
Global("O#XanLoveTalk","GLOBAL",17)
Global("O#XanLoveTalk","GLOBAL",19)
Global("O#XanLoveTalk","GLOBAL",21)
Global("O#XanLoveTalk","GLOBAL",23)
Global("O#XanLoveTalk","GLOBAL",25)
Global("O#XanLoveTalk","GLOBAL",27)
Global("O#XanLoveTalk","GLOBAL",29)
THEN
RESPONSE #100
IncrementGlobal("O#XanLoveTalk","GLOBAL",1)
END

IF
RealGlobalTimerExpired("O#XanRomanceTimer","GLOBAL")
GlobalLT("O#XanLoveTalk","GLOBAL",31)
Global("O#XanRomanceActive","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
OR(15)
Global("O#XanLoveTalk","GLOBAL",2)
Global("O#XanLoveTalk","GLOBAL",4)
Global("O#XanLoveTalk","GLOBAL",6)
Global("O#XanLoveTalk","GLOBAL",8)
Global("O#XanLoveTalk","GLOBAL",10)
Global("O#XanLoveTalk","GLOBAL",12)
Global("O#XanLoveTalk","GLOBAL",14)
Global("O#XanLoveTalk","GLOBAL",16)
Global("O#XanLoveTalk","GLOBAL",18)
Global("O#XanLoveTalk","GLOBAL",20)
Global("O#XanLoveTalk","GLOBAL",22)
Global("O#XanLoveTalk","GLOBAL",24)
Global("O#XanLoveTalk","GLOBAL",26)
Global("O#XanLoveTalk","GLOBAL",28)
Global("O#XanLoveTalk","GLOBAL",30)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Bonded talks, sequential
IF
RealGlobalTimerExpired("O#XanBondedTimer","GLOBAL")
GlobalLT("O#XanBondedTalk","GLOBAL",31)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
!AreaType(DUNGEON)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
OR(12)
Global("O#XanBondedTalk","GLOBAL",5)
Global("O#XanBondedTalk","GLOBAL",7)
Global("O#XanBondedTalk","GLOBAL",9)
Global("O#XanBondedTalk","GLOBAL",11)
Global("O#XanBondedTalk","GLOBAL",15)
Global("O#XanBondedTalk","GLOBAL",17)
Global("O#XanBondedTalk","GLOBAL",19)
Global("O#XanBondedTalk","GLOBAL",21)
Global("O#XanBondedTalk","GLOBAL",23)
Global("O#XanBondedTalk","GLOBAL",25)
Global("O#XanBondedTalk","GLOBAL",27)
Global("O#XanBondedTalk","GLOBAL",29)
THEN
RESPONSE #100
IncrementGlobal("O#XanBondedTalk","GLOBAL",1)
END

IF
OR(2)
Global("O#XanBondedTalk","GLOBAL",2)
Global("O#XanBondedTalk","GLOBAL",4)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
RealGlobalTimerExpired("O#XanBondedTimer","GLOBAL")
GlobalLT("O#XanBondedTalk","GLOBAL",31)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
OR(15)
Global("O#XanBondedTalk","GLOBAL",2)
Global("O#XanBondedTalk","GLOBAL",4)
Global("O#XanBondedTalk","GLOBAL",6)
Global("O#XanBondedTalk","GLOBAL",8)
Global("O#XanBondedTalk","GLOBAL",10)
Global("O#XanBondedTalk","GLOBAL",12)
Global("O#XanBondedTalk","GLOBAL",14)
Global("O#XanBondedTalk","GLOBAL",16)
Global("O#XanBondedTalk","GLOBAL",18)
Global("O#XanBondedTalk","GLOBAL",20)
Global("O#XanBondedTalk","GLOBAL",22)
Global("O#XanBondedTalk","GLOBAL",24)
Global("O#XanBondedTalk","GLOBAL",26)
Global("O#XanBondedTalk","GLOBAL",28)
Global("O#XanBondedTalk","GLOBAL",30)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Bonded 2: vow renewal
IF
Global("O#XanBondedTalk","GLOBAL",3)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
IncrementGlobal("O#XanBondedTalk","GLOBAL",1)
END

// Friend talks, consequential
IF
Global("O#XanET1","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
GlobalGT("O#XanFriendTalk","GLOBAL",10)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
PartyRested()
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET1","GLOBAL",1)
END

IF
Global("O#XanET1","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET3","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
CheckStatGT(Player1,50,INTOXICATION)
OR(11)
AreaCheck("AR0509")
AreaCheck("AR0021")
AreaCheck("AR0406")
AreaCheck("AR0313")
AreaCheck("AR0704")
AreaCheck("AR0709")
AreaCheck("AR0513")
AreaCheck("AR1602")
AreaCheck("AR1105")
AreaCheck("AR2010")
AreaCheck("AR2202")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET3","GLOBAL",1)
END

IF
Global("O#XanET3","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET4","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
GlobalLT("Chapter","GLOBAL",4)
AreaCheck("AR0700")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET4TT","GLOBAL",50)
SetGlobal("O#XanET4","GLOBAL",1)
END

IF
Global("O#XanET4","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET4TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
GlobalLT("Chapter","GLOBAL",4)
AreaCheck("AR0700")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET4","GLOBAL",2)
END

IF
Global("O#XanET4","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET5","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR0404")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET5TT","GLOBAL",50)
SetGlobal("O#XanET5","GLOBAL",1)
END

IF
Global("O#XanET5","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET5TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR0404")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET5","GLOBAL",2)
END

IF
Global("O#XanET5","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET6","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
Global("SpawnBrus","GLOBAL",2)
Global("BodhiAppear","GLOBAL",1)
Global("Chapter","GLOBAL",2)
Global("O#XanET6","GLOBAL",0)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET6","GLOBAL",1)
END

IF
Global("O#XanET6","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET7","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR1500")
GlobalLT("AsylumPlot","GLOBAL",54) 
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET7TT","GLOBAL",50)
SetGlobal("O#XanET7","GLOBAL",1)
END

IF
Global("O#XanET7","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET7TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
AreaCheck("AR1500")
GlobalLT("AsylumPlot","GLOBAL",54) 
THEN
RESPONSE #100
SetGlobal("O#XanET7","GLOBAL",2)
END

IF
Global("O#XanET7","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET8","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
AreaCheck("AR1513")
THEN
RESPONSE #100
SetGlobal("O#XanET8","GLOBAL",1)
END

IF
Global("O#XanET8","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET9","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR2100")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET9TT","GLOBAL",50)
SetGlobal("O#XanET9","GLOBAL",1)
END

IF
Global("O#XanET9","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET9TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR2100")
See(Player1)
CombatCounter(0)
!See([ENEMY])
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("O#XanET9","GLOBAL",2)
END

IF
Global("O#XanET9","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET10","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
AreaCheck("AR2201")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET10","GLOBAL",1)
END

IF
Global("O#XanET10","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET11","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1)
GlobalGT("Chaoter","GLOBAL",4) 
HPPercentLT(Player1,80)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET11","GLOBAL",1)
RealSetGlobalTimer("O#XanET11TT","GLOBAL",50)
END

IF
Global("O#XanET11","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET11TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
HPPercentLT(Player1,80)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET11","GLOBAL",2)
END

IF
Global("O#XanET11","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET13","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
Dead("C6Bodhi")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET13TT","GLOBAL",50)
SetGlobal("O#XanET13","GLOBAL",1)
END

IF
Global("O#XanET13","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET13TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET13","GLOBAL",2)
END

IF
Global("O#XanET13","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET14","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR2800")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET14TT","GLOBAL",150)
SetGlobal("O#XanET14","GLOBAL",1)
END

IF
Global("O#XanET14","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET14TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
AreaCheck("AR2800")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET14","GLOBAL",2)
END

IF
Global("O#XanET14","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanET15","GLOBAL",0)
InParty(Myself)
Global("O#XanFriendship","GLOBAL",1) 
XPGT(Player1,2000000)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanET15TT","GLOBAL",1000)
SetGlobal("O#XanET15","GLOBAL",1)
END

IF
Global("O#XanET15","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanET15TT","GLOBAL")
Global("O#XanFriendship","GLOBAL",1) 
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanET15","GLOBAL",2)
END

IF
Global("O#XanET15","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

// Bonded talks, consequential
IF
Global("O#XanST1","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2) 
GlobalGT("O#XanBondedTalk","GLOBAL",10)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
!Global("O#XanBondedPathAlive","GLOBAL",2)
PartyRested()
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST1","GLOBAL",1)
END

IF
Global("O#XanST1","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST4","GLOBAL",0)
InParty(Myself)
GlobalGT("O#XanBondedTalk","GLOBAL",4)
Global("O#XanRomanceActive","GLOBAL",2)
CheckStatGT(Player1,50,INTOXICATION)
OR(11)
AreaCheck("AR0509")
AreaCheck("AR0021")
AreaCheck("AR0406")
AreaCheck("AR0313")
AreaCheck("AR0704")
AreaCheck("AR0709")
AreaCheck("AR0513")
AreaCheck("AR1602")
AreaCheck("AR1105")
AreaCheck("AR2010")
AreaCheck("AR2202")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST4","GLOBAL",1)
END

IF
Global("O#XanST4","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanST4","GLOBAL",2)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("O#XanST4","GLOBAL",3)
END

IF
Global("O#XanST4","GLOBAL",3)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST6","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
!AreaCheck("AR0305")
!AreaCheck("AR0306")
!AreaCheck("AR0307")
Global("AranJob","GLOBAL",1)
PartyHasItem("RING07")
Global("Chapter","GLOBAL",3)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST6","GLOBAL",1)
END

IF
Global("O#XanST6","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST7","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
AreaCheck("AR1512")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST7","GLOBAL",1)
END

IF
Global("O#XanST7","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST8","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
AreaCheck("AR1514")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST8","GLOBAL",1)
END

IF
Global("O#XanST8","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST9","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2) 
AreaCheck("AR2100")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanST9TT","GLOBAL",50)
SetGlobal("O#XanST9","GLOBAL",1)
END

IF
Global("O#XanST9","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanST9TT","GLOBAL")
Global("O#XanRomanceActive","GLOBAL",2) 
AreaCheck("AR2100")
See(Player1)
CombatCounter(0)
!See([ENEMY])
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("O#XanST9","GLOBAL",2)
END

IF
Global("O#XanST9","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST10","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2) 
!AreaCheck("AR2102")
Global("PlayerLooksLikeDrow","GLOBAL",1)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST10","GLOBAL",1)
END

IF
Global("O#XanST10","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST12","GLOBAL",2)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
SetGlobal("O#XanST12","GLOBAL",3)
END

IF
Global("O#XanST12","GLOBAL",3)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST14","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
Global("Chapter","GLOBAL",6)
OR(7)
AreaCheck("AR0020")
AreaCheck("AR0300")
AreaCheck("AR0400")
AreaCheck("AR0500")
AreaCheck("AR0700")
AreaCheck("AR0900")
AreaCheck("AR1000")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST14","GLOBAL",1)
END

IF
Global("O#XanST14","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanST15","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2) 
XPGT(Player1,2000000)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanST15TT","GLOBAL",1000)
SetGlobal("O#XanST15","GLOBAL",1)
END

IF
Global("O#XanST15","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanST15TT","GLOBAL")
Global("O#XanRomanceActive","GLOBAL",2) 
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanST15","GLOBAL",2)
END

IF
Global("O#XanST15","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Romance talks, consequential

IF
Global("O#XanRT1","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("O#XanRT1","GLOBAL",1)
SetGlobalTimer("O#XanRT1Timer","GLOBAL",ONE_DAY)
END

IF
Global("O#XanRT1","GLOBAL",1)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
GlobalTimerExpired("O#XanRT1Timer","GLOBAL")
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
PartyRested()
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT1","GLOBAL",2)
END

IF
Global("O#XanRT1","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT7","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
CheckStatGT(Player1,50,INTOXICATION)
OR(11)
AreaCheck("AR0509")
AreaCheck("AR0021")
AreaCheck("AR0406")
AreaCheck("AR0313")
AreaCheck("AR0704")
AreaCheck("AR0709")
AreaCheck("AR0513")
AreaCheck("AR1602")
AreaCheck("AR1105")
AreaCheck("AR2010")
AreaCheck("AR2202")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT7","GLOBAL",1)
END

IF
Global("O#XanRT7","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

IF
Global("O#XanRT8","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1) 
AreaCheck("AR0900")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanRT8TT","GLOBAL",50)
SetGlobal("O#XanRT8","GLOBAL",1)
END

IF
Global("O#XanRT8","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanRT8TT","GLOBAL")
Global("O#XanRomanceActive","GLOBAL",1) 
AreaCheck("AR0900")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT8","GLOBAL",2)
END

IF
Global("O#XanRT8","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT9","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1) 
AreaCheck("AR1900")
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanRT9TT","GLOBAL",50)
SetGlobal("O#XanRT9","GLOBAL",1)
END

IF
Global("O#XanRT9","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanRT9TT","GLOBAL")
Global("O#XanRomanceActive","GLOBAL",1) 
AreaCheck("AR1900")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT9","GLOBAL",2)
END

IF
Global("O#XanRT9","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT10","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
AreaCheck("AR1402")
!Dead("ShaDra01")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT10","GLOBAL",1)
END

IF
Global("O#XanRT10","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT11","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
AreaCheck("AR0413")
!Dead("Lavok02")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT11","GLOBAL",1)
END

IF
Global("O#XanRT11","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT12","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1) 
Global("Chapter","GLOBAL",3)
Global("O#XanGaelanKeyPresent","GLOBAL",1)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanRT12TT","GLOBAL",50)
SetGlobal("O#XanRT12","GLOBAL",1)
END

IF
Global("O#XanRT12","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanRT12TT","GLOBAL")
Global("O#XanRomanceActive","GLOBAL",1) 
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT12","GLOBAL",2)
END

IF
Global("O#XanRT12","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT13","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1)
AreaCheck("AR1512")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT13","GLOBAL",1)
END

IF
Global("O#XanRT13","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

IF
Global("O#XanRT14","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1) 
GlobalGT("AsylumPlot","GLOBAL",42)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanRT14TT","GLOBAL",50)
SetGlobal("O#XanRT14","GLOBAL",1)
END

IF
Global("O#XanRT14","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanRT14TT","GLOBAL")
Global("O#XanRomanceActive","GLOBAL",1) 
GlobalLT("AsylumPlot","GLOBAL",55)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanRT14","GLOBAL",2)
END

IF
Global("O#XanRT14","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Romance talk, hangover 
IF
Global("O#XanHangoverTalk","GLOBAL",2)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",1) 
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
SetGlobal("O#XanHangoverTalk","GLOBAL",3)
END

IF
Global("O#XanHangoverTalk","GLOBAL",3)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Relationship is complete, chapter 2 or 3
IF
Global("O#XanItIsTime","GLOBAL",0)
InParty(Myself)
OR(3)
Global("O#XanRomanceActive","GLOBAL",1)
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanFriendship","GLOBAL",1)
OR(3)
Global("O#XanFriendTalk","GLOBAL",31)
Global("O#XanBondedTalk","GLOBAL",31)
Global("O#XanLoveTalk","GLOBAL",31)
GlobalLT("Chapter","GLOBAL",4)
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanItIsTimeTT","GLOBAL",1000)
SetGlobal("O#XanItIsTime","GLOBAL",1)
END

IF
Global("O#XanItIsTime","GLOBAL",1)
InParty(Myself)
GlobalLT("Chapter","GLOBAL",4)
OR(3)
Global("O#XanRomanceActive","GLOBAL",1)
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanFriendship","GLOBAL",1)
RealGlobalTimerExpired("O#XanItIsTimeTT","GLOBAL")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanItIsTime","GLOBAL",2)
END

IF
Global("O#XanItIsTime","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

// Watcher's Keep, Saladrex or Demilich dead
IF
Global("O#XanDemilichSaladrex","GLOBAL",0)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
OR(2)
Global("O#XanRomanceActive","GLOBAL",1)
Global("O#XanRomanceActive","GLOBAL",2)
OR(3)
AreaCheck("AR3018")
AreaCheck("AR3022")
AreaCheck("AR3027")
OR(2)
Dead("GorSal")
Dead("demilich")
THEN
RESPONSE #100
SetGlobal("O#XanDemilichSaladrex","GLOBAL",1)
END

IF
Global("O#XanDemilichSaladrex","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
Interact(Player1)
END

// Demogorgon is dead
IF
Global("O#XanDemogorgonIsDead","GLOBAL",0)
Global("DemogorgonIsDead","GLOBAL",1)
Global("O#XanSpokeToDemogorgon","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
AreaCheck("AR3000")
THEN
RESPONSE #100
SetGlobal("O#XanDemogorgonIsDead","GLOBAL",1)
END

IF
Global("O#XanDemogorgonIsDead","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact(Player1)
END

// Watcher's Keep, entered
IF
Global("O#XanKeepEntered","GLOBAL",0)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
AreaCheck("AR3000") 
Global("OpenDungeonDoor5","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("O#XanKeepEntered","GLOBAL",1)
END

IF
Global("O#XanKeepEntered","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Moonblade in Suldanessellar
IF
Global("O#XanMoonBladeCutScene","GLOBAL",0)
InParty(Myself)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
AreaCheck("AR2808")
Global("MoonBladeFight","GLOBAL",1)
!PartyHasItem("MISCB3")
THEN
RESPONSE #100
SetGlobal("O#XanMoonBladeCutScene","GLOBAL",1)
END

IF
Global("O#XanMoonBladeCutScene","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Killed Firkraag
IF
Global("O#XanKilledFirkraag","GLOBAL",1)
InParty(Myself)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
Global("O#XanRomanceActive","GLOBAL",2)
Dead("Firkra02")
AreaCheck("AR1203")
THEN
RESPONSE #100
SetGlobal("O#XanKilledFirkraag","GLOBAL",2)
END

IF
Global("O#XanKilledFirkraag","GLOBAL",2)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
See(Player1)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Killed Kangaxx
IF
Global("O#XanKilledDemilich","GLOBAL",1)
InParty(Myself)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
Dead("HLDemi")
AreaCheck("AR0331")
THEN
RESPONSE #100
SetGlobal("O#XanKilledDemilich","GLOBAL",2)
END

IF
Global("O#XanKilledDemilich","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Killed Shadow Dragon
IF
Global("O#XanKilledShadowDragon","GLOBAL",1)
InParty(Myself)
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
Global("O#XanRomanceActive","GLOBAL",1)
Dead("ShaDra01")
AreaCheck("AR1402")
THEN
RESPONSE #100
SetGlobal("O#XanKilledShadowDragon","GLOBAL",2)
END

IF
Global("O#XanKilledShadowDragon","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// In Hell
IF
Global("O#XanDoesNotLeaveAfterSoA","GLOBAL",0)
InParty(Myself)
GlobalGT("PlayerIntro","AR2900",0)
!Global("O#XanBondedPathAlive","GLOBAL",2)
THEN
RESPONSE #100
SetGlobal("O#XanDoesNotLeaveAfterSoA","GLOBAL",1)
RealSetGlobalTimer("O#XanLeaveAfterSoATimer","GLOBAL",50)
END

IF
Global("O#XanDoesNotLeaveAfterSoA","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanLeaveAfterSoATimer","GLOBAL")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY]) 
THEN
RESPONSE #100
SetGlobal("O#XanDoesNotLeaveAfterSoA","GLOBAL",2)
END

IF
Global("O#XanDoesNotLeaveAfterSoA","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Bodhi dead, bonded path
IF
Global("O#XanHappyEndingBodhiDead","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanBondedPathAlive","GLOBAL",2)
Dead("C6Bodhi")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanHappyEndingBodhiDead","GLOBAL",1)
END

IF
Global("O#XanHappyEndingBodhiDead","GLOBAL",1)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Chapter 7, bonded
IF
Global("O#XanHappyEnding3","GLOBAL",0)
InParty(Myself)
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanBondedPathAlive","GLOBAL",2)
Global("Chapter","GLOBAL",7)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
RealSetGlobalTimer("O#XanHappyEnding3Timer","GLOBAL",50)
SetGlobal("O#XanHappyEnding3","GLOBAL",1)
END

IF
Global("O#XanHappyEnding3","GLOBAL",1)
InParty(Myself)
RealGlobalTimerExpired("O#XanHappyEnding3Timer","GLOBAL")
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY]) 
THEN
RESPONSE #100
SetGlobal("O#XanHappyEnding3","GLOBAL",2)
END

IF
Global("O#XanHappyEnding3","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Hell, bonded
IF
Global("O#XanHappyEnding4","GLOBAL",0)
InParty(Myself)
GlobalGT("PlayerIntro","AR2900",0)
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanBondedPathAlive","GLOBAL",2)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanHappyEnding4","GLOBAL",2)
END

IF
Global("O#XanHappyEnding4","GLOBAL",2)
InParty(Myself)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
PlaySong(0)
PlaySound("O#XAN")
StartDialogueNoSet(Player1)
END

// Xan-initiated flirts
IF
Global("O#XanFlirtsCheck","GLOBAL",0)
InParty(Myself)
OR(2)
Global("O#XanRomanceActive","GLOBAL",1)
Global("O#XanRomanceActive","GLOBAL",2)
OR(2)
GlobalGT("O#XanLoveTalk","GLOBAL",4)
GlobalGT("O#XanBondedTalk","GLOBAL",4)
THEN
RESPONSE #100
SetGlobal("O#XanFlirtsCheck","GLOBAL",1)
RealSetGlobalTimer("O#XanFlirtTimer","GLOBAL",1111)
END

IF
RealGlobalTimerExpired("O#XanFlirtTimer","GLOBAL")
InParty(Myself)
Global("O#XanFlirtsDisabled","GLOBAL",0)
Global("O#XanFlirtsStarted","GLOBAL",0)
OR(2)
Global("O#XanRomanceActive","GLOBAL",1)
Global("O#XanRomanceActive","GLOBAL",2)
OR(2)
GlobalLT("Chapter","GLOBAL",4)
Global("Chapter","GLOBAL",6)
See(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY]) 
THEN
RESPONSE #100
SetGlobal("O#XanFlirtsStarted","GLOBAL",1)
IncrementGlobal("O#XanFlirtCounter","GLOBAL",1)
END

IF
Global("O#XanFlirtsStarted","GLOBAL",1)
InParty(Myself)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Scripted talk with Imoen
IF
Global("O#XanImoen3","GLOBAL",0)
InParty(Myself)
InParty("Imoen2")
HPPercentLT("Imoen2",80)
HPPercentLT("O#Xan",80)
See("Imoen2")
!StateCheck("Imoen2",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanImoen3","GLOBAL",1)
END

IF
Global("O#XanImoen3","GLOBAL",1)
InParty(Myself)
InParty("Imoen2")
See("Imoen2")
!StateCheck("Imoen2",CD_STATE_NOTVALID) 
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Imoen2")
END

// Imoen on broken romance
IF
Global("O#XanImoenRomanceBrokenTalk","GLOBAL",0)
InParty(Myself)
InParty("Imoen2")
Global("O#XanRT15","GLOBAL",2)
AreaType(FOREST)
See("Imoen2")
!StateCheck("Imoen2",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanImoenRomanceBrokenTalk","GLOBAL",1)
END

IF
Global("O#XanImoenRomanceBrokenTalk","GLOBAL",1)
InParty(Myself)
InParty("Imoen2")
See("Imoen2")
!StateCheck("Imoen2",CD_STATE_NOTVALID) 
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Imoen2")
END

// Scripted talk with Jaheira 1, Galvarey dead
IF
Global("O#XanJaheira1","GLOBAL",0)
InParty(Myself)
InParty("Jaheira")
Dead("Galvarey")
THEN
RESPONSE #100
SetGlobal("O#XanJaheira1","GLOBAL",1)
RealSetGlobalTimer("O#XanJaheira1TT","GLOBAL",50)
END

IF
Global("O#XanJaheira1","GLOBAL",1)
InParty(Myself)
InParty("Jaheira")
RealGlobalTimerExpired("O#XanJaheira1TT","GLOBAL")
See("Jaheira")
!StateCheck("Jaheira",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanJaheira1","GLOBAL",2)
END

IF
Global("O#XanJaheira1","GLOBAL",2)
InParty(Myself)
InParty("Jaheira")
See("Jaheira")
!StateCheck("Jaheira",CD_STATE_NOTVALID) 
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Jaheira")
END

// Scripted talk with Jaheira 2, Terminsel first appeared
IF
Global("O#XanJaheira2","GLOBAL",0)
InParty(Myself)
InParty("Jaheira")
GlobalGT("TerminselSpawn","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("O#XanJaheira2","GLOBAL",1)
RealSetGlobalTimer("O#XanJaheira2TT","GLOBAL",50)
END

IF
Global("O#XanJaheira2","GLOBAL",1)
InParty(Myself)
InParty("Jaheira")
RealGlobalTimerExpired("O#XanJaheira2TT","GLOBAL")
See("Jaheira")
!StateCheck("Jaheira",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanJaheira2","GLOBAL",2)
END

IF
Global("O#XanJaheira2","GLOBAL",2)
InParty(Myself)
InParty("Jaheira")
See("Jaheira")
!StateCheck("Jaheira",CD_STATE_NOTVALID) 
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Jaheira")
END

// Scripted talk with Jaheira 3, Dermin dead
IF
Global("O#XanJaheira3","GLOBAL",0)
InParty(Myself)
InParty("Jaheira")
Dead("Dermin")
THEN
RESPONSE #100
SetGlobal("O#XanJaheira3","GLOBAL",1)
RealSetGlobalTimer("O#XanJaheira3TT","GLOBAL",50)
END

IF
Global("O#XanJaheira3","GLOBAL",1)
InParty(Myself)
InParty("Jaheira")
RealGlobalTimerExpired("O#XanJaheira3TT","GLOBAL")
See("Jaheira")
!StateCheck("Jaheira",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
THEN
RESPONSE #100
SetGlobal("O#XanJaheira3","GLOBAL",2)
END

IF
Global("O#XanJaheira3","GLOBAL",2)
InParty(Myself)
InParty("Jaheira")
See("Jaheira")
!StateCheck("Jaheira",CD_STATE_NOTVALID) 
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Jaheira")
END

// Scripted talk with Minsc
IF
Global("O#XanMinsc1","GLOBAL",0)
InParty(Myself)
InParty("Minsc")
See("Minsc")
!StateCheck("Minsc",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
HPPercentLT("Minsc",80)
HPPercentLT("O#Xan",80)
CombatCounter(0)
!See([ENEMY])
AreaType(DUNGEON)
THEN
RESPONSE #100
SetGlobal("O#XanMinsc1","GLOBAL",1)
END

IF
Global("O#XanMinsc1","GLOBAL",1)
InParty(Myself)
InParty("Minsc")
See("Minsc")
!StateCheck("Minsc",CD_STATE_NOTVALID) 
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Minsc")
END

// Scripted talk with Valygar
IF
Global("O#XanValygar1","GLOBAL",0)
InParty(Myself)
InParty("Valygar")
Dead("C6Bodhi")
See("Valygar")
!StateCheck("Valygar",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
CombatCounter(0)
!See([ENEMY])
!AreaType(DUNGEON)
THEN
RESPONSE #100
SetGlobal("O#XanValygar1","GLOBAL",1)
END

IF
Global("O#XanValygar1","GLOBAL",1)
InParty(Myself)
InParty("Valygar")
See("Valygar")
!StateCheck("Valygar",CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN
RESPONSE #100
Interact("Valygar")
END

// Fixes for the romances
IF
GlobalGT("Chapter","GLOBAL",4)
Global("O#XanRomanceActive","GLOBAL",1)
!InPartyAllowDead("O#Xan")
Global("O#XanSheWasNotBack","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("O#XanSheWasNotBack","GLOBAL",1)
SetGlobal("O#XanRomanceActive","GLOBAL",3)
END

IF
Global("O#XanRomanceActive","GLOBAL",2)
!InPartyAllowDead("O#Xan")
!InMyArea(Player1)
Global("O#XanSheLeftForever","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("O#XanSheLeftForever","GLOBAL",1)
SetGlobal("O#XanRomanceActive","GLOBAL",3)
ActionOverride("O#Xan",DestroySelf())
END

// Xan-Anomen script kill
IF 
Global("O#XanWonAnomen","GLOBAL",0)
Global("O#XanRomanceActive","GLOBAL",2)
OR(2)
Global("AnomenRomanceActive","GLOBAL",1)
Global("AnomenRomanceActive","GLOBAL",2)
THEN
RESPONSE #100
SetGlobal("O#XanWonAnomen","GLOBAL",1)
SetGlobal("AnomenRomanceActive","GLOBAL",3)
END

IF 
Global("O#XanLostAnomen","GLOBAL",0)
Global("AnomenRomanceActive","GLOBAL",2)
Global("O#XanRomanceActive","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("O#XanLostAnomen","GLOBAL",1)
SetGlobal("O#XanRomanceActive","GLOBAL",3)
END

//Setting normal biography
IF
Global("O#XanRomanceActive","GLOBAL",2)
Global("O#XanNormalBiography","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("O#XanNormalBiography","GLOBAL",1)
SetPlayerSound(Myself,@45,EXISTANCE5)
END

// Romantic Encounters
// Coran
IF
Global("RE_CoranSex","GLOBAL",1)
Global("RE_CoranSexXan","GLOBAL",0)
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("O#XanRomanceActive","GLOBAL",2)
THEN
RESPONSE #100
SetGlobal("RE_CoranSexXan","GLOBAL",1)
END

IF
Global("RE_CoranSexXan","GLOBAL",1)
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Saemon
IF
Global("RE_SaemonSex","GLOBAL",1)
Global("RE_SaemonSexXan","GLOBAL",0)
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
!StateCheck(Player1,CD_STATE_NOTVALID)
Global("O#XanRomanceActive","GLOBAL",2)
THEN
RESPONSE #100
SetGlobal("RE_SaemonSexXan","GLOBAL",1)
END

IF
Global("RE_SaemonSexXan","GLOBAL",1)
InParty(Myself)
!StateCheck(Myself,CD_STATE_NOTVALID)
!StateCheck(Player1,CD_STATE_NOTVALID)
THEN
RESPONSE #100
StartDialogueNoSet(Player1)
END

// Hotkey fixers
IF
!Global("O#XanRomanceActive","GLOBAL",2)
HotKey(K)
THEN
RESPONSE #100
StartCutSceneMode()
StartCutScene("O#XanF1")
END

IF
Global("O#XanRomanceActive","GLOBAL",2)
HotKey(K)
THEN
RESPONSE #100
StartCutSceneMode()
StartCutScene("O#XanF2")
END