Scriptname BVTrackInSameCell Extends ActiveMagicEffect  
{ability that will be activated when player is not in the same cell as invisibleObject}

Actor property PlayerRef Auto
ObjectReference Property BVInvisibleObject Auto
Spell Property VampireTurnToAshPileNPC Auto
GlobalVariable Property VampireIdentifyingTurnedNPCs Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

	;Debug.Notification("Player Changed Cells")
	
	Int IdentifyingNPCs = 100
	Actor TurnedNPC = Game.FindRandomActorFromRef(Game.GetPlayer(), 5000.0)
	
	If VampireIdentifyingTurnedNPCs.GetValue() == 0
	
		VampireIdentifyingTurnedNPCs.SetValue(10000)	
	
		While IdentifyingNPCs > 0
		
			TurnedNPC = Game.FindRandomActorFromRef(Game.GetPlayer(), 5000.0)
			
			If TurnedNPC.GetAV("Variable05") == 666 && TurnedNPC.IsDead() == 0 && TurnedNPC != Game.GetPlayer() && TurnedNPC.IsInCombat() == 0
				TurnedNPC.SetAV("Variable05", 667)		
				;Debug.Notification("Feeding is being reset for "+TurnedNPC)
				TurnedNPC.RemoveSpell(VampireTurnToAshPileNPC)
				Utility.WaitMenuMode(0.5)
				TurnedNPC.SetAV("Variable05", 667)			
				TurnedNPC.AddSpell(VampireTurnToAshPileNPC, abVerbose = False)
			EndIf

			IdentifyingNPCs -= 1
			
		EndWhile
	
	EndIf
	
	;Debug.Notification("Done Identifying Turned NPCs")
	Utility.Wait(0.1) ;maybe not necessary
	BVInvisibleObject.MoveTo(PlayerRef)
	
EndEvent
