Jump to content

Home

Script that activates from multiple deaths


TheProphet

Recommended Posts

See this thread starting at DeathDisco's request for implementing an OnUserDefine script for the OnDeath event.

 

Assuming the NPCs have different tags, the OnDeath code would go something like this:

 

void main () {
if (
  GetIsDead(GetObjectByTag("NPC1_tag")) && 
  GetIsDead(GetObjectByTag("NPC2_tag")) &&
  GetIsDead(GetObjectByTag("NPC3_tag")) &&
  GetIsDead(GetObjectByTag("NPC4_tag")) 
) {
  AssignCommand(
    GetObjectByTag("Hutt_tag"),    
    ActionDoCommand( ActionStartConversation(GetFirstPC(),"The_2nd_dialog_name"))
  );
}
}

Link to comment
Share on other sites

  • 2 weeks later...

Maybe the enemies are disappearing (body fading) before the fight is over? In that case the GetObjectByTag function would be returning OBJECT_INVALID. To circumvent this, you could toss in the following line of code before the if statement:

SetIsDestroyable(FALSE);

Link to comment
Share on other sites

Strange. Maybe this would work:

void main () {
SetLocalBoolean(OBJECT_SELF,3,TRUE);
if (
  GetLocalBoolean(GetObjectByTag("NPC1_tag"),3) && 
  GetLocalBoolean(GetObjectByTag("NPC2_tag"),3) && 
  GetLocalBoolean(GetObjectByTag("NPC3_tag"),3) && 
  GetLocalBoolean(GetObjectByTag("NPC4_tag"),3) 
  ) {
  AssignCommand(
    GetObjectByTag("Hutt_tag"),    
    ActionDoCommand( ActionStartConversation(GetFirstPC(),"The_2nd_dialog_name"))
  );
}
}
Link to comment
Share on other sites

(I removed the erroneous &&)

 

I guess it's time to try the SendMessageToPC function to see whether or not the scripts are being fired.

 

Insert this before the SetLocalBoolean function.

SendMessageToPC(GetFirstPC(),"OnDeath Script Fired for "+GetTag(OBJECT_SELF));

 

Maybe we should take this to PM land.

Link to comment
Share on other sites

  • 2 months later...

Hey guys sorry to bring this dinosaur up but i am having a similar situation in the mod. I have it where there are 17 guys on a ship you have to kill, and when they are all dead, a script will fire that has dialog with ace playing. Can I jsut set it to one tag or do i have to do ALL of them unique and set it up here, because there are 17 of them. Is there a script that will chekc to see if there are enemies in the area?

Link to comment
Share on other sites

Originally posted by Gsccc

I have it where there are 17 guys on a ship you have to kill, and when they are all dead, a script will fire that has dialog with ace playing. Can I jsut set it to one tag or do i have to do ALL of them unique and set it up here, because there are 17 of them.

 

A custom OnDeath script like this one would probably work if set on the 17 enemies if they all have the same tag.

 

I would use the OnDeath event script directly rather than a UserDefined script for this since the OnDeath UserDefined was somewhat unreliable in Neverwinter Nights (didn't always fire) and I am unsure if they fixed that problem for KotOR.

 

// OnDeath Event Script

#include "k_inc_switch"

void main()
{
   string sTag = GetTag(OBJECT_SELF);
   int nCount = 0;
   int i = 0;

   object oTalker = GetObjectByTag("speaker_tag");
   object oGuard = GetObjectByTag(sTag, i);

   while (GetIsObjectValid(oGuard)) {
       if ((oGuard != OBJECT_SELF) && !GetIsDead(oGuard)) {
           nCount++;
           break;
       }

       oGuard = GetObjectByTag(sTag, ++i);
   }

   if ((nCount == 0) && !GetIsInConversation(oTalker)) {
       AssignCommand(oTalker, ClearAllActions());
       AssignCommand(oTalker, ActionStartConversation(GetFirstPC(), "alldead_dialog"));
   }

   ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_DEATH);   
}

 

Or, if you wish to check for any hostile creature in the area and not just a defined group, this would probably work as well:

 

// OnDeath Event Script

#include "k_inc_switch"

void main() {
   int nCount = 0;  
   object oTalker = GetObjectByTag("speaker_tag"); 
   object oCreature = GetFirstObjectInArea();

   while (GetIsObjectValid(oCreature)) {
       if (((GetStandardFaction(oCreature) == STANDARD_FACTION_HOSTILE_1) 
           || (GetStandardFaction(oCreature) == STANDARD_FACTION_HOSTILE_2))
           && (oCreature != OBJECT_SELF)
           && !GetIsDead(oCreature)) 
       {
           nCount++;
           break;
       }

       oCreature = GetNextObjectInArea();
   }    

   if ((nCount == 0) && !GetIsInConversation(oTalker)) {
       AssignCommand(oTalker, ClearAllActions());
       AssignCommand(oTalker, ActionStartConversation(GetFirstPC(), "alldead_dialog"));
   }

   ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_DEATH);   
}

Link to comment
Share on other sites

Just wanted to add that

GetIsObjectValid( GetNearestCreature( CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1 ) )

would probably return an accurate indication of whether or not there are any enemies left in the module. The script c_foeinsight contains a variant of the above snippet with a perception check.

 

Also, have you checked out the code for the Sith boarding party sequence after the Peragus turret game in 005EBO? It does mostly what the people in this thread describe (OnDeath script), with the only exception being that it uses a global number to keep track of how many troopers you still have to kill.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...