Scriptname _00E_QuestFunctions extends Quest Conditional
{This script is meant to be attached to any quests and serves as a Function library. Simply import it to call Global functions, and create a script property to access non-global functions}

Import math
Import Utility

;=====================================================================================
;   		      						EXP            					 
;=====================================================================================

Function GiveEP(int ToGive)

	If (PlayerREF as _00E_EPUpdateFunctions).receiveEP(ToGive)
		; Player receives EP
	EndIf

EndFunction

;=====================================================================================
;   		      						SYMPATHY            					 
;=====================================================================================

Function ModSympathyNG(Actor akSympathyActor, int iSympathyMod, bool bIsFlirt = False, bool bStringOverride = False, String sOverride = "") 

	Levelsystem_SympathyActor.ForceRefTo(akSympathyActor)

	ActorBase sympathyBase = akSympathyActor.GetActorBase()

	If sympathyBase == _00E_MC_Jespar
		SympathyJespar.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_MC_Calia
		SympathyCalia.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_CapitalCityMaelGroschenfrst
		SympathyMaelGroschenfuerst.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_SC_Dijaam
		SympathyDijaam.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_SC_Tharael
		SympathyTharael.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_MQ11c_Ryneus
		SympathyRyneus.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_MC_Yuslan
		SympathyYuslan.Mod(iSympathyMod)
	ElseIf sympathyBase == _00E_FS_NQ02_Esme
		SympathyEsme.Mod(iSympathyMod)
	EndIf
	
	If bIsFlirt 
		If sympathyBase == _00E_MC_Jespar
			JesparFlirtCounter.SetValueInt(JesparFlirtCounter.GetValueInt() + 1)
		ElseIf sympathyBase == _00E_MC_Calia
			CaliaFlirtCounter.SetValueInt(CaliaFlirtCounter.GetValueInt() + 1)
		ElseIf sympathyBase == _00E_SC_Dijaam
			DijaamFlirtCounter.SetValueInt(DijaamFlirtCounter.GetValueInt() + 1)
		ElseIf sympathyBase == _00E_SC_Tharael
			TharaelFlirtCounter.SetValueInt(TharaelFlirtCounter.GetValueInt() + 1)
		EndIf
	EndIf
	
	String sActorName = sympathyBase.GetName()

	If !bStringOverride
		If (iSympathyMod > 0) && (iSympathyMod <= 5) 
			_00E_Levelsystem_sApproves.Show()
			; Debug.Notification(sActorName + sLevelsystemAppreciate + ".")
		ElseIf (iSympathyMod > 5) && (iSympathyMod <= 10) 
			_00E_Levelsystem_sAppreciates.Show()
			; Debug.Notification(sActorName + sLevelsystemAppreciateALot + ".")
		ElseIf (iSympathyMod > 10) && (iSympathyMod <= 20) 
			_00E_Levelsystem_sAppreciatesALot.Show()
			; Debug.Notification(sActorName + sLevelsystemApproves + ".")
		ElseIf (iSympathyMod < 0) && (iSympathyMod >= -5) 
			_00E_Levelsystem_sDislikes.Show()
			; Debug.Notification(sActorName + sLevelsystemDislikes + ".")
		ElseIf (iSympathyMod < -5) && (iSympathyMod >= -10) 
			_00E_Levelsystem_sHurt.Show()
			; Debug.Notification(sActorName + sLevelsystemOffended + ".")
		ElseIf (iSympathyMod < -10) && (iSympathyMod >= -20) 
			_00E_Levelsystem_sVeryHurt.Show()
			; Debug.Notification(sActorName + sLevelsystemVeryOffended + ".")
		EndIf
	Else
		Debug.Notification(sActorName + sOverride)
	EndIf
	
EndFunction

;=====================================================================================
;   		      						CAMERA            					 
;=====================================================================================

Function LockCamera() 

	fCameraMaxDistance = Utility.GetINIFloat("fVanityModeMaxDist:Camera")
	Utility.SetINIFloat("fVanityModeMaxDist:Camera", Utility.GetIniFloat("fVanityModeMinDist:Camera"))
	
EndFunction

Function UnlockCamera() 

	Utility.SetINIFloat("fVanityModeMaxDist:Camera", fCameraMaxDistance)

EndFunction

;=====================================================================================
;              							GLOBAL FUNCTIONS                  					 
;=====================================================================================

Function Brawl(Actor pTarget, Actor pTargetFriend = None)

	BrawlKeyword.SendStoryEvent(None, pTarget, pTargetFriend)
	
EndFunction

function PlayerAIWalkStop() Global

	Game.ShowFirstPersonGeometry(True)
	Game.SetPlayerAIDriven(False)
	Game.EnablePlayerControls()
	
endFunction

function PlayerAIWalk(bool abLockedSight = True) Global

	Game.ShowFirstPersonGeometry(False)
	Game.SetPlayerAIDriven(True)
	If abLockedSight == True
		Game.DisablePlayerControls(true, true, true, true, true, true, true, true)
	ElseIf abLockedSight == False
		Game.DisablePlayerControls(true, true, true, False, true, true, true, true)
	EndIf
	
endFunction

Function DisableDialogueQuitting() Global
{Disables the TAB Key during dialogue. Resets automatically upon dialogue exit via Goodbye.}

	if UI.IsMenuOpen("Dialogue Menu")
		if UI.GetBool("Dialogue Menu", "_root.DialogueMenu_mc.bEnableTab") != true
			; Suspected non-Enderal dialoguemenu.swf replacer, rechecking value in order to be sure.
			UI.InvokeBool("Dialogue Menu", "_root.DialogueMenu_mc.SetVariable", True)
			if UI.GetBool("Dialogue Menu", "_root.DialogueMenu_mc.bEnableTab") != true
				Debug.Notification("Detected incompatible dialoguemenu.swf!")
			endif
		endif
	endif

	UI.InvokeBool("Dialogue Menu", "_root.DialogueMenu_mc.SetVariable", False)

EndFunction

Function EnableDialogueQuitting() Global
{Disables the TAB Key during dialogue. Resets automatically upon dialogue exit via Goodbye.}

	UI.InvokeBool("Dialogue Menu", "_root.DialogueMenu_mc.SetVariable", True)

EndFunction

Function RefreshFace() Global

	String facegen = "bUseFaceGenPreprocessedHeads:General"
	Utility.SetINIBool(facegen, False)
	Game.GetPlayer().QueueNiNodeUpdate()
	Utility.SetINIBool(facegen, True)

EndFunction

Function ShowHelpMessage(Message msg, Float fDuration = 5.0, String sEvent = "Empty") Global

	Message.ResetHelpMessage(sEvent)
	msg.ShowAsHelpMessage(sEvent, fDuration, 1.0, 1)

EndFunction

Function SafeMoveTo(ObjectReference refToMove, ObjectReference targetRef, Bool bFadeIn = False) Global

	; A safer way to move an object reference to another ref than just MoveTo.
	; Mostly for actors to take their intended positions. 
	; It's better for the actor to be already running a package that moves them to targetRef at the moment this function is called.

	refToMove.Disable()
	refToMove.MoveTo(targetRef)
	refToMove.Enable(bFadeIn)

EndFunction

Function SafeMoveTo_NoWait(ObjectReference refToMove, ObjectReference targetRef, Bool bFadeIn = False) Global

	; A safer way to move an object reference to another ref than just MoveTo (without waiting for it to be fully enabled).
	; Mostly for actors to take their intended positions. 
	; It's better for the actor to be already running a package that moves them to targetRef at the moment this function is called.

	refToMove.Disable()
	refToMove.MoveTo(targetRef)
	refToMove.EnableNoWait(bFadeIn)

EndFunction

Bool Function DistanceFailsafeMoveTo(ObjectReference refToMove, ObjectReference targetRef, Float fTooFarDistance) Global

	; Moves refToMove to targetRef if refToMove is not within fTooFarDistance from targetRef.
	; Mostly for character travel failsafes in scenes.

    ; Debug.Trace("FailsafeMoveTo: refToMove = " + refToMove + "; d = " + refToMove.GetDistance(targetRef))
    If refToMove.GetDistance(targetRef) >= fTooFarDistance
        refToMove.MoveTo(targetRef)
        ; Debug.Trace("FailsafeMoveTo: refToMove = " + refToMove + " force-moved to marker")
        Return True
    Else
        Return False
    EndIf

EndFunction

Function WaitForReferenceToLoad(ObjectReference ref) Global

    Int maxIterationsToWait = 180
    While ref.Is3DLoaded() == False && maxIterationsToWait > 0
        ; Utility.Wait(0.02)
        maxIterationsToWait -= 1
    EndWhile

EndFunction

Float Function NormalizeHour(Float fHour) Global

	If fHour >= 24.0
		Return (fHour - 24.0)
	ElseIf fHour < 0.0
		Return (fHour + 24.0)
	Else
		Return fHour
	EndIf

EndFunction

Bool Function HourIsInRange(Float fHour, Float fHourStart, Float fHourEnd) Global

	; "Smart" test for fHour being withing a range.
	; Works both with "day" ranges (e.g., 06:00- 20:00) and with "night" ranges (e.g., 21:00-06:00)

	fHour      = NormalizeHour(fHour)
	fHourStart = NormalizeHour(fHourStart)
	fHourEnd   = NormalizeHour(fHourEnd)

	If fHourStart <= fHourEnd ; Something like 06:00 - 20:00
		Return (fHour >= fHourStart && fHour < fHourEnd)
	Else ; Something like 20:00 - 06:00
		Return (fHour >= fHourStart || fHour < fHourEnd)
	EndIf

EndFunction

Function EnableReferenceFormList(FormList referenceList) Global

	Int nItems = referenceList.GetSize()
	Int i = 0

	If nItems < 128 && nItems > 1
		Form[] refArray = referenceList.ToArray()
		While i < nItems
			(refArray[i] as ObjectReference).EnableNoWait()
			i += 1
		EndWhile
	Else
		While i < nItems
			(referenceList.GetAt(i) as ObjectReference).EnableNoWait()
			i += 1
		EndWhile
	EndIf

EndFunction

Function DisableReferenceFormList(FormList referenceList) Global

	Int nItems = referenceList.GetSize()
	Int i = 0

	If nItems < 128 && nItems > 1
		Form[] refArray = referenceList.ToArray()
		While i < nItems
			(refArray[i] as ObjectReference).DisableNoWait()
			i += 1
		EndWhile
	Else
		While i < nItems
			(referenceList.GetAt(i) as ObjectReference).DisableNoWait()
			i += 1
		EndWhile
	EndIf

EndFunction

Float Function SetActorScale(Actor akActor, Float fNewScale) Global

	; Sets the scale of akActor to fNewScale and returns the old scale.
	; This is a workaround for GetScale() returning the cumulative scale of Race.Height * Actor.Scale for actors.
	; So it results in a messed up scale if the value returned by GetScale() is used to revert the scale change for an actor whose race has a non-1.00 height (for example, HighElfRace)

	Float fOriginalScale = akActor.GetScale()
	akActor.SetScale(fNewScale)
	; Now use the known fNewScale and the return of GetScale() to get the race height coeff, and apply that coeff to fOriginalScale to calculate the true actor's reference scale.
	Return fOriginalScale * fNewScale / akActor.GetScale()

EndFunction

Float Function AdjustTimePeriodByEngineTimerError(Float fUnadjustedPeriod) Global

	; In SE, the game time runs slower than the real time by about 2.5/60 second
	
	Return fUnadjustedPeriod - (2.5 * Math.Floor(fUnadjustedPeriod) / 60.0)

EndFunction

Function PrintDebugMessage(String msg) Global
	; Dummy to fix error messages in Papyrus.log about missing function
EndFunction

Function PDB(String msg) Global
	; Dummy to fix error messages in Papyrus.log about missing function
EndFunction



;=====================================================================================
;              				GENERAL NON-GLOBAL FUNCTIONS                  			
;=====================================================================================

Function RemoveSilence()

	_00E_SilenceTransitionLowPriority02.Remove()
	_00E_Music_Special_MQ12b_Samael.Remove()
	_00E_SilenceLongTransitionHighPriority.Remove()
	_00E_SilenceTransitionLowPriority.Remove()
	_00E_SilenceTransitionHighPriority.Remove()
	_00E_SilenceAbruptHighPriority.Remove()
	_00E_Music_Special_TavernSilence.Remove()
	AudioCategoryAMB.UnMute()
	AudioCategoryAMBr.UnMute()
	AudioCategorySFX.UnMute()
	
EndFunction

Function RemoveCombatSoundtracks()

	int iIndex = _00E_MUS_AllCombatSoundtracks.GetSize()
	
	while iIndex > 0
		iIndex -= 1
		MusicType musicToRemove = _00E_MUS_AllCombatSoundtracks.GetAt(iIndex) as MusicType
		musicToRemove.Remove()
	endwhile

EndFunction

Function ShowFailedMessage(String companionName = "Jespar")

	if companionName == "Jespar" && _00E_DisableQuestTutorials.GetValueInt() == 0
		_00E_Tutorial_Companions02_Jespar.Show()
	ElseIf _00E_DisableQuestTutorials.GetValueInt() == 0
		_00E_Tutorial_Companions02_Calia.Show()
	EndIf
	
EndFunction

Function ShowBrawlTutorial()

	If _00E_DisableSkillTutorials.GetValueInt() == 0
		Message.ResetHelpMessage("Brawl")
		_00E_Tutorial_Brawl.ShowAsHelpMessage("Brawl", 3, 3, 1)
	EndIf

EndFunction

Function PriestHeal()
{Called in dialoges with priests}
	
	PlayerREF.RestoreActorValue("Health", PlayerREF.GetAV("Health"))
	_00E_PriestCureDiseases.Cast(PlayerREF, PlayerREF)

EndFunction

Function TeleportNPC(Actor NPCToTeleport, ObjectReference TeleportTarget)
{Teleport an NPC, with animations and FX}

	Weapon weap01 = NPCToTeleport.GetEquippedWeapon(0)
	Weapon weap02 = NPCToTeleport.GetEquippedWeapon(1)
	
	If weap01 != None
		NPCToTeleport.UnEquipItem(weap01)
	EndIf
	If weap02 != None
		NPCToTeleport.UnEquipItem(weap02)
	EndIf
	NPCToTeleport.PlayIdle(IdleMagic_01)
	_00E_TeleportCastSound.Play(NPCToTeleport)
	Wait(3)

	if NPCToTeleport.GetActorBase().GetSex() == 0
		NPCToTeleport.PlayIdle(IdleT02AscendMale)
	Else
		NPCToTeleport.PlayIdle(IdleT02AscendFemale)
	EndIf

	_00E_MagicProtectionSpellM.Play(NPCToTeleport)
	Wait(4)
	TimeFadeOut01FXS.Play(NPCToTeleport)
	Wait(2)
	_00E_A2_Ghostwalk_TeleportDoneSound.Play(NPCToTeleport)

	ObjectReference TeleportFXMarker = NPCToTeleport.PlaceAtMe(XMarkerHeading, 1)
	TeleportFXMarker.MoveTo(NPCToTeleport, 0.0, 0.0, 100.0)
	ObjectReference FXExplosion = TeleportFXMarker.PlaceAtMe(_00E_TeleportExplosion, 1)
	_00E_NPCTeleportExplosionIMOD.Apply()
	Game.ShakeCamera(afStrength = 0.2)
	NPCToTeleport.MoveTo(TeleportTarget)
	Debug.sendAnimationEvent(NPCToTeleport, "IdleWebEnterInstant")
	NPCToTeleport.setActorValue("Variable03", 5)
	TimeFadeOut01FXS.Stop(NPCToTeleport)
	If NPCToTeleport.Is3DLoaded()
		TimeFadeIn01FXS.Play(NPCToTeleport)
	EndIf
	Wait(0.5)
	NPCToTeleport.playidle(WebIdleExit)
	Wait(1)
	TimeFadeIn01FXS.Stop(NPCToTeleport)
	NPCToTeleport.setActorValue("Variable03", 0)
	If weap01 != None
		NPCToTeleport.EquipItem(weap01)
	EndIf
	If weap02 != None
		NPCToTeleport.EquipItem(weap02)
	EndIf

	Return

EndFunction

Function SetAllowIdleChatter(bool bAllow = False)

	if !bAllow
		bAllowIdleChatter = False
		SendModEvent("IdleChatterOff")
	Elseif bAllow
		bAllowIdleChatter = True
	EndIf

EndFunction

Function ShowSynergyMessage()

	_00E_Levelsystem_sSynergyDiscovered.Show()
	GiveEP(150)

	If _00E_AchievementsEnabled.GetValueInt() == 1 && !bUnlockedSynergyAchievement
		Game.UnlockAchievement("END_SYNERGY_01")
		bUnlockedSynergyAchievement = true
	EndIf

EndFunction

Function SkipTimeToHour(Float fNewHourOfDay, Float fMinHoursToSkip = 0.0)

	; Progresses the current in-game time to the desired hour (and optionally, by no less than fMinHoursToSkip hours), moving to the next day if needed

	Float fCurHour = GameHour.GetValue()
	If fNewHourOfDay <= fCurHour
		fNewHourOfDay += 24.0 ; Go to the next day
	EndIf
	If (fNewHourOfDay - fCurHour) < fMinHoursToSkip
		fNewHourOfDay += 24.0 ; Go to the next day
	EndIf
	GameHour.SetValue(fNewHourOfDay)
	SendModEvent("TimeSkip")

EndFunction

Function SkipHours(Float fHoursToSkip)

	; Progresses the current in-game time by fHoursToSkip hours

	GameHour.SetValue(GameHour.GetValue() + fHoursToSkip)
	SendModEvent("TimeSkip")

EndFunction


;=====================================================================================
;   		      						Player Teleport            					 
;=====================================================================================

Event OnUpdate()
	Game.EnablePlayerControls()
EndEvent

Function TeleportPlayer(ObjectReference TeleportTarget)

	Game.DisablePlayerControls(abCamSwitch = true)
	Wait(3)
	If PlayerREF.IsWeaponDrawn()
		PlayerREF.SheatheWeapon()
	EndIf
	Wait(2)
	TeleportIn()
	PlayerREF.MoveTo(TeleportTarget)
	TeleportOut()
	RefreshFace()
	
EndFunction

Function TeleportIn()

	Game.ForceThirdPerson()

	if Player.GetSex() == 0
		PlayerREF.PlayIdle(IdleT02AscendMale)
	Else
		PlayerREF.PlayIdle(IdleT02AscendFemale)
	EndIf

	_00E_MagicProtectionSpellM.Play(PlayerREF)
	Wait(2.7)
	TimeFadeOut01FXS.Play(PlayerREF)
	Wait(1.3)
	_00E_TeleportImod.Apply()
	Wait(2)

EndFunction

Function TeleportOut()

	_00E_A2_Ghostwalk_TeleportDoneSound.Play(playerREF)
	PlayerREF.PlaceAtMe(_00E_NPCOorbayaTeleportExplosionBlue, 1)
	Debug.sendAnimationEvent(playerREF, "IdleWebEnterInstant")
	PlayerREF.setActorValue("Variable03", 5)
	TimeFadeOut01FXS.Stop(PlayerREF)
	TimeFadeIn01FXS.Play(PlayerREF)
	Wait(0.5)
	PlayerREF.playidle(WebIdleExit)
	TimeFadeIn01FXS.Stop(PlayerREF)
    PlayerREF.setActorValue("Variable03", 0)
    PlayerREF.DrawWeapon()
	Wait(3)
	Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState")
	PlayerREF.PlayIdle(IdleForceDefaultState)
    PlayerREF.setActorValue("Variable03", 0)
    Game.EnablePlayerControls()
	_FS_Phasmalist_ControlQuest.MoveApparitionToPlayer()
	RegisterForSingleUpdate(2)

EndFunction

;=====================================================================================
;   		      						FADE TO BLACK            					 
;=====================================================================================

Function FadeToBlackAndBack()

	FadeToBlackIMOD.Apply()
	Wait(2.8)
	FadeToBlackIMOD.PopTo(FadeToBlackHoldIMOD)
	Wait(1.9)
	FadeToBlackHoldIMOD.PopTo(FadeToBlackBackIMOD)

EndFunction

Function FadeToBlack()

	FadeToBlackIMOD.Apply()
	Wait(2.8)
	FadeToBlackIMOD.PopTo(FadeToBlackHoldImod)
	
EndFunction

Function FadeToBlackBack()

	FadeToBlackHoldImod.PopTo(FadeToBlackBackImod)

EndFunction

;=====================================================================================
;   		      						FAKEHEADTRACK (unused?)            			  
;=====================================================================================

function FakeHeadtrackStart() 

	_00E_HeadtrackGlobal.SetValueInt(1)
	game.SetPlayerAIDriven(true)
	game.DisablePlayerControls(true, true, true, true, true, true, true, false, 0)
	PlayerREF.AddPerk(_00E_VisionPerk)
	UpdateSpeed(PlayerREF)
	Wait(0.500000)
	PlayerREF.RemoveSpell(_00E_Vision_UpdateAb)
	
endFunction

function FakeHeadtrackEnd()
	
	_00E_HeadtrackGlobal.SetValueInt(0)
	game.EnablePlayerControls(true, true, true, true, true, true, true, true, 0)
	game.SetPlayerAIDriven(false)
	PlayerREF.RemovePerk(_00E_VisionPerk)
	UpdateSpeed(PlayerREF)
	Wait(0.500000)
	
endFunction

;=====================================================================================
;   		      						VISION          			  				
;=====================================================================================

function EndVision(bool ScenePlaying, Scene RunningScene = None)

	If PlayerREF.HasSpell(_00E_Vision_TimeSpell)
		PlayerREF.RemoveSpell(_00E_Vision_TimeSpell)
	ElseIf PlayerREF.HasSpell(_00E_Vision_NoTimeSpell)
		PlayerREF.RemoveSpell(_00E_Vision_NoTimeSpell)
	ElseIf PlayerREF.HasSpell(_00E_Vision_NoTimeSubtleSpell)
		PlayerREF.RemoveSpell(_00E_Vision_NoTimeSubtleSpell)
	EndIf
	VisionLight.Delete()
	If ScenePlaying == True && RunningScene.IsPlaying()
		RunningScene.Stop()
	EndIf
	PlayerREF.MoveTo(PlayerVisionStartMarker)

endFunction

Function VisionEffectTimestop(bool bSilent = False, bool bCustomImod = False, bool bCustomMusic = False)

	If bCustomImod == False
		_00E_VisionStartTimestopIMOD.Apply()
		_00E_VisionImod.ApplyCrossFade(0.25)
	EndIf
	
	PlayerREF.AddSpell(_00E_Vision_TimeSpell, False)
	
	if !bCustomMusic
		_00E_SilenceAbruptHighPriority.Add()
	EndIf
	
	MagRacialBattlecryFire.Play(PlayerREF)
	fPlayerSpeedBeforeVision = PlayerREF.GetActorValue("SpeedMult")
	PlayerREF.SetActorValue("SpeedMult", 35)
	UpdateSpeed(PlayerREF)
	
	If !bSilent
		VisionSound = _00E_VisionLPM.Play(PlayerREF)
	EndIf
	
	_00E_VisionShaderParticles.Apply(0.5)
	AudioCategoryFST.Mute()
	
	PlayerREF.SetGhost(True)
	
	PlayerVisionStartMarker = PlayerREF.PlaceAtMe(XMarker as form, 1, false, false)
	PlayerVisionFailsaveMarker.MoveTo(PlayerREF)
	Game.DisablePlayerControls(false, true, true, false, true, false, true, false)
	Game.ForceFirstPerson()
	Game.ShowFirstPersonGeometry(False)
	Wait(0.100000)
		
EndFunction

Function VisionEffectTimestopStop(bool bMovementHasBeenLocked = False)

	float fSpeedMultBefore = PlayerREF.GetAV("speedMult")

	PlayerREF.SetGhost(False)
	Game.DisablePlayerControls()
	PlayerREF.SetActorValue("SpeedMult", PlayerSpeed)
	PlayerREF.SetGhost(False)
	AudioCategoryFST.UnMute()
	UpdateSpeed(PlayerREF)
	Game.ShowFirstPersonGeometry(True)
	
	If !bMovementHasBeenLocked
		If PlayerVisionFailsaveMarker.GetDistance(PlayerREF) <= 1000
			PlayerREF.MoveTo(PlayerVisionStartMarker)
		Elseif PlayerVisionFailsaveMarker.GetDistance(PlayerREF) >= 1000
			PlayerREF.MoveTo(PlayerVisionFailsaveMarker)
		EndIf
	EndIf
	
	PlayerREF.SetGhost(False)
	Sound.StopInstance(VisionSound)
	MAGConjurePortalClose.Play(PlayerREF)
	_00E_SilenceAbruptHighPriority.Remove()
	PlayerREF.RemoveSpell(_00E_Vision_TimeSpell)
	_00E_VisionShaderParticles.Remove(0.5)
	_00E_VisionEndImod.ApplyCrossFade(1)
	Wait(0.5)
	PlayerREF.SetAV("speedMult", fPlayerSpeedBeforeVision)
	
	If PlayerREF.GetAV("speedMult") < 50
		PlayerREF.SetAV("speedMult", 100)
	EndIf

	UpdateSpeed(PlayerREF)
	Game.EnablePlayerControls()
	Game.SetPlayerAIDriven(0)
	Game.ShowFirstPersonGeometry(True)
	_00E_SilenceAbruptHighPriority.Remove()
	
EndFunction

Function VisionEffectNoTimestop(Formlist RefsInvolved, Formlist ActorsToFreeze, bool bCustomMusic = False)

	Game.ShowFirstPersonGeometry(False)
	PlayerREF.SetAlpha(0.1)
	PlayerREF.AddPerk(_00E_VisionPerk)
	UpdateSpeed(PlayerREF)
	MagRacialBattlecryFire.Play(PlayerREF)
	
	if !bCustomMusic
		_00E_SilenceAbruptHighPriority.Add()
	EndIf
	
	AudioCategoryFST.Mute()
	PlayerVisionStartMarker = PlayerREF.PlaceAtMe(XMarker as form, 1, false, false)
	PlayerVisionFailsaveMarker.MoveTo(PlayerREF)
	PlayerREF.SetGhost(True)
	VisionSound = _00E_VisionLPM.Play(PlayerREF)
	_00E_VisionStartImod.Apply()
	
	If PlayerREF.IsInInterior()
		_00E_VisionShaderParticles.Apply(0.5)
	EndIf
	
	if RefsInvolved != None
		int iIndex = RefsInvolved.GetSize()

		while iIndex > 0
			iIndex -= 1
			Actor VisionREF = RefsInvolved.GetAt(iIndex) as Actor
			if VisionREF.IsDisabled()
				VisionREF.EnableNoWait()
			EndIf
			VisionRef.SetAlpha(0.5)
			MS04MemoryFXBody01VFX.Play(VisionREF)
		EndWhile
	endif

	if ActorsToFreeze != None
		int iIndex02 = ActorsToFreeze.GetSize()

		while iIndex02 > 0
			iIndex02 -= 1
			Actor FreezeREF = ActorsToFreeze.GetAt(iIndex02) as Actor
			FreezeREF.EnableAI(False)
		EndWhile
	endif
	
	_00E_MQ16_VisionIMOD.Remove()
	_00E_VisionImod.ApplyCrossFade(1)
	
EndFunction

Function VisionEffectNoTimestopStop(Formlist RefsInvolved, Formlist ActorsToFreeze, bool bHasBeenRestrained = False)

	PlayerREF.SetAlpha(1.0)
	Game.ShowFirstPersonGeometry(True)
	
	If !bHasBeenRestrained
		If PlayerVisionFailsaveMarker.GetDistance(PlayerREF) <= 1000
			PlayerREF.MoveTo(PlayerVisionStartMarker)
		Elseif PlayerVisionFailsaveMarker.GetDistance(PlayerREF) >= 1000
			PlayerREF.MoveTo(PlayerVisionFailsaveMarker)
		EndIf
	EndIf
	
	_00E_VisionEndImod.ApplyCrossFade(1)
	If PlayerREF.IsInInterior()
		_00E_VisionShaderParticles.Remove(0.5)
	EndIf
	
	if RefsInvolved != None
		int iIndex = RefsInvolved.GetSize()

	    while iIndex > 0
	        iIndex -= 1
	        Actor VisionREF = RefsInvolved.GetAt(iIndex) as Actor
	        MS04MemoryFXBody01VFX.Stop(VisionREF)
	        VisionRef.SetAlpha(1)
	    EndWhile
	endif

	if ActorsToFreeze != None
		int iIndex02 = ActorsToFreeze.GetSize()

	    while iIndex02 > 0
	        iIndex02 -= 1
	        Actor FreezeREF = ActorsToFreeze.GetAt(iIndex02) as Actor
	        FreezeREF.EnableAI(True)
	    EndWhile
	endif
	
	AudioCategoryFST.UnMute()
	PlayerREF.SetGhost(False)
	Sound.StopInstance(VisionSound)
	MAGConjurePortalClose.Play(PlayerREF)
	_00E_SilenceAbruptHighPriority.Remove()
	PlayerREF.RemovePerk(_00E_VisionPerk)
	
	If PlayerREF.GetAV("speedMult") < 50
		PlayerREF.SetAV("speedMult", 100)
	EndIf
	
	UpdateSpeed(PlayerREF)
	_00E_MQ16_VisionIMOD.Remove()
	_00E_VisionImod.Remove()

EndFunction

Function UpdateSpeed(Actor SpeedUpdateActor)

	If SpeedUpdateActor.HasSpell(_00E_Vision_UpdateAb)
		SpeedUpdateActor.RemoveSpell(_00E_Vision_UpdateAb)
	EndIf
	
	SpeedUpdateActor.AddSpell(_00E_Vision_UpdateAb, False)
	Wait(0.1)
	SpeedUpdateActor.RemoveSpell(_00E_Vision_UpdateAb)

EndFunction

;=====================================================================================
;              							AREMOVE ITEMS SAFE                  					 
;=====================================================================================

Function RemoveAllItemsSafeVersion(ObjectReference TransferToLoc = NONE)
	If Gold001 == NONE || _00E_AllAmmos == NONE
		Return
	EndIf
	
	RemoveItemsIncrementally(Gold001, TransferToLoc)
	Form[] arrows = _00E_AllAmmos.ToArray()
	Int i = 0
	While i < arrows.Length
		RemoveItemsIncrementally(arrows[i], TransferToLoc)
		i += 1
	EndWhile
	
	If TransferToLoc == NONE
		PlayerREF.removeAllItems(_00E_RemoveAllItems_TrashContainer, abRemoveQuestItems = false)
		_00E_RemoveAllItems_TrashContainer.removeAllItems()
	Else
		PlayerREF.RemoveAllItems(akTransferTo = TransferToLoc, abRemoveQuestItems = true)
	EndIf
EndFunction

Function RemoveItemsIncrementally(Form akItem, ObjectReference TransferToLoc)
	Int nCount = PlayerREF.GetItemCount(akItem)
	If nCount > 3000000 && akItem == Gold001
		_00E_PleaseRemoveMoney.Show()
	EndIf
	While nCount > 0
		PlayerREF.RemoveItem(akItem, 10000, true, TransferToLoc)
		nCount -= 10000
	EndWhile
EndFunction

;=====================================================================================
;              							ADDED IN FORGOTTEN STORIES                  
;=====================================================================================

Function SlowMotion(float fDuration = 5.0, bool bSound = true)

	PlayerREF.AddSpell(_00E_FS_NQR05_SlowMotionSP, False)
	
	if bSound 
		_00E_FS_NQR05_SlowMotion_IntroM.Play(PlayerREF)
	endif
	
	Wait(fDuration)
	
	if bSound
		_00E_FS_NQR05_SlowMotion_OutroM.Play(PlayerREF)
	endif
	
	PlayerREF.RemoveSpell(_00E_FS_NQR05_SlowMotionSP)
	
EndFunction

Function UnsummonApparitionIfExists() Global

	_FS_Phasmalist_ControlQuest.UnsummonApparitionIfExists()

EndFunction

Function EndWerewolfModeWhenTransformed() Global

	; This function ends the werewolf mode if the player is currently transformed, with no penalties. 
	_FS_TheriantrophistControlQuest.TransformBackIfTransformed()
	; Links to Theriantrophist script.

EndFunction

Function SetNPCAsCompanion(Actor akActor, bool bCompanion = True, int iCompanionHealth = 100, int iCompanionStamina = 100, int iCompanionMagicka = 100) Global
;Sets an NPC as companion, showing his health bar, making him friendly, unflagging him as ghost. Does the opposite when bCompanion is set to false.
;Additionally sets the AVs Health, Stamina, Magicka for the NPC companion
	
	_00E_FS_ForgottenStories_Functions ForgottenStoriesMiscDialogue = Game.GetFormFromFile(0x01016E89, "Enderal - Forgotten Stories.esm") as _00E_FS_ForgottenStories_Functions
	
	If bCompanion
	
		akActor.SetRelationshipRank(Game.GetPlayer(), 3)
		akActor.SetGhost(False)
		akActor.getActorbase().SetEssential(true) ; just in case, had trouble with FS_NQR05
		akActor.SetPlayerTeammate(True)
		akActor.IgnoreFriendlyHits()
		akActor.SetAV("Health", iCompanionHealth)
		akActor.SetAV("Stamina", iCompanionStamina)
		akActor.SetAV("Magicka", iCompanionMagicka)
		ForgottenStoriesMiscDialogue.showActorHealthBars(akActor)

	Else
	
		akActor.SetGhost(True)
		akActor.getActorbase().SetEssential(true) ; just in case, had trouble with FS_NQR05
		akActor.ResetHealthAndLimbs()
		akActor.SetPlayerTeammate(False)
		akActor.IgnoreFriendlyHits(False)
		ForgottenStoriesMiscDialogue.hideActorHealthBars(akActor)

	EndIf

EndFunction

Function StartVoicedLetter(MusicType MTVoicedLetter)
	
	MTToRemove = MTVoicedLetter
	RegisterForMenu("Book Menu")
	MTVoicedLetter.Add()
	
EndFunction

Event OnMenuClose(String MenuName)

	If MenuName == "Book Menu"
		MTToRemove.Remove()
		UnregisterForMenu("Book Menu")
	EndIf

EndEvent


; SKILL BOOKS

Message Property _00E_SkillbookWarning Auto

Bool _SkillBookReadLocked = False

Function _ReadSkillBook(String skillName, Int skillTopLimit, Form bookItem, Message msgSkillIncrease, GlobalVariable availablePoints, Message msgNoPoints)
	Message failMsg = None

	While _SkillBookReadLocked
		WaitMenuMode(0.1)
	EndWhile
	_SkillBookReadLocked = True

	; DO NOT FORGET TO FALSE _SkillBookReadLocked ON RETURN

	If availablePoints.GetValue() >= 1
		Int curSkill = PlayerREF.GetBaseActorValue(skillName) as Int

		If curSkill >= skillTopLimit
			failMsg = _00E_Levelsystem_sSkillTooWellDeveloped
		ElseIf curSkill >= (skillTopLimit - 25) || (_00E_SkillbookWarning.Show() == 0) ; If cur. skill is within the book's limit or the player says "Yes"
			; Do skill increase
			curSkill += 1
			PlayerREF.SetActorValue(skillName, curSkill)
			availablePoints.Mod(-1)
			_SkillBookReadLocked = False
			msgSkillIncrease.Show(1, curSkill)
			Return
		EndIf
	Else ; availablePoints < 1
		failMsg = msgNoPoints
	EndIf

	; Processing failed read 
	_SkillBookReadLocked = False

	If failMsg != None
		failMsg.Show()
	EndIf

	PlayerREF.AddItem(bookItem, 1, True)
EndFunction

Function ReadPrimarySkillBook(String skillName, Int skillTopLimit, Form bookItem, Message msgSkillIncrease)
	_ReadSkillBook(skillName, skillTopLimit, bookItem, msgSkillIncrease, Lernpunkte, _00E_Levelsystem_sNoMoreLearningPoints)
EndFunction

Function ReadCraftingSkillBook(String skillName, Int skillTopLimit, Form bookItem, Message msgSkillIncrease)
	_ReadSkillBook(skillName, skillTopLimit, bookItem, msgSkillIncrease, Handwerkspunkte, _00E_Levelsystem_sNoMoreCraftingPoints)
EndFunction

Function ReadMemorySkillBook(String sClass, Int iTier, Message talentMessage, float fRecoveryTime02, float fRecoveryTime03, Potion PotionItem, Shout TaughtTalent, WordOfPower Word01, WordOfPower Word02, WordOfPower Word03, Perk Perk01, Perk Perk02, Perk Perk03)
	While _MemoryBookReadLocked
		WaitMenuMode(0.1)
	EndWhile
	_MemoryBookReadLocked = True
	
	int iButton = talentMessage.Show()

	if iButton == 0
		
		if iTier == 1
			iRequiredPoints = iPointRequirementTier01
		Elseif iTier == 2
			iRequiredPoints = iPointRequirementTier02
		Else
			iRequiredPoints = iPointRequirementTier03
		EndIf
		
		if RequirementsMetMemoryBook(iTier, Perk01, Perk02, Perk03, sClass)
			TeachTalent(iTier, TaughtTalent, Perk01, Perk02, Perk03, Word01, Word02, Word03, fRecoveryTime02, fRecoveryTime03)
		Else
		
			if bValidSkilllevel
		
				Message messageToShow = _00E_FS_A3_sMageClassName
			
				if sClass == "Rogue"
					messageToShow = _00E_FS_A3_sRogueClassName
				Elseif sClass == "Warrior"
					messageToShow = _00E_FS_A3_sWarriorClassName
				EndIf
				Debug.Notification(_00E_FS_A3_sYouNeedSkillpoints.GetName() + " " + iRequiredPoints + _00E_FS_A3_sIn.GetName() + messageToShow.GetName() + _00E_FS_A3_sToUnlockThisClass.GetName())
			
			EndIf
				
			PlayerREF.AddItem(PotionItem, 1, true)

		EndIf
		_MemoryBookReadLocked = False
		
	Else
	
		PlayerREF.AddItem(PotionItem, 1, true)
		_MemoryBookReadLocked = False
		Return
		
	EndIf
EndFunction

bool Function RequirementsMetMemoryBook(int iTier, Perk Perk01, Perk Perk02, Perk Perk03, string sClass)
	
	Formlist ClassFormList01
	Formlist ClassFormList02
	Formlist ClassFormList03
	
	if (iTier == 3 && !PlayerREF.HasPerk(Perk02)) || (iTier == 2 && !PlayerREF.HasPerk(Perk01))
	
		_00E_FS_A3_NeedToLearnOtherLevels.Show()
		bValidSkilllevel = False
		Return False
		
	Elseif (iTier == 1 && PlayerREF.HasPerk(Perk01)) || (iTier == 2 && PlayerREF.HasPerk(Perk02)) || (iTier == 3 && PlayerREF.HasPerk(Perk03))
	
		_00E_FS_A3_AlreadyKnowThisLevel.Show()
		bValidSkilllevel = False
		Return False
		
	Else
	
		bValidSkilllevel = True

		if sClass == "Rogue"
			ClassFormList01 = EspionagePerks
			ClassFormList02 = TrickeryPerks
			ClassFormList03 = VagabondPerks

		Elseif sClass == "Warrior"
			ClassFormList01 = BastionPerks
			ClassFormList02 = DerwishPerks
			ClassFormList03 = RagePerks

		Elseif sClass == "Mage"
			ClassFormList01 = ElementalismPerks
			ClassFormList02 = LifeAndDeathPerks
			ClassFormList03 = ManipulationPerks
		EndIf
		
		int iTotalPointsInRequiredClass = (PlayerSkillMenu.GetPointsInClass(ClassFormList01) + PlayerSkillMenu.GetPointsInClass(ClassFormList02) + PlayerSkillMenu.GetPointsInClass(ClassFormList03))
		if iTotalPointsInRequiredClass >= iRequiredPoints
			Return True
		Else
			Return False
		EndIf
		
	EndIf

EndFunction

Function TeachTalent(int iLevel, Shout TaughtTalent, Perk Perk01, Perk Perk02, Perk Perk03, WordOfPower Word01, WordOfPower Word02, WordOfPower Word03, float fRecoveryTime02, float fRecoveryTime03)

	if iLevel == 1
	
		PlayerREF.AddPerk(Perk01)
		PlayerREF.AddShout(TaughtTalent)
		Game.UnlockWord(Word01)
		Game.TeachWord(Word01)
		
	Elseif iLevel == 2
	
		PlayerREF.AddPerk(Perk02)
		Game.UnlockWord(Word02)
		Game.TeachWord(Word02)
		SetRecoveryTimeMemoryBook(2, TaughtTalent, fRecoveryTime02, fRecoveryTime03)
	
	Else
		
		PlayerREF.AddPerk(Perk03)
		Game.UnlockWord(Word03)
		Game.TeachWord(Word03)
		SetRecoveryTimeMemoryBook(3, TaughtTalent, fRecoveryTime02, fRecoveryTime03)
	
	EndIf
	
	TalentPoints.Mod(-1)
	
	If _00E_AchievementsEnabled.GetValueInt() == 1
		Game.UnlockAchievement("END_TALENT_BOOK_01")
	EndIf
	
EndFunction

Function SetRecoveryTimeMemoryBook(int iWord, Shout TaughtTalent, float fRecoveryTime02, float fRecoveryTime03)
{This function handles the issue of cooldowns not depending on the value in the CK but on the duration the player presses the [Shout] key on his keyboard.}

	If iWord == 2
		TaughtTalent.SetNthRecoveryTime(0, fRecoveryTime02)
		TaughtTalent.SetNthRecoveryTime(1, fRecoveryTime02)
	Else
		TaughtTalent.SetNthRecoveryTime(0, fRecoveryTime03)
		TaughtTalent.SetNthRecoveryTime(1, fRecoveryTime03)
		TaughtTalent.SetNthRecoveryTime(2, fRecoveryTime03)
	EndIf

EndFunction


; EQUIPPING SETS

Function OnArmorSetBonusAdded(Bool bFullSet)
	Sound.SetInstanceVolume(MAGIllusionCharm.Play(PlayerREF), 0.4) ; Play MAGIllusionCharm at lower volume

	If bFullSet && bSetAchievementUnlocked == False && _00E_AchievementsEnabled.GetValueInt() == 1
		Game.UnlockAchievement("END_SET_01")
		bSetAchievementUnlocked = True
	EndIf
EndFunction

Function OnArmorSetBonusRemoved()
	_00E_ArmorSetScript_sSetBonusRemoved.Show()
EndFunction



Float fDefaultHeadTrackTimerOldValue = 0.0
Float fStayHeadTrackTimerOldValue = 0.0

Function StopRandomHeadTracking()
    ; Raise "change headtrack target" timers a lot so the NPCs would stare at what the scene tells them, without randomly switching to the player or other NPCs
	If fDefaultHeadTrackTimerOldValue == 0.0
	    fDefaultHeadTrackTimerOldValue = Game.GetGameSettingFloat("fAIHoldDefaultHeadTrackTimer")
	    Game.SetGameSettingFloat("fAIHoldDefaultHeadTrackTimer", 1000.0)
	EndIf
	If fStayHeadTrackTimerOldValue == 0.0
	    fStayHeadTrackTimerOldValue = Game.GetGameSettingFloat("fAIStayonScriptHeadtrack")
	    Game.SetGameSettingFloat("fAIStayonScriptHeadtrack", 1000.0)
	EndIf
EndFunction

Function ResumeRandomHeadTracking()
    If fDefaultHeadTrackTimerOldValue > 0.0
        Game.SetGameSettingFloat("fAIHoldDefaultHeadTrackTimer", fDefaultHeadTrackTimerOldValue)
        fDefaultHeadTrackTimerOldValue = 0.0
    EndIf
    If fStayHeadTrackTimerOldValue > 0.0
        Game.SetGameSettingFloat("fAIStayonScriptHeadtrack", fStayHeadTrackTimerOldValue)
        fStayHeadTrackTimerOldValue = 0.0
    EndIf
EndFunction
 

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

int Property iMajorClassIndex Auto Conditional Hidden
int Property iMinorClassIndex Auto Conditional Hidden

bool Property bAllowIdleChatter = True Auto Conditional Hidden 	; Set this to true when NPCs shouldn't Idle around

float Property fPlayerSpeedBeforeVision Auto Hidden
float Property fCameraMaxDistance Auto Hidden
float Property fBaseGravity Auto Hidden

;Actor akPlayerCopy

Sound Property _00E_FS_NQR05_SlowMotion_IntroM Auto
Sound Property _00E_FS_NQR05_SlowMotion_OutroM Auto

ActorBase Property _00E_MC_Jespar Auto
ActorBase Property _00E_MC_Calia Auto
ActorBase Property _00E_SC_Tharael Auto
ActorBase Property _00E_SC_Dijaam Auto
ActorBase Property _00E_MQ11c_Ryneus Auto
ActorBase Property _00E_CapitalCityMaelGroschenfrst Auto
ActorBase Property _00E_MC_Yuslan Auto
ActorBase Property _00E_FS_NQ02_Esme Auto

GlobalVariable Property SympathyTharael Auto
GlobalVariable Property SympathyJespar Auto
GlobalVariable Property SympathyDijaam Auto
GlobalVariable Property SympathyMaelGroschenfuerst Auto
GlobalVariable Property SympathyCalia Auto
GlobalVariable Property SympathyYuslan Auto
GlobalVariable Property SympathyEsme Auto

GlobalVariable Property CaliaFlirtCounter Auto
GlobalVariable Property DijaamFlirtCounter Auto
GlobalVariable Property JesparFlirtCounter Auto
GlobalVariable Property TharaelFlirtCounter Auto

GlobalVariable Property _00E_AchievementsEnabled Auto

ReferenceAlias Property Levelsystem_SympathyActor Auto

Formlist Property _00E_AllAmmos Auto

MiscObject Property Gold001 Auto

Message Property _00E_PleaseRemoveMoney Auto

GlobalVariable Property GameHour Auto

;--------------------------------------VISION-----------------------------------

float PlayerSpeed
int VisionSound

Perk Property _00E_VisionPerk Auto

SoundCategory Property AudioCategoryFST Auto

VisualEffect Property MS04MemoryFXBody01VFX Auto
ImageSpaceModifier Property _00E_VisionStartImod Auto
ImageSpaceModifier Property _00E_VisionIMOD Auto
ImageSpaceModifier Property _00E_VisionEndImod Auto
Sound Property _00E_VisionLPM Auto
Sound Property MagRacialBattlecryFire Auto 
Sound Property MAGConjurePortalClose Auto 

Spell Property _00E_Vision_UpdateAb Auto

MusicType Property _00E_SilenceTransitionLowPriority02 Auto
MusicType Property _00E_Music_Special_MQ12b_Samael Auto
MusicType Property _00E_SilenceLongTransitionHighPriority Auto
MusicType Property _00E_SilenceTransitionLowPriority Auto
MusicType Property _00E_SilenceTransitionHighPriority Auto
MusicType Property _00E_SilenceAbruptHighPriority Auto
MusicType Property _00E_Music_Special_TavernSilence Auto

Formlist Property _00E_MUS_AllCombatSoundtracks Auto

;--------------------------------------LEVELSYSTEM-----------------------------------

GlobalVariable Property Handwerkspunkte auto
GlobalVariable Property SympathyRyneus auto
GlobalVariable Property Lernpunkte auto
GlobalVariable Property TalentPoints auto
GlobalVariable Property _00E_DisableQuestTutorials Auto
GlobalVariable Property _00E_DisableSkillTutorials Auto
Keyword Property BrawlKeyword Auto

Message Property _00E_FS_A3_sYouNeedSkillpoints Auto
Message Property _00E_FS_A3_sIn Auto
Message Property _00E_FS_A3_sToUnlockThisClass Auto
Message Property _00E_FS_A3_sWarriorClassName Auto
Message Property _00E_FS_A3_sRogueClassName Auto
Message Property _00E_FS_A3_sMageClassName Auto
Message Property _00E_FS_A3_NeedToLearnOtherLevels Auto
Message Property _00E_FS_A3_AlreadyKnowThisLevel Auto

int iPointRequirementTier01 = 5
int iPointRequirementTier02 = 10
int iPointRequirementTier03 = 15

int iRequiredPoints

bool bValidSkilllevel

Formlist Property EspionagePerks Auto
Formlist Property TrickeryPerks Auto
Formlist Property VagabondPerks Auto
Formlist Property BastionPerks Auto
Formlist Property DerwishPerks Auto
Formlist Property RagePerks Auto
Formlist Property ElementalismPerks Auto
Formlist Property LifeAndDeathPerks Auto
Formlist Property ManipulationPerks Auto

_00E_Game_SkillmenuSC Property PlayerSkillMenu Auto

Bool _MemoryBookReadLocked = False

;-------------------------------------TELEPORT SCRIPT-----------------------------------

VisualEffect Property MGTeleportInEffect Auto
Actor Property PlayerREF Auto
ActorBase Property Player Auto
EffectShader Property TimeFadeOut01FXS Auto
EffectShader Property TimeFadeIn01FXS Auto
Explosion Property _00E_TeleportExplosion Auto
Explosion Property _00E_NPCOorbayaTeleportExplosionBlue Auto

Idle Property WebIdleExit Auto
Idle Property IdleT02AscendMale Auto
Idle Property IdleT02AscendFemale Auto
Idle Property IdleForceDefaultState Auto

Static Property XMarkerHeading Auto

Sound Property _00E_MagicProtectionSpellM Auto
Sound Property _00E_A2_Ghostwalk_TeleportDoneSound Auto
Sound Property _00E_TeleportCastSound Auto

Message Property _00E_Tutorial_Brawl Auto
Message Property _00E_Tutorial_Companions02_Jespar Auto
Message Property _00E_Tutorial_Companions02_Calia Auto

Message Property _00E_Levelsystem_sApproves Auto
Message Property _00E_Levelsystem_sAppreciates Auto
Message Property _00E_Levelsystem_sAppreciatesALot Auto
Message Property _00E_Levelsystem_sDislikes Auto
Message Property _00E_Levelsystem_sHurt Auto
Message Property _00E_Levelsystem_sVeryHurt Auto
Message Property _00E_Levelsystem_sDoesNotTrust Auto
Message Property _00E_Levelsystem_sExtremelyHurt Auto
Message Property _00E_Levelsystem_sIsHurt Auto

Message Property _00E_Levelsystem_sSynergyDiscovered Auto
Message Property _00E_Levelsystem_sNoMoreCraftingPoints Auto
Message Property _00E_Levelsystem_sNoMoreLearningPoints Auto
Message Property _00E_Levelsystem_sSkillTooWellDeveloped Auto
Message Property _00E_Levelsystem_sSkillBy Auto
Message Property _00E_Levelsystem_sSkillTo Auto
Message Property _00E_Levelsystem_sSkillFrom Auto
Message Property _00E_Levelsystem_sSkillIncreased Auto
Message Property _00E_Levelsystem_sAbilityEnemyLevelTooHigh Auto
Message Property _00E_Levelsystem_sAbilityEnemyHasToBeAlive Auto
Message Property _00E_Levelsystem_sEnemyHasToBeDead Auto
Message Property _00E_Levelsystem_sAbilityEnemyTooFarAway Auto
Message Property _00E_Levelsystem_sAbilityTargetImmune Auto
Message Property _00E_Levelsystem_sAbilityMarkingRemoved Auto
Message Property _00E_Levelsystem_sEnemyMarked Auto
Message Property _00E_Levelsystem_sAbilityStanceStarted Auto
Message Property _00E_Levelsystem_sAbilityStanceEnded Auto
Message Property _00E_Levelsystem_sAbilityStanceQyrai Auto
Message Property _00E_Levelsystem_sAbilityStanceSkaragg Auto
Message Property _00E_Levelsystem_sEnemyAlreadyMarked Auto
Message Property _00E_Levelsystem_sEldritchBloodVictimMarked Auto
Message Property _00E_Levelsystem_sEldritchBloodAttackTargetMarked Auto
Message Property _00E_Levelsystem_sEldritchBloodAttackVictimMarkingRemoved Auto
Message Property _00E_Levelsystem_sEldritchBloodVictimMarkingRemoved Auto
Message Property _00E_Levelsystem_sGhostwalkEnemyTooCloseToWall Auto

ObjectReference Property PlayerVisionStartMarker Auto Hidden
ObjectReference Property PlayerVisionFailsaveMarker Auto Hidden
ObjectReference Property VisionLight Auto Hidden

ObjectReference Property _00E_RemoveAllItems_TrashContainer Auto

Idle Property IdleMagic_01 Auto

Spell Property _00E_Vision_NoTimeSpell Auto
Spell Property _00E_Vision_NoTimeSubtleSpell Auto
Spell Property _00E_Vision_TimeSpell Auto
Spell Property _00E_PriestCureDiseases Auto
Spell Property _00E_FS_NQR05_SlowMotionSP Auto

GlobalVariable Property _00E_HeadtrackGlobal Auto

ImageSpaceModifier Property FadeToBlackIMOD Auto
ImageSpaceModifier Property FadeToBlackHoldIMOD Auto
ImageSpaceModifier Property FadeToBlackBackIMOD Auto
ImageSpaceModifier Property _00E_NPCTeleportExplosionIMOD Auto
ImageSpaceModifier Property _00E_TeleportImod Auto
ImageSpaceModifier Property _00E_VisionStartTimestopIMOD Auto
ImageSpaceModifier Property _00E_MQ16_VisionIMOD Auto

ShaderParticleGeometry Property _00E_VisionShaderParticles Auto

SoundCategory Property AudioCategoryAMB Auto
SoundCategory Property AudioCategoryAMBr Auto
SoundCategory Property AudioCategorySFX Auto

Static Property XMarker Auto

int doOnce
int done
float SpeedBefore

bool bUnlockedSynergyAchievement

;for re-equipping the player after the bathouse scene
Armor PlayerHelmet
Armor PlayerCuirass
Armor PlayerGauntlets
Armor PlayerBoots
Armor PlayerRing01
Armor PlayerRing02
Armor PlayerNecklace
Weapon RightHandWeapon
Weapon LeftHandWeapon
Spell RightHandSpell
Spell LeftHandSpell
Armor Shield

;for VoiceLetters
MusicType MTToRemove

;for sets
Sound Property MAGIllusionCharm Auto
Message Property _00E_ArmorSetScript_sSetBonusRemoved Auto
bool bSetAchievementUnlocked = false