You are here

What's the Best Way...

4 posts / 0 new
Last post
Tarot Redhand
Tarot Redhand's picture
What's the Best Way...

I have a class of creature that, given the right circumstances, I need to kill all instances of, in an area but only that area. I figure that it is probably best to do this by having all these creatures to have the same tag. I was wondering though what is the best way of going about this (example scripts more than welcome).

Thanks in advance for any help with this.

TR

  • up
    50%
  • down
    50%
Proleric
Proleric's picture

To remove everything (creature or placeable) with a given tag, I do this:

==========

// Remove specified objects
 
// We make the objects invisible because they won't be destroyed until end of script.
 
void bh_destroy(string sNPC)
{
  object oNPC       = GetObjectByTag(sNPC, 0);
  int    n          = 0;
 
  while (GetIsObjectValid(oNPC))
    {
      SetPlotFlag(oNPC, FALSE);
      ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectVisualEffect(VFX_DUR_CUTSCENE_INVISIBILITY), oNPC);
      DestroyObject(oNPC, 1.0);
      oNPC = GetObjectByTag(sNPC, ++n);
    }
}
==========
 
However, when I need the death script to fire, or leave corpses, I do this:
 
==========
// Kill creature to force OnDeath event (which EffectDeath does not)
 
void bhKill(object oNPC, int nDamageType = DAMAGE_TYPE_BLUDGEONING)
{
  SetPlotFlag(oNPC, FALSE);
  AssignCommand(GetModule(), ApplyEffectToObject(DURATION_TYPE_INSTANT,
                             SupernaturalEffect(EffectDamage(2 * GetCurrentHitPoints(oNPC), nDamageType)), oNPC));
}
 
==========
 
The latter script only kills one, as it stands, but you get the general idea.
 
If I had creatures with the same tag in multiple areas, I'd use GetFirst / NextObjectInArea, checking the tag. You can use GetNearestObjectByTag, of course, but then you need to be careful about the timing - you don't want to delete any before you've processed them all, otherwise the indexing gets borked.
 
Best method? Dunno, but it works for me.

NWN and DAO adventures at http://proleric.com/

  • up
    50%
  • down
    50%
Vanya Mia
Vanya Mia's picture

I'd use something simular to Proleric (in both cases, depending on whether you need to keep the bodies or not) via an area or placeable heartbeat script. One that checks for a flag and stops if it's not set, so you don't get lag, but if the flag is set checks for creatures with that tag and removes or kills them. Firing deletion directly from a death script should work but you'd have to be careful to disable its activation when the others die or it would call multiple times and could bork the script, and while I think scripts continue to run when fired even if the calling object is removed the first creature to die may have to hang around until the routine is done just in case it causes a search fail. The search loop being on the area, or a placeable for that matter, hopefully prevents the problems Proleric describes.

"I took Skill Focus: Craft Disturbing Mental Image as my feat last level." Belkar, OOTS

  • up
    50%
  • down
    50%
Tarot Redhand
Tarot Redhand's picture

Thanks guys. Sorry for shortness of reply but RL intervenes.

TR

  • up
    50%
  • down
    50%