Scriptname BaboFollowerSceneTriggerScript extends ObjectReference  

Quest Property RequiredQuest Auto

Int Property RequestedStage Auto
Int Property RequestedStage02 Auto

Int property NextStage Auto

Scene Property SceneToStart  Auto  
{scene to start}

Actor[] Property ActorArray Auto

bool Property ActorArrayToggle = false Auto 
{by default, it is set to false. set to true if you want this event to be triggered by kills}

bool Property DoOnce = true Auto  
{set to true if you want this trigger to fire only once
false means it will try to start the scene each time
the trigger actor enters it
}

Actor property triggerActor auto
{by default, the player}

Function ResetTrigger()
	gotoState("waiting")
	tempTriggered = false
	enable()
EndFunction

auto state waiting
EVENT onTriggerEnter(objectReference actronaut)
Actor actronautActor = actronaut as actor 
if (triggerActor == None) || (actronaut as actor == triggerActor)
	if !(triggerActor.isincombat()) || !(actronautActor.isincombat())
		if (RequiredQuest.GetStage() == (RequestedStage)) || (RequiredQuest.GetStage() == (RequestedStage02))
			If CountActors() || !ActorArrayToggle
			SceneToStart.Start()
			RequiredQuest.Setstage(Nextstage)
			tempTriggered = true
			if DoOnce
				gotoState("done")
				disable()
;				delete()
			endIf
			Endif
		endif
	endif
endif
endEVENT
endState

state done
; do nothing
endState

Bool Function CountActors()
Int iIndex = ActorArray.Length
	If iIndex != 0
	While iIndex
		iIndex -= 1 ; 29'th element is 30'th Draugr
		Actor kActor = ActorArray[iIndex]
		If kActor.isdead()
		Else
			Return false
		EndIf
	EndWhile
	Else
		Return false
	EndIf
	Return True
EndFunction


bool tempTriggered = false
