Author Topic: Help with a henchman respawn script?  (Read 761 times)

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Help with a henchman respawn script?
« Reply #15 on: July 08, 2012, 10:13:27 pm »


               

Lightfoot8 wrote...

Mr. Versipellis wrote...

http://pastebin.com/CpmY4F7R#


Your script still looks problematic to me.  The problems start with how you are defining oMaster and oMe at the begining of the script ( lines 6-9 ).  Both of them as written have a chance of returning the wrong object.  oMaster should be defined as a local that is set up at the time the henchman is added to the party.   oMe should be simply OBJECT_SELF


for oMaster you can use the wrapper function set up in X0_I0_HENCHMAN.

ie
object oMaster = GetLastMaster();
object oMe = OBJECT_SELF;

At that point if oMaster does not return the correct object, make sure that you have the SetLastMaster function in the script that adds the henchman to the party.


line 13:  SetLocalInt(GetMaster(OBJECT_SELF), GetResRef(OBJECT_SELF) + "erno_dead", 1);
Makes no since to me as being  set up on the master instead of the henchman.  We even have the problem here that if the henchman has already been removed from the party GetMaster is going to return an invalid object.  assuming that the other scripts are done correctly for the var being set on the PC, just use oMaster instead of GetMaster() ie:

 SetLocalInt(oMaster, GetResRef(OBJECT_SELF) + "erno_dead", 1);


lines: 17 through 30: 
This section does nothing close to the comments say it is doing.   None of the actions have a chance to fire, the Henchman being dead will not even que up actions.  even if the action que was active, The ActionDoCommands would get added to the que, however  the Action que is already locked when they fire and try to add the actions they contain to the action que.    ActionDoCommand is normally used to add commands to the Action que in this maner, NOT OTHER ACTIONS.

The SetDestroyable function in this section is way to late.  If the Henchman is not already set to be non destroyable, it will do no good to try and set it now. the henchman is already well on his way to being destroyed.   This is another function that you will want to make sure is set when the henchman is added to the party. 

To get this section to do what it looks like it is tring to do simply changing it to 

 
if (GetDidDie()) return;
else SetDidDie();

GetDidDie and SetDidDie are wrapper functions around the NW_L_HEN_I_DIED var in  X0_I0_HENCHMAN. 


Line 33: 
Change it to a d8 since you have added more options.

Line 48 & 49: should be  DURATION_TYPE_INSTANT

Line55:  should only be ran if a valid connection to oMaster has been made This means that lines 46 - 63 should be removed to there own functoin for better control.   this will also allow us to make checks to see if combat is still going on before raising the henchman. 


With the above adjustments you end up with something like this. 

#include "nw_i0_generic"
#include "nw_i0_plot"
#include "X0_I0_HENCHMAN"

void ResHenchman(object oPC,string sLiner = "", object oHenchman =OBJECT_SELF)
{
   if ( GetIsInCombat (oPC) || !GetIsObjectValid(oPC))
   {
     DelayCommand(30.0,ResHenchman(oPC,sLiner,oHenchman));
     return;
   }


  ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), oHenchman);
  ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oHenchman)), oHenchman);
  //DelayCommand(30.75, SetIsDestroyable(TRUE, TRUE, TRUE));
  DelayCommand(1.0, SpeakString(sLiner));
  SetDidDie(FALSE);

  if (GetArea(oPC) == GetArea(oHenchman))
  {
    DelayCommand(1.5, AddHenchman(oPC, oHenchman));

    //Re-set the variable to get rid of annoying dialogueif the henchie has successfully re-joined
    DeleteLocalInt(oPC, GetResRef(oHenchman) + "erno_dead");

    //Set up the proper conditions for henchman as defined by the X2 script
    SetAssociateState(NW_ASC_IS_BUSY, FALSE,oHenchman);
    //SetAssociateListenPatterns();
    SetLocalInt(oHenchman, "NW_COM_MODE_COMBAT", ASSOCIATE_COMMAND_ATTACKNEAREST);
    SetLocalInt(oHenchman, "NW_COM_MODE_MOVEMENT", ASSOCIATE_COMMAND_FOLLOWMASTER);
    SetAssociateState(NW_ASC_IS_BUSY, FALSE,oHenchman);
  }
}
void main()
{
  //Define the former master
  object oMaster=GetLastMaster();
  //Define the henchman
  object oMe =OBJECT_SELF;

  //Set the HCH erno_dead variable, just in case the script goes wrong.
  //This means that you see a special bit of dialogue when you speak to the hench post-death, but only if something goes wrong, i.e. the PC moves areas
  SetLocalInt(oMaster, GetResRef(OBJECT_SELF) + "erno_dead", 1);


  //Double-hit thing to stop the body from getting destroyed or anything
  if (GetDidDie()) return;
  else SetDidDie();

  //Choose a random dialogue string
  string sRevive;
  int iRandom = d8();
  switch(iRandom)
  {
    case 1: sRevive = "Better luck next time, eh?"; break;
    case 2: sRevive = "Thank all the Gods that we pulled through that..."; break;
    case 3: sRevive = "That was... unpleasant, to say the least."; break;
    case 4: sRevive = "Oh my... how long was I out for?"; break;
    case 5: sRevive = "Well, there's one for the journal."; break;
    case 6: sRevive = "Argh, I can barely feel my legs!"; break;
    case 7: sRevive = "That was strangely invigorating!"; break;
    case 8: sRevive = "For the love of all things holy, let's be more careful next time!"; break;
  }
 
//Resurrect and remove effects, then add back the henchman
  DelayCommand(0.1, RemoveEffects(OBJECT_SELF));
  DelayCommand( 30.0,ResHenchman(oMaster,sRevive) );
}
 

  
 
EDIT:  Forgot to reset his death flag.   Done.

Thanks much. I think this is all set up and working perfectly, I've run through a few dungeons and I haven't encountered any issues yet. You've been so helpful with this script - I'll be sure to credit you in the module documentation!
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Help with a henchman respawn script?
« Reply #16 on: August 10, 2012, 10:27:20 pm »


               Hey, I hate to resurrect an old thread but I've noticed that this script only ever seems to work once - that is to say, the first time the NPC dies, they are resurrected as dictated by the script, but after that, their corpse just lies there on the floor.
The current version is here, designed for an NPC tagged "Erno" and copied ad verbatim from the module:
http://pastebin.com/Cd4YjCbe
Any clue what might be causing this?
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Help with a henchman respawn script?
« Reply #17 on: August 16, 2012, 04:05:54 pm »


               Bump?