/* Use this script to extend the bottom of X#BELGIN.bcs */

/* Quest is only initiated if Tiax is in the party, but party can pretend he isn't */

IF %BGT_VAR%
Global("X#TiaxQuest","GLOBAL",0)
InParty("tiax")
See("tiax")
InMyArea(Player1)
THEN 
RESPONSE #100
SetGlobal("X#TiaxQuest","GLOBAL",1)
END

/* Initiate conversation */
/* Using Dialogue() here instead of MoveToObject() and SDNS() because of potential problems if the PC leaves the area before Belgin gets a chance to corner him. */
IF %BGT_VAR%
Global("X#TiaxQuest","GLOBAL",1)
See("tiax")
InMyArea(Player1)
!StateCheck(Player1,CD_STATE_NOTVALID)
!StateCheck(Myself,CD_STATE_NOTVALID)
THEN 
RESPONSE #100
Dialog(Player1)
END

/* Belgin vanishes from the Helm and Cloak if Karris is sent after him */
IF %BGT_VAR%
Global("X#BelginPlacement","GLOBAL",11)
THEN
RESPONSE #100
SetGlobal("X#BelginPlacement","GLOBAL",12)
DestroySelf()
END

/* backup for leaving FOREVAR */
IF %BGT_VAR%
Global("X#BelginPlacement","GLOBAL",5)
THEN
RESPONSE #100
SetGlobal("X#BelginPlacement","GLOBAL",6)
EscapeArea()
END

/* moves to Blade & Stars 225 MoveBetweenAreas(S:Area*,P:Location*,I:Face*) This, although not often seen, is an extremely useful effect. It will allow an actor to move himself from one area to another, keeping his HP, effects, vital statistics, etc. This is the ideal action to move non-party NPC's from area to area. */
/* MakeGlobal() requires that ToB be installed! Instead of using the combination MakeGlobal() and MoveBetweenAreas(), why not use EscapeAreaMove()? It does more or less the same thing as the two actions in combination, and doesn't require ToB. I'll include the suggested recode as a commented out possibility */
IF %BGT_VAR%
Global("X#BelginPlacement","GLOBAL",7)
THEN
RESPONSE #100
SetGlobal("X#BelginPlacement","GLOBAL",8)
EscapeAreaMove("%NWBaldursGate_Helm&Cloak_L1%",327,811,0)
END

/* After his name is cleared */
IF %BGT_VAR%
Global("X#TiaxQuest","GLOBAL",5)
See(Player1)
THEN 
RESPONSE #100
Dialog(Player1)
END

IF %BGT_VAR%
Global("X#BelginBattle","GLOBAL",1)
Global("X#BelginEnemy","LOCALS",0)
THEN
RESPONSE #100
SetGlobal("X#BelginEnemy","LOCALS",1)
Enemy()
END

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

IF %BGT_VAR%
Allegiance(Myself,ENEMY)
Global("X#BelginBuffs","LOCALS",0)
THEN
RESPONSE #100
ReallyForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
ReallyForceSpell(Myself,CLERIC_FREE_ACTION)
ReallyForceSpell(Myself,CLERIC_BLESS)
SetGlobal("X#BelginBuffs","LOCALS",1)
END

IF
Allegiance(Myself,ENEMY)
THEN
RESPONSE #100
MoveToObject(NearestEnemyOf(Myself))
AttackOneRound(NearestEnemyOf(Myself))
END
