Author Topic: Commoner NPCs Fleeing Hostile NPCs  (Read 397 times)

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Commoner NPCs Fleeing Hostile NPCs
« on: October 01, 2010, 04:19:29 am »


                Hi again ':wizard:'

I'm trying to learn scripting, but it's difficult. so I am asking again if someone can help me put together a script '^_^'

I want to make my commoner NPCs run away from Hostile NPCs. I want them to scream, and I want them to shout "Don't kill me!"

Here's all the pieces I think I need, I just can't quite put them together!
  • GetLastPerceived
  • GetIsEnemy
  •     ActionDoCommand( SetCommandable( TRUE));
  •     ClearAllActions( TRUE);
  •     ActionDoCommand( PlayVoiceChat( VOICE_CHAT_PAIN2));
  •     ActionSpeakString ("Don't kill me!)~~~~~~
  •     ActionMoveAwayFromObject(object oFleeFrom, int bRun=FALSE, float fMoveAwayRange=40.0f)
I've been trying to put them together myself but I can't figure it out still, some help would be amazing ':lol:'
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Commoner NPCs Fleeing Hostile NPCs
« Reply #1 on: October 01, 2010, 08:41:56 am »


               Something like this should work. Just slap this in the scared NPCs OnPerception event.


void main()
{
//Get the last creature percieved. We'll call it oNPC.
object oNPC = GetLastPerceived();
//If oNPC is a player(or DM) or was not percieved by seeing, then end.
if (GetIsPC(oNPC) || !GetLastPerceptionSeen()) return;
//if oNPC is hostile then do stuff.
if (GetIsEnemy(oNPC, OBJECT_SELF))
    {
    ClearAllActions(TRUE);
    PlayVoiceChat(VOICE_CHAT_PAIN2, OBJECT_SELF);
    ActionSpeakString("Don't kill me!");
    ActionMoveAwayFromObject(oNPC, TRUE, 40.0);
    }
}

Hope it helps.
               
               

               


                     Modifié par GhostOfGod, 01 octobre 2010 - 07:49 .
                     
                  


            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Commoner NPCs Fleeing Hostile NPCs
« Reply #2 on: October 05, 2010, 02:16:17 pm »


               I haven't had time to check it out yet, but I am sure it will work, and really thanks a lot for the pointers as to what each line does, it really helps! '<img'> Thanks again~!!
               
               

               
            

Legacy_tmanfoo

  • Full Member
  • ***
  • Posts: 129
  • Karma: +0/-0
Commoner NPCs Fleeing Hostile NPCs
« Reply #3 on: October 06, 2010, 10:28:00 pm »


               You can always set a local variable on the Advanced tab of the NPC you want to flee combat situations.



int X2_L_BEH_OFFENSE = 0



I don't remember if it has a minimum requirement for AI level, perhaps someone else knows the answer to that question.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Commoner NPCs Fleeing Hostile NPCs
« Reply #4 on: October 06, 2010, 11:58:45 pm »


               

tmanfoo wrote...

You can always set a local variable on the Advanced tab of the NPC you want to flee combat situations.

int X2_L_BEH_OFFENSE = 0

I don't remember if it has a minimum requirement for AI level, perhaps someone else knows the answer to that question.


That works too. But I believe that would also make the NPCs flee from players. The OP asked for the NPCs to flee from other NPCs. But if in fact you want the fleeing NPCs to run from players too, then this is a simpler solution.
               
               

               
            

Legacy_tmanfoo

  • Full Member
  • ***
  • Posts: 129
  • Karma: +0/-0
Commoner NPCs Fleeing Hostile NPCs
« Reply #5 on: October 07, 2010, 04:30:30 am »


               Ohhh I missed that bit.  Perhaps I should refrain from posting when it's late.