You could alway use a Global Variable Quest script.
I have made one for my mod as it saves typing the same lines of code again and again for each effect I make and passing functions etc to it is really helpfull.
On the script on your quest...
Scriptname scrQuestGlobalVar extends QuestActor Property ActTargetRef Auto ; Interchangeable Target from Detect spell.
I think you need to set the Property of the ActTargetRef in the "Quest - Scripts - Properties (of above script)" to None before testing.
Then on your script which is attached to said NPC...
Scriptname scrDetect extends activemagiceffect{Detection test.}scrQuestGlobalVar Property GlobalVars AutoActor Property PlayerRef AutoEVENT OnEffectStart(Actor akTarget, Actor akCaster)GlobalVars.ActTargetRef = akTargetENDEVENTThen on the script for what you are casting or which one needs said actors reference...
Scriptname scrTestTargetSpell extends ActiveMagicEffectLFscrQuestGlobalVar Property GlobalVars Auto ; Reference the Quest script with global variables, saves a lot of repeated code.EVENT (what ever event you need)IF GlobalVars.ActTargetRef != NONE TargetRef = GlobalVars.ActTargetRefENDIFENDEVENT
You could even put a while event around the IF statement to check constantly.
Hope that helps.