Aller au contenu

Photo

Commoner NPCs Fleeing Hostile NPCs


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
Lethal_Bottle

Lethal_Bottle
  • Members
  • 14 messages
 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:

#2
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#3
Lethal_Bottle

Lethal_Bottle
  • Members
  • 14 messages
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! :D Thanks again~!!

#4
tmanfoo

tmanfoo
  • Members
  • 85 messages
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.

#5
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

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.

#6
tmanfoo

tmanfoo
  • Members
  • 85 messages
Ohhh I missed that bit. Perhaps I should refrain from posting when it's late.