Scriptname SuH_Main extends Quest  

;ent/ Scripts
SexLabFramework property SexLab auto
SuH_Fun property _Fun auto
cell property SuH_realm auto
;end/
;ent/ Globals
GlobalVariable property SuH_MODversion auto
GlobalVariable property SuH_SETallowdrainkill auto
GlobalVariable property SuH_SETessentialacts auto
GlobalVariable property SuH_SETclearactor auto
GlobalVariable property SuH_PCSstackmaxsex auto
GlobalVariable property SuH_PCSstackmaxsperm auto
GlobalVariable property SuH_PCSstackmaxmilk auto
GlobalVariable property SuH_PCSstacksex auto
GlobalVariable property SuH_PCSstacksperm auto
GlobalVariable property SuH_PCSstackmilk auto
GlobalVariable property SuH_PCSxp auto
GlobalVariable property SuH_PCSxpearn auto
GlobalVariable property SuH_PCScaphealth auto
GlobalVariable property SuH_PCScapmagicka auto
GlobalVariable property SuH_PCScapstamina auto
GlobalVariable property SuH_PCSabsorbhealth auto
GlobalVariable property SuH_PCSabsorbmagicka auto
GlobalVariable property SuH_PCSabsorbstamina auto
GlobalVariable property SuH_PCSspermhealth auto
GlobalVariable property SuH_PCSspermmagicka auto
GlobalVariable property SuH_PCSspermstamina auto
GlobalVariable property SuH_PCSmilkhealth auto
GlobalVariable property SuH_PCSmilkmagicka auto
GlobalVariable property SuH_PCSmilkstamina auto
GlobalVariable property SuH_PCSxpgain auto
GlobalVariable property SuH_PCSbpoint auto
GlobalVariable property SuH_PCSdpoint auto
GlobalVariable property SuH_PCSspoint auto
GlobalVariable property SuH_PCSmpoint auto
GlobalVariable Property SuH_PCSbdsm auto
GlobalVariable Property SuH_PCSbdsmspecial auto
GlobalVariable property SuH_rank_perfectorgasm auto
GlobalVariable property SuH_rank_perfectorgasm2 auto
GlobalVariable property SuH_rank_selfstacker auto
GlobalVariable property SuH_rank_valuestacker auto
GlobalVariable property SuH_rank_masochist auto
GlobalVariable property SuH_rank_giftedconsent auto
GlobalVariable property SuH_rank_lusciousliquids auto
GlobalVariable property SuH_rank_forcemaster auto
GlobalVariable property SuH_rank_savingessence auto
GlobalVariable property SuH_rank_deviouspartner2 auto
GlobalVariable property SuH_SETalwaysdrainkill auto
GlobalVariable property SuH_SETconsentdrain auto
GlobalVariable property SuH_SETspecialdeath auto
GlobalVariable property SuH_SETactmessage auto
GlobalVariable property SuH_CHKsdinact auto
GlobalVariable property SuH_PETsummonlevel auto
GlobalVariable property SuH_PETsummonxp auto
GlobalVariable property SuH_PETdogunlock auto
GlobalVariable property SuH_PETwolfunlock auto
GlobalVariable property SuH_PEThorseunlock auto
GlobalVariable property SuH_PETskeeverunlock auto
GlobalVariable property SuH_PETfamiliarunlock auto
GlobalVariable property SuH_PETbearunlock auto
GlobalVariable property SuH_PETsabrecatunlock auto
GlobalVariable property SuH_PETdraugrunlock auto
GlobalVariable property SuH_PETtrollunlock auto
GlobalVariable property SuH_PETsprigganunlock auto
GlobalVariable property SuH_PEThorkerunlock auto
GlobalVariable property SuH_PETfalmerunlock auto
GlobalVariable property SuH_PETdoglevel auto
GlobalVariable property SuH_PETwolflevel auto
GlobalVariable property SuH_PEThorselevel auto
GlobalVariable property SuH_PETskeeverlevel auto
GlobalVariable property SuH_PETbearlevel auto
GlobalVariable property SuH_PETsabrecatlevel auto
GlobalVariable property SuH_PETdraugrlevel auto
GlobalVariable property SuH_PEThorkerlevel auto
GlobalVariable property SuH_PETsprigganlevel auto
GlobalVariable property SuH_PETfalmerlevel auto
GlobalVariable property SuH_PETfamiliarlevel auto
GlobalVariable property SuH_PETtrolllevel auto
GlobalVariable property SuH_PEThuskyunlock auto
GlobalVariable property SuH_PEThuskylevel auto
GlobalVariable property SuH_PETbristlelevel auto
GlobalVariable property SuH_PETseekerlevel auto
GlobalVariable property SuH_PETgargoylelevel auto
GlobalVariable property SuH_PETnetchlevel auto
GlobalVariable property SuH_PETrieklinglevel auto
GlobalVariable Property SuH_SETcombatseduction auto
GlobalVariable Property SuH_perk_absorb auto
GlobalVariable Property SuH_perk_absorbl auto
GlobalVariable Property SuH_PCSxpgainitem auto
GlobalVariable Property SuH_perk_sperml auto
GlobalVariable Property SuH_perk_milkl auto
GlobalVariable Property SuH_PCScaphealthitem auto
GlobalVariable Property SuH_PETspiderunlock auto
GlobalVariable Property SuH_SETcalmaura auto
GlobalVariable Property SuH_SETdisablehealthrecovery auto
GlobalVariable Property SuH_SETdisablemagickarecovery auto
GlobalVariable Property SuH_SETdisablestaminarecovery auto
;end/
;ent/ Factions
Faction property SuH_Tracker auto
Faction property SuH_ignoreabsorb auto
Faction property SuH_petfaction auto
;end/
;ent/ Spells
Spell property SuH_sex_PCmastery auto
Spell property SuH_sex_PCtraining auto
Spell property SuH_sex_PCsubmit auto
Spell property SuH_sex_NPCattacker auto
Spell property SuH_sex_NPCconsent auto
Spell property SuH_sex_NPCvictim auto
Spell property SuH_stat_essential auto
Spell property SuH_dyna_player auto
Spell property SuH_sex_inact auto
Spell property SuH_spell_selfpleasure auto
Spell property SuH_spell_nightsembrace auto
Spell property SuH_spell_teliRealm auto
Spell Property SuH_spell_sexualenrage auto
Spell Property SuH_spell_sexualentice auto
Spell Property SuH_sex_petpattacker auto
Spell Property SuH_sex_petnattacker auto
Spell Property SuH_sex_petpconsent auto
Spell Property SuH_sex_petnconsent auto
Spell Property SuH_sex_petpvictim auto
Spell Property SuH_sex_petnvictim auto
Spell Property SuH_sex_petorgasm auto
Spell Property SuH_sex_petspell auto
Spell Property SuH_CHAinvact auto
Spell Property SuH_sex_CScd auto
Spell Property SuH_com_absorbvisuals auto
Spell Property SuH_spell_petself auto
Spell Property SuH_spell_pettarget auto
Spell Property SuH_dyna_calmaura auto
;end/
;ent/ Items
Ingredient Property SuH_ing_milk auto
Ingredient Property SuH_ing_sperm auto
Ingredient Property SuH_ing_vitalitystone auto
Ingredient Property SuH_ing_empowermentstone auto
Ingredient Property SuH_ing_specialtystone auto
Ingredient Property SuH_ing_soulofdesire auto
Ingredient Property SuH_ing_soulofexperience auto
Ingredient Property SuH_ing_soulofforce auto
Ingredient Property SuH_ing_souloflife auto
Ingredient Property SuH_ing_soulofmagic auto
Ingredient Property SuH_ing_soulofpower auto
;end/
;ent/ other var
Actor Property PlayerRef auto
actor property SuH_actor_dog auto
actor property SuH_actor_wolf auto
actor property SuH_actor_horse auto
actor property SuH_actor_skeever auto
actor property SuH_actor_familiar auto
actor property SuH_actor_bear auto
actor property SuH_actor_sabrecat auto
actor property SuH_actor_draugr auto
actor property SuH_actor_troll auto
actor property SuH_actor_spriggan auto
actor property SuH_actor_horker auto
actor property SuH_actor_falmer auto
ObjectReference Property SuH_sd_lostchest Auto 
ObjectReference Property SuH_sd_goldchest Auto 
MiscObject property Gold001 auto
;end/

;ent/ MODupdate
Function MODupdate()
	float MODversion = SuH_MODversion.GetValue()
	;Always Run
	; NOTE : Succubus Heart MUST reset the player Dynamic Effect spell on each load because Skyrim doesn't store spell values properly between saves
	PlayerRef.RemoveSpell(SuH_dyna_player)
	PlayerRef.AddSpell(SuH_dyna_player, false)
	; NOTE : Re-remove Status Regen that's disabled, Skyrim resets them to default when loading a save
	if SuH_SETdisablehealthrecovery.GetValue() > 0.0
		playerRef.SetActorValue("HealRate", 0)
	endIf
	if SuH_SETdisablemagickarecovery.GetValue() > 0.0
		playerRef.SetActorValue("MagickaRate", 0)
	endIf
	if SuH_SETdisableStaminarecovery.GetValue() > 0.0
		playerRef.SetActorValue("StaminaRate", 0)
	endIf
	;ent/ Previous Patches
	if MODversion < 0.1
		SexLab.TrackFaction(SuH_tracker,"NPCtracker")
		RegisterForModEvent("NPCtracker_Added","anim_NPC_Added")
		RegisterForModEvent("NPCtracker_Start","anim_NPC_Start")
		RegisterForModEvent("NPCtracker_Orgasm","anim_NPC_Orgasm")
		RegisterForModEvent("NPCtracker_End","anim_NPC_End")
		RegisterForModEvent("PlayerTrack_Added","anim_PC_Added")
		RegisterForModEvent("PlayerTrack_Start","anim_PC_Start")
		RegisterForModEvent("PlayerTrack_Orgasm","anim_PC_Orgasm")
		RegisterForModEvent("PlayerTrack_End","anim_PC_End")
	endIf
	if MODversion < 0.6
		playerRef.AddSpell(SuH_spell_nightsembrace)
		PlayerRef.AddSpell(SuH_spell_selfpleasure)
	endIf
	if MODversion < 0.7
		SuH_PCSxpearn.SetValue(25)
	endIf
	if MODversion < 3.342
		playerRef.AddSpell(SuH_spell_teliRealm)
	endIf
	if MODversion < 3.431
		if MODversion != 0.0
			int xpgainnew = Math.Floor(SuH_PCSxpgain.GetValue() * 100)
			SuH_PCSxpgain.SetValue(xpgainnew)
		endIf
		int b = Math.Floor((SuH_PCScaphealth.GetValue() - 100)+((SuH_PCSabsorbhealth.GetValue() - 1)*5)+((SuH_PCSspermhealth.GetValue() - 1)*2)+((SuH_PCSmilkhealth.GetValue() - 1)*2)) 
		int d = Math.Floor((SuH_PCSstackmaxsex.GetValue()+SuH_PCSstackmaxsperm.GetValue()+SuH_PCSstackmaxmilk.GetValue()+(SuH_PCSxpgain.GetValue() - 100) - 3)*5)
		int s = Math.Floor((SuH_PCScapstamina.GetValue() - 100)+((SuH_PCSabsorbstamina.GetValue() - 1)*5)+((SuH_PCSspermstamina.GetValue() - 1)*2)+((SuH_PCSmilkstamina.GetValue() - 1)*2))
		int m = Math.Floor((SuH_PCScapmagicka.GetValue() - 100)+((SuH_PCSabsorbmagicka.GetValue() - 1)*5)+((SuH_PCSspermmagicka.GetValue() - 1)*2)+((SuH_PCSmilkmagicka.GetValue() - 1)*2))
		int maso = SuH_rank_masochist.GetValue() as int
		int perf = SuH_rank_perfectorgasm.GetValue() as int
		int gift = SuH_rank_giftedconsent.GetValue() as int
		int lusi = SuH_rank_lusciousliquids.GetValue() as int
		int forc = SuH_rank_forcemaster.GetValue() as int
		int savi = SuH_rank_savingessence.GetValue() as int
		int valu = SuH_rank_valuestacker.GetValue() as int
		int sels = SuH_rank_selfstacker.GetValue() as int
		SuH_PCSbpoint.SetValue(b)
		SuH_PCSdpoint.SetValue(d)
		SuH_PCSspoint.SetValue(s)
		SuH_PCSmpoint.SetValue(m)
		int bdsmrating = b+d+s+m
		SuH_PCSbdsm.SetValue(bdsmrating)
		string Lbdsmrating = " "
		if d >= b && d >= s && d >= m
			Lbdsmrating = "Desire"
			SuH_PCSbdsmspecial.SetValue(2)
		elseif b >= s && b >= m
			Lbdsmrating = "Body"
			SuH_PCSbdsmspecial.SetValue(1)
		elseif s >= m
			Lbdsmrating = "Soul"
			SuH_PCSbdsmspecial.SetValue(3)
		else
			Lbdsmrating = "Mind"
			SuH_PCSbdsmspecial.SetValue(4)
		endIf
		int xp = SuH_PCSxp.GetValue() as int
		int xpboost = (maso+perf+gift+lusi+forc+savi+valu+sels)*2000
		SuH_PCSxp.SetValue(xp+xpboost)
		SuH_rank_masochist.SetValue(0)
		SuH_rank_perfectorgasm.SetValue(0)
		SuH_rank_giftedconsent.SetValue(0)
		SuH_rank_lusciousliquids.SetValue(0)
		SuH_rank_forcemaster.SetValue(0)
		SuH_rank_savingessence.SetValue(0)
		SuH_rank_valuestacker.SetValue(0)
		SuH_rank_selfstacker.SetValue(0)
	endIf
	if MODversion < 3.44
		SuH_sd_lostchest.RemoveItem(Gold001, 999999)
	endIf
	if MODversion < 3.45
		playerRef.AddSpell(SuH_spell_sexualenrage)
		playerRef.AddSpell(SuH_spell_sexualentice)
	endIf
	if MODversion < 4.12
		SuH_realm.Reset()
		SuH_actor_bear.GetActorBase().SetEssential(false)
		SuH_actor_dog.GetActorBase().SetEssential(false)
		SuH_actor_draugr.GetActorBase().SetEssential(false)
		SuH_actor_falmer.GetActorBase().SetEssential(false)
		SuH_actor_familiar.GetActorBase().SetEssential(false)
		SuH_actor_horker.GetActorBase().SetEssential(false)
		SuH_actor_horse.GetActorBase().SetEssential(false)
		SuH_actor_sabrecat.GetActorBase().SetEssential(false)
		SuH_actor_skeever.GetActorBase().SetEssential(false)
		SuH_actor_spriggan.GetActorBase().SetEssential(false)
		SuH_actor_troll.GetActorBase().SetEssential(false)
		SuH_actor_wolf.GetActorBase().SetEssential(false)
		SuH_actor_bear.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_dog.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_draugr.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_falmer.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_familiar.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_horker.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_horse.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_sabrecat.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_skeever.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_spriggan.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_troll.RemoveFromFaction(SuH_ignoreabsorb)
		SuH_actor_wolf.RemoveFromFaction(SuH_ignoreabsorb)
		
		actor char = SuH_actor_bear
		int x = SuH_PETbearlevel.GetValue() as int
		int h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		int m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		int s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_dog
		x = SuH_PETdoglevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_draugr
		x = SuH_PETdraugrlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_falmer
		x = SuH_PETfalmerlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_familiar
		x = SuH_PETfamiliarlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_horker
		x = SuH_PEThorkerlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_horse
		x = SuH_PEThorselevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_sabrecat
		x = SuH_PETsabrecatlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_skeever
		x = SuH_PETskeeverlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_spriggan
		x = SuH_PETsprigganlevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_troll
		x = SuH_PETtrolllevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
		char = SuH_actor_wolf
		x = SuH_PETwolflevel.GetValue() as int
		h = math.floor(char.GetBaseActorValue("Health") + (x * 50))
		m = math.floor(char.GetBaseActorValue("Magicka") + (x * 50))
		s = math.floor(char.GetBaseActorValue("Stamina") + (x * 50))
		char.SetActorValue("Health",h)
		char.SetActorValue("Magicka",m)
		char.SetActorValue("Stamina",s)
	endIf
	if MODversion < 4.14
		SuH_PETsummonlevel.SetValue(0)
		SuH_PETsummonxp.SetValue(0)
		SuH_PETdogunlock.SetValue(1)
		SuH_PETskeeverunlock.SetValue(0)
		SuH_PETwolfunlock.SetValue(0)
		SuH_PETdraugrunlock.SetValue(0)
		SuH_PEThorseunlock.SetValue(0)
		SuH_PEThorkerunlock.SetValue(0)
		SuH_PETsprigganunlock.SetValue(0)
		SuH_PETtrollunlock.SetValue(0)
		SuH_PETfamiliarunlock.SetValue(0)
		SuH_PETsabrecatunlock.SetValue(0)
		SuH_PETfalmerunlock.SetValue(0)
		SuH_PETtrollunlock.SetValue(0)
	endIf
	if MODversion < 4.151 && MODversion >= 4.14
		int dog = Math.Floor(SuH_PETdoglevel.GetValue() * 20)
		int skeever = Math.Floor(SuH_PETskeeverlevel.GetValue() * 24)
		int wolf = Math.Floor(SuH_PETwolflevel.GetValue() * 28)
		int draugr = Math.Floor(SuH_PETdraugrlevel.GetValue() * 28)
		int horse = Math.Floor(SuH_PEThorselevel.GetValue() * 32)
		int horker = Math.Floor(SuH_PEThorkerlevel.GetValue() * 32)
		int spriggan = Math.Floor(SuH_PETsprigganlevel.GetValue() * 32)
		int troll = Math.Floor(SuH_PETtrolllevel.GetValue() * 36)
		int familiar = Math.Floor(SuH_PETfamiliarlevel.GetValue() * 36)
		int sabrecat = Math.Floor(SuH_PETsabrecatlevel.GetValue() * 36)
		int bear = Math.Floor(SuH_PETbearlevel.GetValue() * 32)
		int falmer = Math.Floor(SuH_PETfalmerlevel.GetValue() * 36)
		int husky = Math.Floor(SuH_PEThuskylevel.GetValue() * 32)
		int seeker = Math.Floor(SuH_PETseekerlevel.GetValue() * 32)
		int gargoyle = Math.Floor(SuH_PETgargoylelevel.GetValue() * 32)
		int netch = Math.Floor(SuH_PETnetchlevel.GetValue() * 32)
		int riekling = Math.Floor(SuH_PETrieklinglevel.GetValue() * 32)
		int bristle = Math.Floor(SuH_PETbristlelevel.GetValue() * 32)
		
		int xptot = dog+skeever+wolf+draugr+horse+horker+spriggan+troll+familiar+sabrecat+bear+falmer+husky+seeker+gargoyle+netch+riekling+bristle
		int x = Math.Floor(xptot - SuH_PETsummonxp.GetValue())
		SuH_PETsummonxp.SetValue(x)
	endIf
	if MODversion < 4.171
		if MODversion > 4.160
			int x = SuH_perk_absorbl.GetValue() as int
			int xpv = Math.Floor(SuH_PCSxpgain.GetValue() - x)
			int xpiv = Math.Floor(SuH_PCSxpgainitem.GetValue() - x)
			SuH_perk_absorb.SetValue(0)
			SuH_perk_absorbl.SetValue(0)
			SuH_PCSxpgain.SetValue(xpv)
			SuH_PCSxpgainitem.SetValue(xpiv)
		endIf
	endIf
	if MODversion < 4.19
		PlayerRef.AddSpell(SuH_spell_petself)
		PlayerRef.AddSpell(SuH_spell_pettarget)
	endIf
	if MODversion < 4.20
		int absorb = SuH_perk_absorbl.GetValue() as int
		int x = Math.Floor(SuH_PCSxpgain.GetValue() - absorb)
		int y = Math.Floor(SuH_PCSxpgainitem.GetValue() - absorb)
		int z = absorb * 2
		SuH_PCSxpgain.SetValue(x)
		SuH_PCSxpgainitem.SetValue(y)
		x = Math.Floor(SuH_PCSbdsm.GetValue() + z)
		SuH_PCSbdsm.SetValue(x)
		
		int sperm = SuH_perk_sperml.GetValue() as int
		int milk = SuH_perk_milkl.GetValue() as int
		x = Math.Floor(SuH_PCScaphealth.GetValue() - ((sperm + milk) * 5))
		y = Math.Floor(SuH_PCScaphealthitem.GetValue() - ((sperm + milk) * 5))
		z = Math.Floor(SuH_PCSxp.GetValue() + ((sperm + milk) * 500))
		SuH_PCSxp.SetValue(z)
		SuH_PCScaphealth.SetValue(x)
		SuH_PCScaphealthitem.SetValue(y)
	endIf
	if MODversion < 4.3
		SuH_MODversion.SetValue(4.3)
		if SuH_PETsummonlevel.GetValue() > 1
			SuH_PETspiderunlock.SetValue(1)
		endIf
	endIf
	;end/
	;Current Patch
	if MODversion < 4.41
		if MODversion != 0.0
			debug.MessageBox("Succubus Heart : BDSM Rating / Passives have been reset in update 4.41 for fixes/changes, make sure to re-apply your set-up!")
			_Fun.PassiveReset(1)
		endIf
		SuH_MODversion.SetValue(4.41)
		debug.Notification("Succubus Heart : 4.41 Installed")
	endIf
endFunction
;end/

Event OnInit()
	MODupdate()
endEvent

;ent/ NPC Anim Start
Function anim_NPC_Start(form ActorRef, int threadId)
	actor char = ActorRef as actor ; Get Actor
	char.addSpell(SuH_sex_inact, false) ; Add InAct spell tag
	if SuH_SETclearactor.GetValue()
		char.ClearExtraArrows()
	endIf
	; if SuH_SETessentialacts.GetValue()
		; if char.GetActorBase().IsEssential()
			;do nothing
		; else
			; char.GetActorBase().setEssential() ; Make character essential
			; char.addSpell(SuH_stat_essential) ; Add Essential spell tag
		; endIF
	; endIf
	if char.IsInFaction(SuH_petfaction)
		sslThreadController Thread = SexLab.GetController(threadId)
		actor[] animActor = SexLab.HookActors(threadId)
		actor animVictim = SexLab.HookVictim(threadId)
		string petID = "none" ; Capture pet
		; If Segment Needs to be here (Check Pet to apply spell effects to other actors)
		int i = 0
		int pact = 0
		int nact = 0
		; Calculate pet spell effect (on Others) and tally actors
		While i < animActor.Length
			if animActor[i] != char
				if animActor[i] == PlayerRef
					pact = 1
				else
					nact += 1
				endIf
			endIf
			_Fun.spellPET(petID, animActor[i])
			i+= 1
		endWhile
		; Calculate pet spell effect (On Pet)
		if animVictim != none
			if char == animVictim
				if pact != 0
					char.AddSpell(SuH_sex_petpvictim)
				else
					char.AddSpell(SuH_sex_petnvictim)
				endIf
			else
				if pact != 0
					char.AddSpell(SuH_sex_petpattacker)
				else
					char.AddSpell(SuH_sex_petnattacker)
				endIf
			endIf
		else
			if pact != 0
				char.AddSpell(SuH_sex_petpconsent)
			else
				char.AddSpell(SuH_sex_petnconsent)
			endIf
		endIf
	endIf
endFunction
;end/

;ent/ NPC Anim Orgasm
Function anim_NPC_Orgasm(form ActorRef, int threadId)
	sslThreadController Thread = SexLab.GetController(threadId) ; Get Thread
	actor char = ActorRef as actor ; Get Actor (We'll exclude char from results)
	actor[] animActor = SexLab.HookActors(threadId) ; Create Actor Array
	int pact = 0
	; Hand out sex drops
	if animActor.Length > 1 ; If multiple actors are present
		; Check for player
		int i = 0 ; Set array position to 0
		While i < animActor.Length
			if animActor[i] != char
				if animActor[i] == PlayerRef
					pact = 1
				endIf
			endIf
			i += 1
		endWhile
		int charGender = SexLab.GetGender(char) ; Get char gender
		if charGender == 0 || charGender == 2 ; If char is male or male creature
			i = 0 ; Set array position to 0
			while i < animActor.Length
				if animActor[i] != char
					animActor[i].AddItem(SuH_ing_sperm, 2, true) ; Give actor 2 items
					animActor[i].EquipItem(SuH_ing_sperm, false, true) ; Use 1 item
				endIf
				i += 1
			endWhile
		elseIf charGender == 1 || charGender == 3 ; If char is female or female creature
			i = 0 ; Set array position to 0
			while i < animActor.Length
				if animActor[i] != char
					animActor[i].AddItem(SuH_ing_milk, 2, true)
					animActor[i].EquipItem(SuH_ing_milk, false, true)
				endIf
				i += 1
			endWhile
		endIf
	else ; If actor is alone
		int charGender = SexLab.GetGender(char) ; Get char gender
		if charGender == 0 || charGender == 2 ; If char is male or male creature
			char.AddItem(SuH_ing_sperm, 2, true)
			char.EquipItem(SuH_ing_sperm, false, true)
		elseIf charGender == 1 || charGender == 3 ; If char is female or female creature
			int i = 0 ; Set array position to 0
			char.AddItem(SuH_ing_milk, 2, true)
			char.EquipItem(SuH_ing_milk, false, true)
		endIf
	endIf
	; Pet orgasm calculation
	if char.IsInFaction(SuH_petfaction)
		SuH_sex_petorgasm.cast(char, char)
	endIf
	; Player Included Proc
	if pact == 1
		if char.GetRelationshipRank(PlayerRef) >= 3
			_Fun.perkcalc("allyorgasm")
		endIf
	endIf
endFunction
;end/

;ent/ NPC Anim End
Function anim_NPC_End(form ActorRef, int threadId)
	actor char = ActorRef as actor ; Get Actor
	; Remove sex effects
	char.RemoveSpell(SuH_sex_PCmastery)
	char.RemoveSpell(SuH_sex_PCtraining)
	char.RemoveSpell(SuH_sex_PCsubmit)
	char.RemoveSpell(SuH_sex_NPCattacker)
	char.RemoveSpell(SuH_sex_NPCconsent)
	char.RemoveSpell(SuH_sex_NPCvictim)
	char.RemoveSpell(SuH_sex_petspell)
	char.RemoveSpell(SuH_sex_inact)
	if char.hasSpell(SuH_stat_essential) ; if char has essential spell tag
		char.GetActorBase().setEssential(FALSE) ; Remove essential
		char.removeSpell(SuH_stat_essential) ; Remove essential spell tag
	endIf
	if SuH_SETallowdrainkill.GetValue()
		float x = char.GetActorValue("Health")
		if x < 1.0
			char.DamageActorValue("Health", 1.0)
			_Fun.perkcalc("killdrain")
		elseIf SuH_SETalwaysdrainkill.GetValue()
			char.DamageActorValue("Health", 9999999999)
			_Fun.perkcalc("killdrain")
		endIf
	endIf
	if char.IsInFaction(SuH_petfaction)
		char.removeSpell(SuH_sex_petpconsent)
		char.removeSpell(SuH_sex_petnconsent)
		char.removeSpell(SuH_sex_petpattacker)
		char.removeSpell(SuH_sex_petnattacker)
		char.removeSpell(SuH_sex_petpvictim)
		char.removeSpell(SuH_sex_petnvictim)
	endIf
	if SuH_SETcombatseduction.GetValue()
		char.AddSpell(SuH_sex_CScd, false)
	endIf
	if char.HasSpell(SuH_CHAinvact)
		char.RemoveSpell(SuH_CHAinvact)
		char.GetActorBase().setEssential(false)
	endIf
endFunction
;end/

;ent/ PC Anim Start
Function anim_PC_Start(form ActorRef, int threadId)
	sslThreadController Thread = SexLab.GetController(threadId) ; Get Thread
	actor[] animActor = SexLab.HookActors(threadId) ; Create Actor Array
	actor char = ActorRef as actor ; Get Actor (Looking for player)
	char.AddSpell(SuH_sex_inact, false) ; Add InAct spell tag
	char.AddSpell(SuH_sex_inact, false) ; Add InAct spell tag
	if SuH_SETclearactor.GetValue()
		char.ClearExtraArrows()
	endIf
	if char == PlayerRef && animActor.Length > 1 ; If actor is player then execute and distribute effect spells
		if SuH_SETcalmaura.GetValue()
			char.AddSpell(SuH_dyna_calmaura, false)
		endIf
		If PlayerRef.IsBleedingOut() == True
			SuH_CHKsdinact.SetValue(1)
			PlayerRef.SetNoBleedoutRecovery(false)
			PlayerRef.ForceActorValue("Health", 100.0)
		endIf
		; if SuH_SETactmessage.GetValue()
			; debug.MessageBox("Act Started")
		; endIf
		actor victim = SexLab.HookVictim(threadId) ; Get Victim
		int i = 0 ;Set array position to 0
		while i < animActor.Length ; Scan through all actors and apply effects
			if animActor[i] == PlayerRef ; If character is the PC
				if PlayerRef == victim ; If PC is victim
					PlayerRef.AddSpell(SuH_sex_PCsubmit, false) ; Add Submit Effect
				elseif victim != none ; If PC is aggressor
					PlayerRef.AddSpell(SuH_sex_PCmastery, false) ; Add Mastery Effect
				else ; If PC is consent
					PlayerRef.AddSpell(SuH_sex_PCtraining, false) ; Add Training Effect
				endIf
			else ; If character is an NPC
				if animActor[i] == victim ; If NPC is a victim
					if animActor[i].IsInFaction(SuH_ignoreabsorb)
					else
						animActor[i].AddSpell(SuH_sex_NPCvictim, false) ; Add Victim Effect
					endIf
					_Fun.seducedNPCSet(animActor[i], "aggressive", 0)
				elseif victim != none ; If NPC is aggressor
					if animActor[i].IsInFaction(SuH_ignoreabsorb)
					else
						animActor[i].AddSpell(SuH_sex_NPCattacker, false) ; Add Attacker Effect
					endIf
					_Fun.seducedNPCSet(animActor[i], "aggressive", 0)
				else ; If NPC is consent
					if animActor[i].IsInFaction(SuH_ignoreabsorb)
					else
						animActor[i].AddSpell(SuH_sex_NPCconsent, false) ; Add Consent Effect
					endIf
					_Fun.seducedNPCSet(animActor[i], "consent", 0)
				endIf
			endIf
			i+=1
		endWhile
	endIf
endFunction
;end/

;ent/ PC Anim Orgasm
Function anim_PC_Orgasm(form ActorRef, int threadId)
	actor char = ActorRef as actor ; Get Actor (We'll exclude char from results)
	sslThreadController Thread = SexLab.GetController(threadId) ; Get Thread
	actor[] animActor = SexLab.HookActors(threadId) ; Create Actor Array
	if char == PlayerRef
		_Fun.XPcalc("PCorgasm")
		_Fun.perkcalc("orgasm")
	endIf
	; Hand out sex drops
	if animActor.Length > 1 ; If multiple actors are present	
		; Apply player/character specific effects
		if char == PlayerRef
			_Fun.XPcalc("PCorgasm")
			; Devious Partner 2 Effect (Stamina to Gold)
			int x = SuH_rank_deviouspartner2.GetValue() as int
			if x > 0
				int y = x*5
				playerRef.AddItem(Gold001, y, true)
			endIf
			_Fun.perkcalc("orgasm")
		endIf
		int charGender = SexLab.GetGender(char) ; Get char gender
		if charGender == 0 || charGender == 2 ; If char is male or male creature
			int i = 0 ; Set array position to 0
			while i < animActor.Length
				if animActor[i] != char
					animActor[i].AddItem(SuH_ing_sperm, 2, true) ; Give actor 2 items
					animActor[i].EquipItem(SuH_ing_sperm, false, true) ; Use 1 item
				endIf
				i += 1
			endWhile
		elseIf charGender == 1 || charGender == 3 ; If char is female or female creature
			int i = 0 ; Set array position to 0
			while i < animActor.Length
				if animActor[i] != char
					animActor[i].AddItem(SuH_ing_milk, 2, true)
					animActor[i].EquipItem(SuH_ing_milk, false, true)
				endIf
				i += 1
			endWhile
		endIf
		; Calculate rare drop chance and handout
		if char == PlayerRef
			int i = 0
			while i < animActor.Length
				if animActor[i] != char
					int ran = Utility.RandomInt(0,99) + SuH_rank_perfectorgasm.GetValue() as int
					if ran >= 94
						int rare = Utility.RandomInt(0,2)
						if rare == 0
							char.AddItem(SuH_ing_vitalitystone, 1, true)
							if char == PlayerRef ; Notify player of rare drop
								debug.Notification("Succubus Heart - RARE DROP - Vitality Stone")
							endIf
						elseif rare == 1
							char.AddItem(SuH_ing_empowermentstone, 1, true)
							if char == PlayerRef
								debug.Notification("Succubus Heart - RARE DROP - Empowerment Stone")
							endIf
						elseif rare == 2
							char.AddItem(SuH_ing_specialtystone, 1, true)
							if char == PlayerRef
								debug.Notification("Succubus Heart - RARE DROP - Specialty Stone")
							endIf
						endIf
					endIf
				endIf
				i += 1
			endWhile
			; Apply Perfect Orgasm's Death Drop Bonus Passive
			int perforg2 = SuH_rank_perfectorgasm2.GetValue() as int
			if perforg2 > 0
				int m = perforg2*5
				int ranD = Utility.RandomInt(1,100)
				if ranD <= m
					int ran = Utility.RandomInt(0,49)
					if ran < 14
						playerRef.AddItem(SuH_ing_soulofforce, 1, false)
					elseIf ran < 28
						playerRef.AddItem(SuH_ing_soulofexperience, 1, false)
					elseIf ran < 41
						playerRef.AddItem(SuH_ing_soulofdesire, 1, false)
					elseIf ran < 44
						playerRef.AddItem(SuH_ing_souloflife, 1, false)
					elseIf ran < 47
						playerRef.AddItem(SuH_ing_soulofmagic, 1, false)
					elseIf ran < 50
						playerRef.AddItem(SuH_ing_soulofpower, 1, false)
					endIf
				endIf
			endIf
		endIf
	else ; If actor is alone
		int charGender = SexLab.GetGender(char) ; Get char gender
		if charGender == 0 || charGender == 2 ; If char is male or male creature
			char.AddItem(SuH_ing_sperm, 2, true)
			char.EquipItem(SuH_ing_sperm, false, true)
		elseIf charGender == 1 || charGender == 3 ; If char is female or female creature
			int i = 0 ; Set array position to 0
			char.AddItem(SuH_ing_milk, 2, true)
			char.EquipItem(SuH_ing_milk, false, true)
		endIf
	endIf
	
endFunction
;end/

;ent/ PC Anim End
Function anim_PC_End(form ActorRef, int threadId)
	actor char = ActorRef as actor ; Get Actor
	; Remove sex effects
	char.RemoveSpell(SuH_sex_PCmastery)
	char.RemoveSpell(SuH_sex_PCtraining)
	char.RemoveSpell(SuH_sex_PCsubmit)
	char.RemoveSpell(SuH_sex_NPCattacker)
	char.RemoveSpell(SuH_sex_NPCconsent)
	char.RemoveSpell(SuH_sex_NPCvictim)
	char.RemoveSpell(SuH_sex_petspell)
	char.RemoveSpell(SuH_sex_inact)
	char.RemoveSpell(SuH_dyna_calmaura)
	if char == PlayerRef
		; Give Sex Stack
		int sex = SuH_PCSstacksex.GetValue() as int
		int msex = SuH_PCSstackmaxsex.GetValue() as int
		if sex < msex
			int valuestacker = SuH_rank_valuestacker.GetValue() as int
			int tstack = sex + valuestacker + 1
			if tstack < msex
				SuH_PCSstacksex.SetValue(tstack)
			else
				SuH_PCSstacksex.SetValue(msex)
			endIf
		endIf
		;Self Stacker
		int selfstacker = SuH_rank_selfstacker.GetValue() as int
		if selfstacker != 0
			int pg = SexLab.GetGender(char)
			if pg == 1 ;female
				int y = SuH_PCSstackmaxmilk.GetValue() as int
				int z = SuH_PCSstackmilk.GetValue() as int
				int k = z + selfstacker
				if k < y
					SuH_PCSstackmilk.SetValue(k)
				else
					SuH_PCSstackmilk.SetValue(y)
				endIf
			else ;male
				int y = SuH_PCSstackmaxsperm.GetValue() as int
				int z = SuH_PCSstacksperm.GetValue() as int
				int k = z + selfstacker
				if k < y
					SuH_PCSstacksperm.SetValue(k)
				else
					SuH_PCSstacksperm.SetValue(y)
				endIf
			endIf
		endIf
		if SuH_CHKsdinact.GetValue()
			_Fun.SDrespawn()
		endIf
		if SuH_SETcombatseduction.GetValue()
			char.AddSpell(SuH_sex_CScd, false)
		endIf
		SuH_com_absorbvisuals.cast(playerRef, playerRef)
	; Kill if HP is lower than 1 and Kill Drain is enabled
	elseif SuH_SETallowdrainkill.GetValue()
		if char.HasSpell(SuH_CHAinvact)
			char.RemoveSpell(SuH_CHAinvact)
			char.GetActorBase().setEssential(false)
		endIf
		float x = char.GetBaseActorValue("Health")
		if x < 1.0
			char.DamageActorValue("Health", 1.0)
		elseIf SuH_SETalwaysdrainkill.GetValue()
			char.DamageActorValue("Health", 9999999999)
		endIf
		if SuH_SETcombatseduction.GetValue()
			char.AddSpell(SuH_sex_CScd, false)
		endIf
	endIf
endFunction
;end/