Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Attack after low health??

Page: 1 of 1
 GeorgNihilus
01-12-2010, 7:17 PM
#1
Hi again :) ... I need to check an NPC's health (NPC1) and, let's say when it is in 30%, turn another NPC (NPC2) to hostile forcing her to attack me, that after approaching to me of course. How do I script this? :raise:

thanks on advance :dude1:
 Star Admiral
01-12-2010, 8:19 PM
#2
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
 GeorgNihilus
01-12-2010, 8:56 PM
#3
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.
 Star Admiral
01-13-2010, 12:08 AM
#4
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
 GeorgNihilus
01-13-2010, 3:23 PM
#5
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:
 Star Admiral
01-13-2010, 4:02 PM
#6
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
 GeorgNihilus
01-13-2010, 8:11 PM
#7
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 ...
 Star Admiral
01-13-2010, 9:08 PM
#8
Strange. Not sure why the ActionForceMoveToLocation() would behave that way. :confused: Well, if changing it to ActionMoveToLocation() works, then great. Looking forward to see your finished mod. :)

- Star Admiral
 GeorgNihilus
01-15-2010, 4:31 PM
#9
It was probably the path, not clean enough for running. It was ALMOST lineal but I have to change it slightly for the other function. Maybe I try later but now it's working ... :)
Page: 1 of 1