IF
InParty(Myself)
Global("AjPalTimerStarted","GLOBAL",0)
THEN
RESPONSE #100
RealSetGlobalTimer("AjPaladinTalkTime","GLOBAL",600)
SetGlobal("AjPalTimerStarted","GLOBAL",1)
END

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
RealGlobalTimerExpired("AjPaladinTalkTime","GLOBAL")
Global("AjPaladinFriendTalk","GLOBAL",0)
Class(Player1,PALADIN)
THEN
RESPONSE #100
IncrementGlobal("AjPaladinFriendTalk","GLOBAL",1)
RealSetGlobalTimer("AjPFriendlyTalkTime","GLOBAL",10)
StartDialogueNoSet(Player1)
END

IF 
InParty(Myself)
RealGlobalTimerExpired("AjPFriendlyTalkTime","GLOBAL")
Global("AjPaladinFriendTalk","GLOBAL",1)
THEN
RESPONSE #100
IncrementGlobal("AjPaladinFriendTalk","GLOBAL",1)
END

//Ajantis Central Baldur's Gate
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
AreaCheck("AR7700")
Global("AjWalls","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("AjWalls","GLOBAL",1)
StartDialogueNoSet(Player1)
RealSetGlobalTimer("AjantisShield","GLOBAL",3600)
END

//Ajantis ShieldTalk

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
RealGlobalTimerExpired("AjantisShield","GLOBAL")
Global("AjShieldFriendTalk","GLOBAL",0)
THEN
RESPONSE #100
IncrementGlobal("AjShieldFriendTalk","GLOBAL",1)
RealSetGlobalTimer("AjPFriendlyTalkTime","GLOBAL",10)
StartDialogueNoSet(Player1)
END

IF 
InParty(Myself)
RealGlobalTimerExpired("AjPFriendlyTalkTime","GLOBAL")
Global("AjShieldFriendTalk","GLOBAL",1)
THEN
RESPONSE #100
IncrementGlobal("AjShieldFriendTalk","GLOBAL",1)
END

//Ajantis Bhaal talk
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
Global("KnowBhaal","GLOBAL",1)
Global("X#AjantisKnowBhaalTalk","GLOBAL",0) 
THEN
RESPONSE #100
SetGlobal("X#AjantisKnowBhaalTalk","GLOBAL",1)
Dialog(Player1)
END

////attacking Drizzt: Ajantis turns hostile
IF
AreaCheck("AR3100")
InParty(Myself) //No "Combatcounter=0" here!
Global("X#AjantisDrizzt3","GLOBAL",0)//from other Ajantis interjection
Global("X#PartyAttackedDrizzt","GLOBAL",1)
Global("X#AjantisDrizztHostile","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisDrizztHostile","GLOBAL",1)
StartDialogueNoSet(Player1)
END


//attacking Dynaheir

IF
AreaCheck("AR4100")
InParty(Myself)
!InParty("Dynaheir")
See("Dynaheir")
!Allegiance("Dynaheir",ENEMY)
Global("X#AjantisDefendDyna","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisDefendDyna","GLOBAL",1)
END

IF
AreaCheck("AR4100")
InParty(Myself) //No "Combatcounter=0" here!
Global("X#AjantisDefendDyna","GLOBAL",1)
Global("X#AjantisDynaheir","GLOBAL",0) //from other Ajantis interjection
Global("X#PartyAttackedDynaheir","GLOBAL",1)
Global("X#AjantisDynaHostile","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisDynaHostile","GLOBAL",1)
StartDialogueNoSet(Player1)
END


//Ajantis BAF (will shut down Global once the Party left the map)

IF
!AreaCheck("AR4100")
InParty(Myself)
Global("X#AjantisDefendDyna","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("X#AjantisDefendDyna","GLOBAL",2)
END


//Rep 20

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
Global("X#AjantisBestReputationTalk","GLOBAL",0)
Reputation(Player1,20)
THEN
RESPONSE #100
SetGlobal("X#AjantisBestReputationTalk","GLOBAL",1)
StartDialogueNoSet(Player1)
END

//Bjornin

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
AreaCheck("AR3100")
Global("HelpBjornin","GLOBAL",2)
Global("X#AjantisHelpBjornin","GLOBAL",1)
Global("X#AjantisBjorninArea","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisBjorninArea","GLOBAL",1)
Dialog(Player1)
END

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
AreaCheck("AR3100")
Global("OgresKilled","GLOBAL",4)
Global("HelpBjornin","GLOBAL",2)
Global("X#AjantisHelpBjornin","GLOBAL",1)
Global("X#AjantisBjorninOgresKilled","GLOBAL",0) //Checkvariable
THEN
RESPONSE #100
SetGlobal("X#AjantisBjorninOgresKilled","GLOBAL",1)
Dialog(Player1)
END

//If Joseph's ring in mine is found
IF
AreaCheck("AR4403")
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("RINGJOS")
Global("X#AjantisWomanNashkellPromise","GLOBAL",1) //Checkvariable
THEN
RESPONSE #100
SetGlobal("X#AjantisWomanNashkellPromise","GLOBAL",2)
Dialog(Player1)
END 


//Mirianne's letter found

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
AreaCheck("AR9700")
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("SCRL3I")
Global("X#AjantisMiriannePromise","GLOBAL",1)
Global("X#AjantisMirianneLetter","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisMirianneLetter","GLOBAL",1)
Dialog(Player1)
END

//Remind to get Samuel to temple
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
GlobalTimerExpired("X#AjantisSamuel","GLOBAL")
PartyHasItem("MISC13") //Samuel
Global("X#AjantisBringSamuel","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisBringSamuel","GLOBAL",1)
Dialog(Player1)
END

//found Nathan

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
OR(2)
AreaCheck("AR8301")
AreaCheck("AR8300")
InParty(Myself)
!StateCheck(Player1,STATE_SLEEPING)
Global("BrunQuest","GLOBAL",1)
PartyHasItem("MISC67")
Global("X#AjantisNathanFound","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisNathanFound","GLOBAL",1)
Dialog(Player1)
END

//Theive's Guild

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
AreaCheck("AR7253") //main area of thief guild
Global("X#AjantisThievesGuild","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisThievesGuild","GLOBAL",1)
Dialog(Player1)
END

//Dopplegangers in Duke's palace
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
AreaCheck("AR7208")
InParty(Myself)
!StateCheck(Player1,STATE_SLEEPING)
Global("NobleDopple","GLOBAL",1) 
Global("X#AjantisNobleDopple","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisNobleDopple","GLOBAL",1)
Dialog(Myself)
END

// Kozah Idol
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
AreaCheck("ARA101")
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("MISC48")
Global("TalkedToCharleston","GLOBAL",2)
Global("X#AjantisKozahStatue","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisKozahStatue","GLOBAL",1)
Dialog(Myself)
END

//Undercellar

IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
AreaCheck("AR7212")
Global("X#AjantisUndercellar","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisUndercellar","GLOBAL",1)
Dialog(Player1)
END

//If Nester's dagger was found
IF
AreaCheck("AR7900")
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("DAGG06")
Global("X#AjantisQuinnPromise","GLOBAL",1)
Global("X#AjantisNestorsDagger","GLOBAL",0) //Checkvariable
THEN
RESPONSE #100
SetGlobal("X#AjantisNestorsDagger","GLOBAL",1)
Dialog(Player1)
END

//If baby Peladan was found
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("MISC96")
AreaCheck("ARW504")
OR(2)
Global("MaraQuest","GLOBAL",1)
Global("MaraTalk","GLOBAL",1)
Global("X#AjantisPeladan","GLOBAL",0) //Checkvariable
THEN
RESPONSE #100
SetGlobal("X#AjantisPeladan","GLOBAL",1)
Dialog(Player1)
END

//Entrance to CK library (should be called before the iron throne bosses are met)
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
AreaCheck("AR6508") //this should be the CK library
Global("X#AjantisLibraryCK","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisLibraryCK","GLOBAL",1)
Dialog(Player1)
END


//########################################
// un-proofread part

//Ajantis recognises low rep of a freshly joined group

//memory of rep > 11 by joining
IF 
InParty(Myself)
ReputationGT(Player1,11)
Global("X#AjantisNoBadRepJoin","GLOBAL",0)
Global("X#AjantisNoBadRepJoinCheck","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisNoBadRepJoin","GLOBAL",1)
SetGlobal("X#AjantisNoBadRepJoinCheck","GLOBAL",1)
END

//bad rep join talk after joining a party with rep < 12
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
Global("X#AjantisNoBadRepJoin","GLOBAL",0)
ReputationLT(Player1,12)
Global("X#AjantisBadRepJoinTalk","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("X#AjantisBadRepJoinTalk","GLOBAL",1)
StartDialogueNoSet(Player1)
END

//Reputation lower 12 (I put this here, as I had to make some adjustments)

//long bad rep talk delay for non-evil alignent PC ~and~ if chapter < 3
IF
InParty(Myself) 
!Alignment(Player1,MASK_EVIL)
GlobalLT("CHAPTER","GLOBAL",3)
Global("X#AjantisBadRepTimer","GLOBAL",0)
!Global("X#AjantisNoBadRepJoin","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("X#AjantisBadRepTimer","GLOBAL",1)
RealSetGlobalTimer("X#AjantisBadRepDelay","GLOBAL",7200) // 2 hour delay
END

//short bad rep talk delay: chapter > 3 ~or~ for evil PC
IF
InParty(Myself) 
OR(2)
Alignment(Player1,MASK_EVIL)
GlobalGT("CHAPTER","GLOBAL",2)
Global("X#AjantisBadRepTimer","GLOBAL",0)
!Global("X#AjantisNoBadRepJoin","GLOBAL",1)
THEN
RESPONSE #100
SetGlobal("X#AjantisBadRepTimer","GLOBAL",1)
RealSetGlobalTimer("X#AjantisBadRepDelay","GLOBAL",1800) //30 min delay
END


//reputation < 12: Ajantis will warn PC
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
OR(2)
Global("X#AjantisBadReputationWarning","GLOBAL",0)
Global("X#AjantisBadReputationWarning","GLOBAL",2)
ReputationLT(Player1,12)
OR(2)
Global("X#AjantisNoBadRepJoin","GLOBAL",1)
RealGlobalTimerExpired("X#AjantisBadRepDelay","GLOBAL")
THEN
RESPONSE #100
SetGlobal("X#AjantisBadReputationIncrease","GLOBAL",0)
SetGlobal("X#AjantisNoBadRepJoin","GLOBAL",2)
SetGlobal("X#AjantisBadReputationWarning","GLOBAL",1)
SetGlobal("X#AjantisBadRepTimer","GLOBAL",0)
Dialog(Player1)
END


//Ajantis recognises rep increase after former bad rep talk
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
OR(2)
Global("X#AjantisBadRepJoinTalk","GLOBAL",2) 
Global("X#AjantisBadReputationWarning","GLOBAL",2)
Global("X#AjantisBadReputationIncrease","GLOBAL",0)
ReputationGT(Player1,11)
!Global("X#AjantisRomanceMatch","GLOBAL",1) //maybe differs for romance
THEN
RESPONSE #100
RealSetGlobalTimer("X#AjantisBadRepDelay","GLOBAL",1)
SetGlobal("X#AjantisBadRepJoinTalk","GLOBAL",3) //to prevent from looping 
SetGlobal("X#AjantisBadReputationIncrease","GLOBAL",1)
StartDialogueNoSet(Player1)
END

//Ajantis good rep talk for rep >17
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
Global("X#AjantisGoodReputationTalk","GLOBAL",0)
ReputationGT(Player1,17)
THEN
RESPONSE #100
SetGlobal("X#AjantisGoodReputationTalk","GLOBAL",1)
StartDialogueNoSet(Player1)
END

//reputation < 12: Ajantis will warn PC
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
OR(2)
Global("X#AjantisBadReputationWarning","GLOBAL",0)
Global("X#AjantisBadReputationWarning","GLOBAL",2)
ReputationLT(Player1,12)
OR(2)
Global("X#AjantisNoBadRepJoin","GLOBAL",1)
RealGlobalTimerExpired("X#AjantisBadRepDelay","GLOBAL")
THEN
RESPONSE #100
SetGlobal("X#AjantisBadReputationIncrease","GLOBAL",0)
SetGlobal("X#AjantisNoBadRepJoin","GLOBAL",2)
SetGlobal("X#AjantisBadReputationWarning","GLOBAL",1)
SetGlobal("X#AjantisBadRepTimer","GLOBAL",0)
Dialog(Player1)
END

//if the "wanted" letter is found on an opponent(SCRLKAR.ITM)
IF
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("SCRLKAR")
Global("X#AjantisWantedLetter","GLOBAL",0) //Checkvariable
THEN
RESPONSE #100
SetGlobal("X#AjantisWantedLetter","GLOBAL",1)
StartDialogueNoSet(Player1)
END 

//if dead Chelak is found
IF
OR(2)
AreaCheck("AR8801")
AreaCheck("AR8800")
InParty(Myself) CombatCounter(0) !See([ENEMY])
!StateCheck(Player1,STATE_SLEEPING)
PartyHasItem("MISC90")
Global("X#AjantisTiberHelp","GLOBAL",1)//Checkvariable
THEN
RESPONSE #100
SetGlobal("X#AjantisTiberHelp","GLOBAL",2)
StartDialogueNoSet(Player1)
END
