I had an extensive custom AI in the past, which was completely re-written.
I'll say this: If you want to add many of the things that you mention, you may need to do a lot of re-structuring of the base code.
Basically, here is where to start:
On many events, there is an opportunity to DetermineCombatRound(). When a creature sees something, it checks to see if it's hostile. On Hit, obviously. On heartbeat, there may be a check for nearby enemies as a sanity check.
Inside the determine combat round function, you need to check if they are already doing what they should be doing. I think the default NWN code just placed a variable on them to say that they were busy if they were doing anything... You may need to be more specific than that.
Let's say that your NPC has determined that there is at least 1 enemy nearby and is free to do something. Great. First thing should be to clear all actions. This will pull them out of any random walk or anything else that they may have been doing. Now, you have a plethora of choices on how to proceed.
I assigned point scores to the NPC for various things such as melee ability, ranged, magic, etc.
I also assigned the same points to PC's when they logged in. I saved these as local variables on the (N)PC. When a combat round was determined, I'd compare these stats that I assigned them. Each round, the stats were adjusted based on percentage of hp remaining and spells left. If the NPC's ratings were a lot higher than their target, they'd just do basic attacks. Save spells, don't use items, etc. In a challenging encounter, they'd each use a custom function based on their class.
For example: Clerics would first check and heal wounded, then buff, then attack if there was no one to heal or buff. They'd only buff if they weren't already winning.
If the enemy was much more powerful, the NPC would first try to retreat to pre-determined "Safe Spots" that I had placed (Just basic waypoints that I located by name "SAFE_FACTION", where FACTION is the name of their faction). If there was no waypoint, they would move toward whomever was most powerful in their group. If they were the most powerful member of their group, and there was no waypoint, they'd move away from the attacker. I should note that it's dangerous to just move away with the default functions. They get stuck on trees and things. It's better to use some math to find a spot in the direction that you want to move, and then tell them to move to that spot with proper pathfinding.
If they had at least an int of 9, they had a chance of surrendering if their health dropped too low.
In the end, my custom AI was many thousands of lines of code. I had to keep a good server running to prevent lag. In order to account for every combat spell, item, feat combination, as well as sanity checks to make sure that each is used wisely, I used switches embedded in switches, each filled with a lot of 'if' statements.
You could probably kludge the default code to appear to do things, but doing things in any intelligent manner won't happen without scripting every decision they can make in an intelligent way. Expect a large project.
EDIT:
HipMaestro: How much scripting experience do you have? Do you mostly just need to be pointed at the default code so that you can tweak it, or do you need help interpreting it so that you know where and how to alter it?
If you're a decent scripter, I advise starting by taking apart one of the other custom AI's. They demonstrate all the different techniques that are generally used. I was inspired by several different AI authors when I wrote mine (Pretty much the entire list, above). Looking at how others have taken control of the AI could go a long way to inspiring you.
'>
Modifié par wyldhunt1, 02 novembre 2013 - 08:14 .