Scriptname SuH_dyna_effectScript extends activemagiceffect  

SexLabFramework property SexLab auto

GlobalVariable Property SuH_SETcombatseduction auto
GlobalVariable Property SuH_SETalwaysgive auto
GlobalVariable Property SuH_SETcsNPChmax auto
GlobalVariable Property SuH_SETcsNPChmin auto
GlobalVariable Property SuH_SETcsPCShmax auto
GlobalVariable Property SuH_SETcsPCShmin auto
GlobalVariable Property SuH_SETcsPCSNhmax auto
GlobalVariable Property SuH_SETcsPCSNhmin auto
GlobalVariable Property SuH_SETcsMaleHomo auto
GlobalVariable Property SuH_SETcsFemaleHomo auto
GlobalVariable Property SuH_SETcsMaleAttack auto
GlobalVariable Property SuH_SETcsFemaleAttack auto
GlobalVariable Property SuH_SETcsCreatureAttack auto
GlobalVariable Property SuH_SETcsCreatureWMale auto
GlobalVariable Property SuH_SETcsCreatureWFemale auto
GlobalVariable Property SuH_SETcsPlayerAttack auto
GlobalVariable Property SuH_SETcsPlayerSubmit auto
GlobalVariable Property SuH_PCSmilkstacks auto

MagicEffect Property SuH_CHAinacteffect auto
MagicEffect Property SuH_csGraceeffect auto
MagicEffect Property SuH_sp_milkdrinkereffect auto

Spell Property SuH_dyna_ability auto

Actor Property PlayerRef Auto
Actor char

int csActive
int x
int mStacks

Event OnEffectStart(Actor akTarget, Actor akCaster)
	csActive = 0
	char = akTarget
endEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	UnregisterForUpdate()
endEvent

Event OnUpdate()
	csActive = 0
endEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	Actor attChar = akAggressor as Actor
	
	if attChar == PlayerRef
		;ent/ Milk Drinker effect
		If playerRef.HasMagicEffect(SuH_sp_milkdrinkereffect)
			mStacks = SuH_PCSmilkstacks.GetValue() as int
			if mStacks < 5 && mStacks != 0
				x = mStacks*2
				SuH_PCSmilkstacks.SetValue(0)
				char.DamageActorValue("health",x)
			else
				mStacks -= 5
				SuH_PCSmilkstacks.SetValue(mStacks)
				char.DamageActorValue("health",10)
			endIf
		endIf
		;end/
	endIf
	
	if SuH_SETcombatseduction.GetValue() ;;; If Combat Seduction is on ,,,
		if csActive != 1
			csActive = 1
			RegisterForSingleUpdate(1.0)
			;;; Check - Attacking self or has grace period ,,,
			if char == attChar
				csActive = 0
				UnregisterForUpdate()
			else ;;; If Valid ,,,
				bool charV = SexLab.IsValidActor(char)
				bool attCharV = SexLab.IsValidActor(attChar)
				;;; Check SexLab Validity ,,,
				if charV == true && attCharV == true
					float chp = ((char.GetActorValue("Health"))/(char.GetBaseActorValue("Health")))
					;;; Check if Attacker is Player and Valid SET ,,,
					If attChar == PlayerRef && SuH_SETcsPlayerAttack.GetValue()
						;;; Check if character is low enough ,,,
						if chp > 0 && chp <= SuH_SETcsPCSNhmax.GetValue()
							int charG = SexLab.GetGender(char)
							int attCharG = SexLab.GetGender(attChar)
							if charG == 1 ;;; Female Char ,,,
								;;; Female Attacker ,,,
								if attCharG == 1 && SuH_SETcsFemaleAttack.GetValue() && SuH_SETcsFemaleHomo.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = char
									aniActors[1] = attChar
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Lesbian", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								;;; Male Attacker ,,,
								elseIf attCharG == 0 && SuH_SETcsMaleAttack.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = char
									aniActors[1] = attChar
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Aggressive", "Lesbian", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								;;; Creature Attacker ,,,
								elseIf attCharG >= 2 && SuH_SETcsCreatureAttack.GetValue() && SuH_SETcsCreatureWFemale.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = char
									aniActors[1] = attChar
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								else
									csActive = 0
									UnregisterForUpdate()
								endIf
							elseIf charG == 0 ;;; Male Char ,,,
								;;; Female Attacker ,,,
								if attCharG == 1 && SuH_SETcsFemaleAttack.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = attChar
									aniActors[1] = char
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Cowgirl", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								;;; Male Attacker ,,,
								elseIf attCharG == 0 && SuH_SETcsMaleAttack.GetValue() && SuH_SETcsMaleHomo.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = char
									aniActors[1] = attChar
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Aggressive", "Lesbian", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								;;; Creature Attacker ,,,
								elseIf attCharG >= 2 && SuH_SETcsCreatureAttack.GetValue() && SuH_SETcsCreatureWMale.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = char
									aniActors[1] = attChar
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								else
									csActive = 0
									UnregisterForUpdate()
								endIf
							elseIf charG >= 2 ;;; Creature Char ,,,
								;;; Female Attacker ,,,
								if attCharG == 1 && SuH_SETcsCreatureWFemale.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = attChar
									aniActors[1] = char
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								;;; Male Attacker ,,,
								elseIf attCharG == 0 && SuH_SETcsCreatureWMale.GetValue()
									Actor[] aniActors = new actor[2]
									aniActors[0] = attChar
									aniActors[1] = char
									sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
									SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
									csActive = 0
									UnregisterForUpdate()
								else
									csActive = 0
									UnregisterForUpdate()
								endIf
							else
								csActive = 0
								UnregisterForUpdate()
							endIf
						endIf
					elseIf chp > 0 && chp <= SuH_SETcsNPChmax.GetValue() && attChar != PlayerRef 
						int charG = SexLab.GetGender(char)
						int attCharG = SexLab.GetGender(attChar)
						if charG == 1 ;;; Female Char ,,,
							;;; Female Attacker ,,,
							if attCharG == 1 && SuH_SETcsFemaleAttack.GetValue() && SuH_SETcsFemaleHomo.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = char
								aniActors[1] = attChar
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Lesbian", "", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							;;; Male Attacker ,,,
							elseIf attCharG == 0 && SuH_SETcsMaleAttack.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = char
								aniActors[1] = attChar
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Aggressive", "Lesbian", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							;;; Creature Attacker ,,,
							elseIf attCharG >= 2 && SuH_SETcsCreatureAttack.GetValue() && SuH_SETcsCreatureWFemale.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = char
								aniActors[1] = attChar
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							else
								csActive = 0
								UnregisterForUpdate()
							endIf
						elseIf charG == 0 ;;; Male Char ,,,
							;;; Female Attacker ,,,
							if attCharG == 1 && SuH_SETcsFemaleAttack.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = attchar
								aniActors[1] = char
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Cowgirl", "", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							;;; Male Attacker ,,,
							elseIf attCharG == 0 && SuH_SETcsMaleAttack.GetValue() && SuH_SETcsMaleHomo.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = char
								aniActors[1] = attChar
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"Aggressive", "Lesbian", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							;;; Creature Attacker ,,,
							elseIf attCharG >= 2 && SuH_SETcsCreatureAttack.GetValue() && SuH_SETcsCreatureWMale.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = char
								aniActors[1] = attChar
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							else
								csActive = 0
								UnregisterForUpdate()
							endIf
						elseIf charG >= 2 ;;; Creature Char ,,,
							;;; Female Char ,,,
							if attCharG == 1 && SuH_SETcsCreatureWFemale.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = attChar
								aniActors[1] = char
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							;;; Male Char ,,,
							elseIf attCharG == 0 && SuH_SETcsCreatureWMale.GetValue()
								Actor[] aniActors = new actor[2]
								aniActors[0] = attChar
								aniActors[1] = char
								sslBaseAnimation[] animSET = SexLab.GetAnimationsByTags(2,"", "", requireAll=true)
								SexLab.StartSex(aniActors, animSET, victim=char, allowbed=false)
								csActive = 0
								UnregisterForUpdate()
							else
								csActive = 0
								UnregisterForUpdate()
							endIf
						else
							csActive = 0
							UnregisterForUpdate()
						endIf
					else
						csActive = 0
						UnregisterForUpdate()
					endIf
				else
					csActive = 0
					UnregisterForUpdate()
				endIf
			endIf
		endIf
	endIf
endEvent