Scriptname zBloodNPCbleed extends activemagiceffect  

Keyword property WeapTypeBattleaxe auto
Keyword property WeapTypeBow auto
Keyword property WeapTypeDagger auto
Keyword property WeapTypeGreatsword auto
Keyword property WeapTypeMace auto
Keyword property WeapTypeSword auto
Keyword property WeapTypeWarAxe auto
Keyword property WeapTypeWarHammer auto
Keyword property ActorTypeAnimal auto
Keyword property ActorTypeGiant auto

Race property AlduinRace auto
Race property DragonRace auto
Race property WerewolfBeastRace auto

Race AggressorRace

ImpactDataSet Property BloodFXDrop01 auto
ImpactDataSet Property BloodFXDrop02 auto
ImpactDataSet Property BloodFXDrop03 auto

Spell Property BugfixSpell auto
MagicEffect Property BugfixSpellME auto

Actor target
Actor caster
int iBleeding
int picktexture
string asNodeName
float health

float locationX
float locationY

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
	target = akTarget
	caster = akCaster
EndEvent

EVENT OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
if target != None
   AggressorRace = (akAggressor as Actor).GetRace()	
		
    if ((akSource.HasKeyword(WeapTypeBattleaxe) || akSource.HasKeyword(WeapTypeBow) || akSource.HasKeyword(WeapTypeDagger) || akSource.HasKeyword(WeapTypeGreatsword) || akSource.HasKeyword(WeapTypeMace) || akSource.HasKeyword(WeapTypeSword) || akSource.HasKeyword(WeapTypeWarAxe) || akSource.HasKeyword(WeapTypeWarHammer)) || AggressorRace == DragonRace || AggressorRace == AlduinRace || AggressorRace == WerewolfBeastRace || akAggressor.HasKeyword(ActorTypeAnimal) || akAggressor.HasKeyword(ActorTypeGiant))
		
	if target.HasNode("NPC Spine2 [Spn2]")			;; humanoids
		asNodeName = "NPC Spine2 [Spn2]"
	elseif target.HasNode("NPC Spine2")					;; Falmer
		asNodeName = "NPC Spine2"
	elseif target.HasNode("NPC Ribcage")					;; Bear
		asNodeName = "NPC Ribcage"
	elseif target.HasNode("Canine_Ribcage")				;; Dog, wolf
		asNodeName = "Canine_Ribcage"
	elseif target.HasNode("Sabrecat_Ribcage[Spn4]")	;; Sabrecat
		asNodeName = "Sabrecat_Ribcage[Spn4]"
	elseif target.HasNode("[body]")						;; Spider
		asNodeName = "[body]"
	else													;; Just in case, default
		asNodeName = "NPC Spine2 [Spn2]"
	endif

	health = target.GetAVPercentage("Health")	

	if !target.HasMagicEffect(BugfixSpellME) && health <= 0.5 && !target.isDead() ;same as bugfix for npc and player hit. this will not apply blood drops again for 1 min
		BugfixSpell.Cast(target, target)

			utility.wait(3)
			bloodDrops()

	endif
endif
endif
EndEvent

	FUNCTION bloodDrops() ;Blood Drops
	while (!target.isDead() && iBleeding <= 80) && (health <= 0.6) && target != None

		picktexture = Utility.RandomInt(0, 2)
		locationX = Utility.RandomFloat(-0.3, 0.3)
		locationY = Utility.RandomFloat(-0.3, 0.3)
			if  picktexture == 0 && target != None
				target.PlayImpactEffect(BloodFXDrop01, asNodeName, locationX, locationY, -1, 512, false, true)
					
			elseif picktexture == 1 && target != None
				target.PlayImpactEffect(BloodFXDrop02, asNodeName, locationX, locationY, -1, 512, false, true)
				
			elseif picktexture == 2 && target != None
				target.PlayImpactEffect(BloodFXDrop03, asNodeName, locationX, locationY, -1, 512, false, true)
					
			endif
			
			iBleeding += 1

			if iBleeding <= 40
				utility.wait(0.3)
			elseif iBleeding <= 80
				utility.wait(0.5)
			endif	
	endWhile
	endFUNCTION
