Jump to content

Home

Attack after low health??


GeorgNihilus

Recommended Posts

I assume you mean that NPC1 starts at full health, gets in a fight with you, and when he drops to 30% health, trigger NPC2 to join the fight with him?

 

- Star Admiral

Yes :) NPC2 attacks me only when her partner is 30% health. I want her to join fight later to assist her pals instead of immediately.

Link to comment
Share on other sites

Try this. I assumed that NPC1 is set to hostile and NPC2 is set to neutral. If you want NPC1 to start neutral and become hostile after a dialog, you'll need to attach a separate script to the dialog file.

 

Be sure to set the Minimum 1HP flag in NPC1's utc file to make sure he doesn't die before triggering the script. Put this script in the OnDamaged field in NPC1's utc file.

 

void main() {
  int nFlag = IntToFloat( GetCurrentHitPoints( OBJECT_SELF ) ) < ( 0.3 * GetMaxHitPoints( OBJECT_SELF ) );
  if( nFlag && !GetLocalBoolean( OBJECT_SELF , 10 ) ) {
     SetLocalBoolean( OBJECT_SELF, 10, TRUE );
     SetMinOneHP( OBJECT_SELF, FALSE );
  object oNPC2 = GetObjectByTag( "NPC2_Tag", 0 );
  ChangeToStandardFaction( oNPC2, 1 );
  ExecuteScript( "k_ai_master", oNPC2, 1005 );
  }
  ExecuteScript( "k_ai_master", OBJECT_SELF, 1006 );
}

 

Let me know if it doesn't work.

 

EDIT: Added a local boolean check so NPC2 will be set to hostile only once instead of every time NPC1 gets damaged.

 

- Star Admiral

Link to comment
Share on other sites

Great scripting Admiral, thanks :) it works, without the local boolean. Haven't tried the one with the local boolean.

 

Now my major problem is that I want my NPC to run to a spot once her partner's health is low BEFORE engaging combat (I already have an OnNotice script to make her fight after that if she ends far from the battle area). So what I need is to force NPC2 to run to the spot when NPC2 health is low. The whole idea is to 'see' her (NPC2) running to me just a moment after the fight with her friendly NPC1 starts. Ambitious of my part ah? :giggle1:

 

Here's the script I'm using, I need to run the commented red line BUT for NPC2 ... ideas??

 

void main() {

int nFlag = IntToFloat( GetCurrentHitPoints( OBJECT_SELF ) ) < ( 0.3 * GetMaxHitPoints( OBJECT_SELF ) );

int bRun;

float fTimeout;

 

if( nFlag ) {

SetMinOneHP( OBJECT_SELF, FALSE );

object oNPC2 = GetObjectByTag( "p_handmaiden002n", 0 );

ChangeToStandardFaction( oNPC2, 1 );

// ActionForceMoveToLocation(Location(Vector(4.86255, -38.67907, 23.70791), 87.24083), bRun=TRUE, fTimeout=30.0f); but for NPC2!!

ExecuteScript( "k_ai_master", oNPC2, 1005 );

}

ExecuteScript( "k_ai_master", OBJECT_SELF, 1006 );

}

 

thanks as usual :thmbup1::giggle1:

Link to comment
Share on other sites

1x modified script coming up. :) FYI, usually 2 decimal places are enough for specifying location.

 

void main() {
  int nFlag = IntToFloat( GetCurrentHitPoints( OBJECT_SELF ) ) < ( 0.3 * GetMaxHitPoints( OBJECT_SELF ) );
  if( nFlag && !GetLocalBoolean( OBJECT_SELF , 10 ) ) {
     SetLocalBoolean( OBJECT_SELF, 10, TRUE );
     SetMinOneHP( OBJECT_SELF, FALSE );
     object oNPC2 = GetObjectByTag( "p_handmaiden002n", 0 );
  SetCommandable( TRUE, oNPC2 );
  AssignCommand( oNPC2, ClearAllActions() );
  AssignCommand( oNPC2, ActionForceMoveToLocation( Location( Vector( 4.86, -38.68, 23.71 ), 87.24 ), TRUE, 30.00 ) );
     ChangeToStandardFaction( oNPC2, 1 );
     ExecuteScript( "k_ai_master", oNPC2, 1005 );
  }
  ExecuteScript( "k_ai_master", OBJECT_SELF, 1006 );
}

 

- Star Admiral

Link to comment
Share on other sites

Excellent SA!! that did it, getting into battle as I want ... better said running into battle :thmbup1:

 

oh thanks for the 2 digits comment, a needed rest for my fingers :)

 

finally I came out with this, considering the ActionForceMoveToLocation() function was actually making her move at light speed to the place heh heh instead of running, I changed it. Should that function behave like that? :raise:

 

void main() {

int nFlag = IntToFloat( GetCurrentHitPoints( OBJECT_SELF ) ) < ( 0.57 * GetMaxHitPoints( OBJECT_SELF ) );

if( nFlag && !GetLocalBoolean( OBJECT_SELF , 10 ) ) {

SetLocalBoolean( OBJECT_SELF, 10, TRUE );

// SetMinOneHP( OBJECT_SELF, FALSE );

object oNPC2 = GetObjectByTag( "p_handmaiden002n", 0 );

SetCommandable( TRUE, oNPC2 );

AssignCommand( oNPC2, ClearAllActions() );

AssignCommand( oNPC2, ActionMoveToLocation( Location( Vector( 3.94, -41.49, 23.70 ), 81.37 ), TRUE ) );

ChangeToStandardFaction( oNPC2, 1 );

ExecuteScript( "k_ai_master", oNPC2, 1005 );

}

ExecuteScript( "k_ai_master", OBJECT_SELF, 1006 );

}

 

Soon I hope you'll see this mess you did :D in my mod, to experience your scripting in your own flesh ...

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...