Need nCounter help

How do I reset the nCounter back to zero after spawned creature is destroyed so the next time my object is used it doesn’t just destroy the next one spawned immediately since the counter has reached max prescribed (40)?

I think I tried:
SetLocalInt(OBJECT_SELF, “life_countdown”, nCounter, 0); After the destroy command but then I think it just kept resetting every HB. Why? I don’t understand why, if I put this after that destroy command (which only happens as a result of counter max reached) does it seem to happen every HB? Or at least the destroy never happens with that line in.

This script is placed on HB of an invisible object in the same area as the spawned skeleton is in. It works, but once the counter reaches 40, any more skeletons summoned by user don’t last 240 seconds, but rather 6 (one HB). I’m trying to make them all last the same amount from summoned. This may not be the best way since I set max henchman to 10. I tried to put this on Skeleton HB but it never worked. It doesn’t appear that a monster can destroy itself (can’t self-terminate)?

//Determines lifespan of special temporary henchman Flaming Dead
//Placed on invisible placeable Flaming Dead Life Countdown

void main()
{

object oSelf = GetNearestObjectByTag("ZEP_SKELFLAMING02");
{
 if (OBJECT_INVALID == oSelf)
 return;

  int nCounter = GetLocalInt(OBJECT_SELF, "life_countdown");
  nCounter++;
  SetLocalInt(OBJECT_SELF, "life_countdown", nCounter);

  if (nCounter > 40)
  DestroyObject(oSelf);

}

}

The two things I did manage to get to work perfectly is not allow summon in any other area, in fact make a spell fail effect on PC and send message. Also, unsummon all when leaving the area. That will guarantee temporary hench-skeletons to this level. I just wanted to further time restrict since I’m giving the PC a small army.

Try this -

void main()
{
	int nCounter;
	object oSelf = GetNearestObjectByTag("ZEP_SKELFLAMING02");

	if (OBJECT_INVALID != oSelf)
	{
		nCounter = GetLocalInt(OBJECT_SELF, "life_countdown");
		nCounter++;

		if (nCounter > 40)
		{
			nCounter = 1;
			DestroyObject(oSelf);
		}
		SetLocalInt(OBJECT_SELF, "life_countdown", nCounter);
	}
}

You almost had it.

TR

Thanks. Seems to work perfectly.

Just one thing. If you set that local int “life_countdown” to zero instead of one, you will need to alter

if (nCounter > 40)

to

if (nCounter > 39)

if you want the delay to be 240 seconds.

TR