GeorgNihilus Posted January 12, 2010 Share Posted January 12, 2010 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? thanks on advance Link to comment Share on other sites More sharing options...
Star Admiral Posted January 13, 2010 Share Posted January 13, 2010 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 Link to comment Share on other sites More sharing options...
GeorgNihilus Posted January 13, 2010 Author Share Posted January 13, 2010 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 More sharing options...
Star Admiral Posted January 13, 2010 Share Posted January 13, 2010 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 More sharing options...
GeorgNihilus Posted January 13, 2010 Author Share Posted January 13, 2010 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? 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 Link to comment Share on other sites More sharing options...
Star Admiral Posted January 13, 2010 Share Posted January 13, 2010 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 More sharing options...
GeorgNihilus Posted January 14, 2010 Author Share Posted January 14, 2010 Excellent SA!! that did it, getting into battle as I want ... better said running into battle 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? 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 in my mod, to experience your scripting in your own flesh ... Link to comment Share on other sites More sharing options...
Star Admiral Posted January 14, 2010 Share Posted January 14, 2010 Strange. Not sure why the ActionForceMoveToLocation() would behave that way. Well, if changing it to ActionMoveToLocation() works, then great. Looking forward to see your finished mod. - Star Admiral Link to comment Share on other sites More sharing options...
GeorgNihilus Posted January 15, 2010 Author Share Posted January 15, 2010 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 ... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.