Scriptname _00E_ComplexFollowTrigScript extends ObjectReference  
{Use this script if you have an NPC following the player. If the player leaves this box, the NPC will make a remark and stay put. 
If the player returns into the triggerbox, the NPC will follow him again.}

;=====================================================================================
;              							EVENTS                  					 
;=====================================================================================

Event OnTriggerEnter(ObjectReference akActionRef)
	if (akActionRef == PlayerREF)
		myActor = FollowingNPC.GetActorReference() 
			if (myActor.GetCurrentPackage() == FollowingPackage) || (myActor.GetCurrentPackage() == WaitPackage)
				If (Counter.GetValueInt() == 0)
					myActor.Say(NPCPlayerReturnsDialogue)
				EndIf
				Counter.SetValueInt(Counter.GetValueInt() + 1)
				Debug.MessageBox(akActionRef + " just entered us!" + Counter.GetValue())
				myActor.EvaluatePackage()
			EndIf
	EndIf			
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
	if (akActionRef == PlayerREF)
		if (myActor.GetCurrentPackage() == FollowingPackage) || (myActor.GetCurrentPackage() == WaitPackage)
			Counter.SetValueInt((Counter.GetValueInt() - 1))
			Debug.MessageBox(akActionRef + " just left us!" + Counter.GetValue())
			myActor.EvaluatePackage()
			if (Counter.GetValueInt() == 0)
				myActor.Say(NPCPlayerLeavesDialogue)
			EndIf
		endif
	endif
			
EndEvent


;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================

Actor myActor

Topic Property NPCPlayerLeavesDialogue Auto
{The topic the NPC says when the player leaves the triggerbox, such as "I'll wait for you here"}
Topic Property NPCPlayerReturnsDialogue Auto
{The topic the NPC says when the player returns, such as "Glad you're back"!}

ReferenceAlias Property FollowingNPC Auto
{The Alias of the NPC who is following the player}

Package Property FollowingPackage Auto
{The follow package that is usually running}
Package Property WaitPackage Auto
{The wait package that will run if the player leaves}

Actor Property PlayerREF Auto

GlobalVariable Property Counter Auto
{Set this to a custom global variable}