Scriptname SuH_dynaES_active extends activemagiceffect  

SuH_Fun property _Fun auto
Faction Property SuH_Tracker auto
Actor Property PlayerRef auto

GlobalVariable Property SuH_SETcombatseduction auto
GlobalVariable Property SuH_SETnpc2npchealth auto
GlobalVariable Property SuH_SETnpc2pchealth auto


Ingredient Property SuH_ing_soulofforce auto
Ingredient Property SuH_ing_soulofexperience auto
Ingredient Property SuH_ing_souloflife auto
Ingredient Property SuH_ing_soulofmagic auto
Ingredient Property SuH_ing_soulofpower auto
Ingredient Property SuH_ing_soulofdesire auto

actor char

Event OnEffectStart(Actor akTarget, Actor akCaster)
	char = akTarget
	char.AddToFaction(SuH_Tracker)
EndEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	Actor attChar = akAggressor as Actor ; Set Attacker as usable actor reference
	if attChar != char
	if SuH_SETcombatseduction.GetValue()
		if attChar == PlayerRef
			float charHealthPercent = (char.GetActorValue("health") / char.GetBaseActorValue("health"))
			if charHealthPercent <= SuH_SETnpc2pchealth.GetValue()
				actor[] animActor = new actor[2] ; Create Array of actors
				animActor[0] = attChar ; Set attChar
				animActor[1] = char ; Set char
				_Fun.ANIMcalc("0", animActor, char) ; Send aggressive act to SuH_Fun
			endIf
		else
			float charHealthPercent = (char.GetActorValue("health") / char.GetBaseActorValue("health"))
			if charHealthPercent <= SuH_SETnpc2npchealth.GetValue()
				actor[] animActor = new actor[2] ; Create Array of actors
				animActor[0] = attChar ; Set attChar
				animActor[1] = char ; Set char
				_Fun.ANIMcalc("0", animActor, char) ; Send aggressive act to SuH_Fun
			endIf
		endIf
	endIf
	endIF
endEvent

Event Ondying(Actor akKiller)
	int ran = Utility.RandomInt(0,58)
	if ran < 14
		char.AddItem(SuH_ing_soulofforce, 1, false)
	elseIf ran < 28
		char.AddItem(SuH_ing_soulofexperience, 1, false)
	elseIf ran < 41
		char.AddItem(SuH_ing_soulofdesire, 1, false)
	elseIf ran < 44
		char.AddItem(SuH_ing_souloflife, 1, false)
	elseIf ran < 47
		char.AddItem(SuH_ing_soulofmagic, 1, false)
	elseIf ran < 50
		char.AddItem(SuH_ing_soulofpower, 1, false)
	endIf
endEvent