Author Topic: Kill all in a faction function help  (Read 443 times)

Legacy_prokat

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Kill all in a faction function help
« on: August 31, 2010, 06:29:32 am »


               Hi all-
I'm trying to write a function that will kill all of an object's faction.  Here's what I have:

void KillTheFaction(object oMember)
{
    object oTarget = GetFactionLeastDamagedMember(oMember, FALSE);
    while(GetIsObjectValid(oTarget))
    {
          ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(GetCurrentHitPoints(oTarget)), oTarget);
         oTarget = GetFactionLeastDamagedMember(oMember, FALSE);
    }
}

It receives oMember who belongs to a faction.  Then cycles through all members of that faction and kills them by reducing the HP to zero until it runs out of objects that belong to that faction.

It either doesn't totally work, does work (rarely), or crashes nwn.  I'm not sure what's wrong but hopefully you can help.  If there's an easier way to do this, please suggest it.  Thank you!
               
               

               


                     Modifié par prokat, 31 août 2010 - 05:44 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Kill all in a faction function help
« Reply #1 on: August 31, 2010, 08:45:13 am »


               void KillTheFaction(object oMember)  //
{
 object oTarget;
 effect eDeath = EffectDeath();  //This Simply Works (Apply Damage can crash the game)
 
oTarget = GetFirstFactionMember(oMember, TRUE);
 while(GetIsObjectValid(oTarget))
 {
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eDeath, oTarget); 
    oTarget = GetNextFactionMember(oMember, TRUE);
 }

}
               
               

               


                     Modifié par Genisys, 31 août 2010 - 07:46 .
                     
                  


            

Legacy_prokat

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Kill all in a faction function help
« Reply #2 on: August 31, 2010, 09:26:08 am »


               Thank you! Bashing my head against the wall on that one.  GetFirstFactionMember() and EffectDeath() are great!  The TRUE flag on the faction function made me think it wasn't working (as I am killing NPCs) but I never defined what I was killing.  



Thanks again Genisys. You cleared my coding block!