Scriptname _00E_NQ_Bounty01_TargetScript extends ReferenceAlias  


; SCRIPT AUTHOR DENNIS MAY 2014
; Script handles Bandit appearance and checks if bounty job is done
; SCRIPT CHANGE TILL MAY 2018
; Added-in Body Clean-up suggested by gavrant for performance reasons, check out WIDeadBodyCleanupScript for original code
; ====================================================================================
           							; EVENTS                  					 
; ====================================================================================	

Event OnCellAttach() ;FIRE WHEN PLAYER ENTERS THE CELL THE NEEDED ACTOR IS IN
	If NQ_Bounty01.GetStage() == __Config_iEnableAtStage && GetReference().IsDisabled()
		GetReference().Enable() ; Enable the bandit when he is needed in the quest
	Endif
EndEvent

Event OnDeath(Actor akKiller)
	finished = True
	
    Int iStage = __Config_iEnableAtStage

    NQ_Bounty01.SetObjectiveCompleted(iStage)		;MissionObjective: Kill the bandit - Done

    iStage += 5
    NQ_Bounty01.SetStage(iStage)					;MissionObjective: Take your bounty - New
    NQ_Bounty01.SetObjectiveDisplayed(iStage)		;Show Objective
    BountyScript._00E_NQ_Bounty01_Status = 2		;Unlock bounty board to receive your gold
EndEvent

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
	If finished == False && aeCombatState != 0 && akTarget
		If _00E_PlayerSummonedCreature == None
			_00E_PlayerSummonedCreature = Game.GetFormFromFile(0x000482FC, "Skyrim.esm") as Keyword
		EndIf

		If BlameSpellKeyword == None
			BlameSpellKeyword = Game.GetFormFromFile(0x0005BD16, "Skyrim.esm") as Keyword
		EndIf

		If akTarget == PlayerRef || akTarget.IsPlayerTeammate() || akTarget.HasKeyword(_00E_PlayerSummonedCreature) || akTarget.GetFactionReaction(PlayerRef) == 2 || akTarget.HasEffectKeyword(BlameSpellKeyword)
			finished = True
			GetActorRef().GetActorBase().SetEssential(False)
		EndIf
	EndIf
EndEvent

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


Actor Property PlayerRef Auto
Quest Property NQ_Bounty01 Auto
_00E_NQ_Bounty01_Functions Property BountyScript Auto			;ACCESS TO QUEST SCRIPT
Int Property __Config_iEnableAtStage Auto  
{Type the quest stage number to enable the bandit 10, 30, 50. Enable new enemy every 20th stage }
Keyword Property _00E_PlayerSummonedCreature Auto
Keyword Property BlameSpellKeyword Auto
Bool finished = False