I do my Call Help from the OnUserDefined handle and put the code in the end combat round section.
In order for the NPC to run that code they need this somewhere in their OnSpawn handle:
SetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT) so the system knows that it should look in the UserDef script for code to run.
From there you can add whatever you want.
Instead of running every 6 seconds while the NPC exists, it only runs while the NPC is in combat and you might be able to assume that if they are in combat there is a PC fighting them (and save yourself the need to check for one).
All that aside, I think this is the code snippet might be what you want and may work in either place.
object oSpawn;
object oSelf = OBJECT_SELF;
int iPC = 0;
int iNPC = 0;
effect eVFX;
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 27.0, GetLocation(oSelf), TRUE);
//this first loop will count the number of PCs we can see, and the number of friendly NPCs
while( GetIsObjectValid(oTarget) )
{
if( GetIsPC(oTarget) && GetObjectSeen(oTarget,oSelf) )
{
iPC++;
}
else if( GetObjectType(oTarget) == OBJECT_TYPE_CREATURE && GetIsFriend(oTarget,oSelf) )
{
iNPC++;
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, 27.0, GetLocation(oSelf), TRUE);
}
//now that we have counted them up, lets spawn things until iNPC = iPC
do
{
eVFX = EffectVisualEffect(VFX_FNF_GAS_EXPLOSION_EVIL);
oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ephemeralnegativ", GetLocation(oSelf));
DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oSpawn));
}
while( iPC > iNPC );