Aller au contenu

Photo

Modifying creature AI


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

#1
Shaun the Crazy One

Shaun the Crazy One
  • Members
  • 183 messages
So I've barely broken the ice on this one.  There are a few places in my mod where I'd like creaturs to prioritise NPCs rather than the player.  There is also a place where I whould like hostile NPCs to steal from a treasure the PC is raid and then flee with out trying to attack the player.  There are also a few battles where I'd like to control rather the hostile NPCs use ranged or melee weapons.  How do I go about making these small modifications to the AI scripts?

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
There's a useful handle for this kind of modification: write your script and set it as a local string on the creature, with a string name as defined in DetermineCombatRound. I don't recall the exact name off the top of my head right now, but it's something like "CombatAIScript".

I've used this to create special AI behavior like flanking.

The one thing you must absolutely do is test, test, and test the behavior again. There are a lot of things going on in the AI and things can be tricky.

I would NOT override or add onto the heartbeat script because that is more likely to wipe out behavior you should preserve.

#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
You're welcome to try to adopt my tactical AI, though the documentation might not be completely self-explanatory. I can always walk you through things.

As for your specific tasks, you can easily set NPCs to use ranged or melee weapons by using the combat AI switches. Just look through the standard on-spawn script to see how to set them (also, x2_inc_switches). Melee is default, but there are special switches for ranged and stealthy attackers.
Your first task is more complicated. I had to modify the perception, damaged, and physically attacked scripts to get them to ignore enemies and keep moving (the 'rush' command in my tactical AI). Less fluid behavior could be achieved just by giving them new commands on the heartbeat (or a pseudo-heartbeat).

#4
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
One technique I used to make NPCs ignore the PC was by creating new perception, damage, heartbeat, endcombatround, physically attacked, spell cast at scripts. What I did was add an on/off switch at the beginning. If the switch was "off", the NPC would not run the script. That way, you can give it simple commands like ActionForceMoveToObject() or such, without them responding to attacks or stop to attack on their own. The switch is also nice because it gives you an option to turn it on on a few or all of the NPCs whenever you want.

A cheap "cheater" trick to make them use only melee or ranged is this:

If you want them to use ranged weapons, give them ranged as well as melee. The AI will default to using ranged.

If you want them to only use melee, just don't give them ranged weapons.

If you want a more nuanced approach, though, you will probably need to modify the AI.

Also, the script that MC was talking about is saved as a local string on the object. The string's name is:

X2_SPECIAL_COMBAT_AI_SCRIPT

and the value is the name of whatever script you want it to run. Be careful with this, you have to use certain functions within the script to make sure that your alternate combat commands dont happen as well as the normal ones.

It has been about 6 months since I've messed with this, but I know you need to use the function:

SetCreatureOverrideAIScriptFinished();

at the end of the script. I *think* this function tells the creature to stop other attack activities for the round, but you are going to want to double check that one because I an not sure.

#5
Shaun the Crazy One

Shaun the Crazy One
  • Members
  • 183 messages
Thanks everyone, alot of helpful information.  I like M Rieder's technique for making NPCs ignore hostiles.  I'm working on those scripts now.  I'll take another look at the switches in the OnSpawn script to see how about the switches for ranged and meele attacks.  I'll have to try out the X2_SPECIAL_COMBAT_AI_SCRIPT and see what I can do with that.  I think I'm also gonna take a look at the Crossroad Keep battle from the OC.  I recall a part when the undead often charged right by you, I'd like to see how they did that.

Thank you all for your help this information gives me a great sence of direction.

#6
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Good luck with the AI. It can make you want to pull out your hair!