Trigger spawning in multiple creatures - help!

The script below froze the game, while it spawned a multitude of the same creature around the player, when I’d only like just one to spawn. It’s an old script I pulled from somewhere, duct-tapped it together, and voila!

Player enters a trigger near flowers. A flower releases a gas spore that has a chance to paralyze the player. During that moment, vines from the same flower spawn (a hostile creature), and attacks the player. Except, well, take a look at the screen shot.

Clearly something bad is happening in the while loop, but I’m not clear as to where to put a stop to the loop so only one hostile vine from the flower is spawned in.

void ActionCreate(string sCreature, location lLoc)
{
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
}

void main()
{
object oEnt = GetEnteringObject();

object oMold = GetNearestObjectByTag("YellowMusk", oEnt);
object oMold2 = GetNearestObjectByTag("YellowMusk2", oEnt);
if(GetIsObjectValid(oMold2) && (!GetIsObjectValid(oMold) ||
    GetDistanceBetween(oEnt, oMold2) < GetDistanceBetween(oEnt, oMold)))
{
    oMold = oMold2;
}

if(!GetIsObjectValid(oMold) || GetDistanceBetween(oEnt, oMold) > 3.5)
{
    DestroyObject(OBJECT_SELF);
    return;
}

if(GetLocalInt(oMold, "DoOnce"))
{
    DestroyObject(OBJECT_SELF);
    return;
}

FloatingTextStringOnCreature("Flowers on the plant puff out a cloud of dust!", oEnt);

location lSelf = GetLocation(oMold);
effect eSpores = EffectVisualEffect(VFX_FNF_GAS_EXPLOSION_NATURE);
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eSpores, lSelf);

effect eSpore = EffectParalyze();
object oSpore = GetFirstObjectInShape(SHAPE_SPHERE, 4.0, lSelf, TRUE);

if ( ! FortitudeSave( oEnt, 17, SAVING_THROW_TYPE_MIND_SPELLS ) )
{

  while(GetIsObjectValid(oSpore))
  {

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSpore, oSpore, 18.0f);
    oSpore = GetNextObjectInShape(SHAPE_SPHERE, 4.0, lSelf, TRUE);
    object oCreature = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);

     if (GetHasSpellEffect(SPELL_INVISIBILITY, GetFirstPC())) return;

     string sCreature = "musk001";
     location lLoc = GetLocation(GetFirstPC());
     
     object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "musk001", lLoc);
     
     SetPlotFlag(GetNearestObjectByTag("MuskVines"), FALSE);
     DestroyObject(GetNearestObjectByTag("MuskVines"));
  }
}

SetLocalInt(oMold, "DoOnce", TRUE);
DestroyObject(oMold);
DestroyObject(OBJECT_SELF);

}

Thanks!

FP!

This reminds me of this thread.
Basically, the loop is executed while oSpore is a valid object. Within the loop, a new object is created. Although oSpore is set to the next object in the sphere, it seems it’s set to the current oSpore because the new creature puts every object one rank down in the list.
What happens if you add another

at the end (just after oSpawn is created)?

Additionally, if you want just one muskvine creature to appear, why do you use a loop?

One question why are you using GetFirstPC() a number of times in the while loop after you already got the information with

object oCreature = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);

In fact oCreature is not used anywhere in your script making that line redundant.

TR

@4760 has the gist of it. The script keeps adding objects to the shape, so the next object in shape is valid forever. A short delay on object creation should fix it.

Or add some conditions into the while loop to control it?