### ------ Jasperre's Improved AI - v1.3 ------

By Jasperre - Please contact me at the Bioware forums, rather then my e-mail adress, and see my Bioware Guild for bugs, and things.

I'd like to thank captaincursor, Kepp, Silk, Tony K, Paninsulas, Temrek the wizard, Timendainum, flrd2dth, adolf102_2, k_e_n_s_a_i, Icerz, Plasmatic, BloodDragon, IronHawk msippel and anyone else at my guild who Beta Tested, and a load more people for help, testing, support and the like.

#### About & Installing/Updating

This AI is a complete change to the default AI, but can easily be used as a subsitute, an addition to some creatures, and so on.
It is meant for NPC's only, not HENCHMEN or FAMILARS. I cannot state this enough - they are for NPC's only! I have removed all henchmen associated items, as I only aimed for it to be used with creatures, not with henchmen (which the improved henchmen AI takes good care of).
Installation is of some variety, so choose what you want to import into a module. Please note:
- The script from 1.0-1.2: j_inc_ondeath has been removed
- If you override the default AI files, you can get the originals by deleting the module ones, but saying NO to remove all references. The AI failes are always under "All Resources" and "Creauture AI" in the open menu too.
The seperate erf's and what they hold are here. Import them, and recompile, to make them work properly. You may only need one of these, so read the descriptions carefully :-)
AI_Jass_Override.erf - This contains the main AI, but it will override the default creature AI (including all special death and spawn scripts). It overrides the "nw_c2_defaultX" files, and Raise Dead/Resurrection (Which is not required by default).
AI_Jass_NonOver.erf - This holds the same script as above (that do the same things), but will not override anything whatsoever. Use this to not affect the default scripts if you don't want to.
AI_Jass_Optional.erf - This contains 3 things. Firstly, the Raise Dead and Resurrection spells scripts, which are optional - they make sure NPC's immediantly re-activate combat, and that PC's also warn others they are alive, so the AI can react to someone being raised by someone who is invisible. Secondly, it holds the Spell Trigger scripts, which are required if you want to have automatic spell triggers in the module. Thirdly, it contains the Basic AI include, which has many handy functions for custom AI building. The Custom AI erf also has this.
Other files included in the zip:
AI_Jass_Spawns.erf - This has a few customised spawn scripts. Some are very generic, some are speclist for some race, class or boss. It should help you get an idea of spawn options, especially the targeting methods.
AI_Jass_Customs.erf - A few custom AI files, which are detailed in the files themselves, and are set by SetCustomAIFileName("NAMEHERE"); in the spawn script. They are easily customiseable, and so can be used for either modifying, or to lessen lag of the AI for simple, or un-intelligent creatures. Please note that I would not recommend using a custom AI file creature near, or in the same area of, a normal Jasperre's AI creature.
AI_Jass_UDEs.erf - This is a set of User Defined events, using both Pre-UDE's and UDE's. Examples include Troll Regenerating, pickpocket XP and healing from being damaged.
AI_Jass_SendHelp.erf - This is a set of files for the SendForHelp bug, that override default state scripts, only commenting out the Bioware function that had a loop of all faction members. Totally optional! Shouldn't affect any module if imported (except for lowering the amount of lag). See this thread about it.
Readme Files - In here are Read Me files for all AI events, creatures, some notes on attacks and CR's, as well as the special Spawn Script options file - which details all the On Spawn options for easy reference - the in-game On Spawn file has brief notes to guide you. User Defined Events as well as Visual Effects and XP are aslo mentioned.

These are the script names, for putting in the creature slots, while the default ones are just that - default.
I recommend caching, in the module properties, at the very least nw_c2_default9, nw_d2_default2 and nw_c2_default3 (or thier non-override versions), as well as the file j_ai_detercombat. You can add all the creature AI scripts, most are very small, but in a lot of cases the 4 scripts above (Especially j_ai_detercombat!) being cached helps performance.

Default Filename | Non-Override Name | Title of event | Description
nw_c2_defaulte | j_ai_onblocked | On Blocked | Controls what to do with blocking doors
nw_c2_default3 | j_ai_oncombatrou | On Combat Round End | Every Combat Round (3 or 6 seconds) they choose an action, initiated with this.
nw_c2_default4 | j_ai_onconversat | On Conversation | This listens, for allied and enemy talking, and reacts accordingly
nw_c2_default6 | j_ai_ondamaged | On Damaged | When damaged, and not in combat, this should react aggressivly
nw_c2_default7 | j_ai_ondeath | On Death | When a creature dies, it will take some pre-set time to dissapear, and this also destroys all INT's, and non-droppable objects.
nw_c2_default8 | j_ai_ondistrubed | On Disturbed | When pickpocketed, or picks something up, this will trigger (probably setting what weapons to use again, if it was a weapon)
nw_c2_default1 | j_ai_onheartbeat | On Heartbeat | Plays animations, fast buffs, loot picking-up.
nw_c2_default2 | j_ai_onpercieve | On Percieve | This will attack enemies, that they hear or see, if not in combat.
nw_c2_default5 | j_ai_onphiattack | On Physical Attacked | When attacked (By a weapon/fist) and not in combat, they will attack the attackee
nw_c2_defaulta | j_ai_ononrest | On Rest | Not much. Mearly activated when ActionRest is taken on creature. Will make them sit cross legged for 6 seconds
nw_c2_default9 | j_ai_onspawn | On Spawn | Hub of controls for the AI. Spawn options, weapons setting done here.
nw_c2_defaultb | j_ai_onspellcast | On Spell Cast At | If a friendly or hostile spell is cast at at the creature, they will probably initiate combat.
nw_c2_defaultb | j_ai_onuserdef | On User Defined | Empty, ready for custom events to be added, with minimal (or no) changing of the above scripts.

Other Default Overrided Scripts modified:

Filename | Name of Script | Description
nw_s3_balordeth | Balor Death Fireball | This is the same, apart from it also removes the body.
nw_c2_dropin9 | Dragon/flying Appear Spawn file | This applies the effect EffectAppear to jump them down, and then executes the default On Spawn file.
nw_c2_dimdoors | Dimension Doors On Spawn | This sets the On combat Round End User defined event, and then executes the normal OnSpawn file.
nw_c2_herbivore | Herbivore On Spawn | This sets up herbivore stuff -> Auto Fleeing, No opening doors, and random walking animations
nw_c2_lycan_9 | Lycanthorpe On Spawn | This sets up the On Attacked User defined event, Fearless and nothing else special.
nw_c2_omnivore | Omivore On Spawn | Sets the creature to Fearless, no opening doors, and random walking animations
nw_c2_stnkbtdie | Skink Beetle On Death | Creates the Stink Beetles normal Cloud of Stunning, and then executes the default death script.

Other AI Scripts:

Filename | Name of Script | Description
j_ai_destroyself | Destroy OBJECT_SELF | This makes sure the creature who calls it is dead, and then destroys them completely (removes the corpse).
j_ai_detercombat | Determine Combat Round | Cache This file at least. This is the compiled default AI combat file - it is called from others via. ExecuteScript, to improve performance all round.
j_ai_heart_aimat | Heartbeat - Animations | called Via. Heartbeat, it is a compiled Animations file. It helps heartbeat performance splitting the larger parts which may not be used into different scripts.
j_ai_heart_buff | Heartbeat - PreBuffing | called Via. Heartbeat, if the creature has the Pre-buff setting set, and a enemy comes near.
j_ai_heart_serch | Heartbeat - Search for PC | called Via. Heartbeat, this moves the NPC randomly nearer the nearest enemy PC.
j_ai_setweapons | Set Weapons file | Can be used in a module to Set what weapons the NPC will use in its inventory. This is called from the combat round only if they lose a weapon, or from the Disturbed Script if they are pickpocketed.
j_ai_walkwaypoin | Walk Waypoints | This is called from the Heartbeat and End of Combat. It needs to be included mostly for the Return To Spawn Location setting.
j_ai_wingbuffet | Dragon - Wing Buffet | This is like a spell file - it performs the Dragons Wing Buffet - and is executed from the spawn file.

Include Scripts:
- Changes to these would require the base scripts to be re-compiled. I'd use "Build Module" with "Compile Scripts" option for this.
- j_inc_npc_attack is for use by module builders, especially useful for conversation actions. It has a lot of ways of initiating combat and so forth.

Filename | Name of Script | Description
j_inc_constants | Constants Include File | Contains all "const" key integers and strings, as well as very common functions used almost everywhere. This script is common to almost all AI scripts.
j_inc_debug | Debug Include File | This is included in j_inc_constants, and therefore is common to most files. It seperates the DebugActionSpeak from other things - so you can turn on and off debugging easily.
j_inc_heartbeat | Heartbeat Include File | For the heartbeat file. This contains everything the heartbeat only needs, to shorten file size.
j_inc_npc_attack | NPC attack include | Use by module builders to easily initiate combat and do some special things like an entire faction getting angry. Useful for conversation files. Point: Contains DetermineCombatRound
j_inc_other_ai | Other AI functions include | This is common to most of the Perception, Phisical attacked, and so on scripts. It cuts down file size and relieves pressure off the CPU for opening and not operating the combat bits of the AI unless need be.
j_inc_seteffects | Set Effects include | Seperated for easy changing, really. This runs through effects on a target, setting local variables so the AI runs faster.
j_inc_setweapons | Set Weapons include | This set of functions is common to the spawn script and j_ai_setweapons
j_inc_spawnin | Spawn In include | This is used for all On Spawn options and functions.
j_inc_basic | Custom AI/Basic AI include | Found in "optional" and "custom" ERF's. It has several functions for easier custom AI file's - see examples for uses of the functions (In "custom" ERF).

#### Version 1.3 Updates

- Updated routines to be faster, quicker and less repetition
- Spells include SoU spells, and are cast more randomly (for same-level spells) which help sorcerors.
- Some better casting behaviour, such as invisiblity casting
- On Spawn now calculates wether to hide automatically, same with searching
- On Spawn sets up what spells (In categories) and levels (0-9) to have less GetHasSpell checks, and less talent checks
- On Spawn sets up all item categories, and doesn't re-set them as often as before. Items should be used better
- New Spawn toggles (see On Spawn for information, and the readme for spawn options which detail it!)
- File documenting Intelligence - what levels (1-10) do what should be complete.
- Speakstring arrays added.
- Pre-X User Defined Events, which can run before normal AI in cirtain files, and stop the rest of the script in some cases.
- New User Defined Events - On Combat Action Start, and On Combat Action End.
- Split up of combat include from other files - should be faster to run/compile/etc.
- New option for "Custom AI File" (Idea taken gratefully from Georg of Bioware from thier Hordes AI)
- New targeting system, which will choose targets according to spawn settings (to make boring orcs, or killer lich's)
- Weapons are set, and picked up when disarmed. Creatures with a variety of weapons will pick the best to use, such as shield, or 2 handed
- New checks/routines for invisible people/moving/LOS/targeting/chasing
- Counterspelling, dispelling sorted better
- Spontaeos casting of healing spells :-)
- Feats are corrected, in cases, run faster, and include SoU feats
- SoU Waypoints, animations re-added
- Added most buffs to "fast buff enemy" and some ways to set up own sets of spell triggers.
- Morale improved, much better running and checks are different so are less prone. Many options OnSpawn for this too.
- More leader actions, better implimented (mass fleeing, runners, extra morale)
- Lag options - this should help and CPU cycles by user being able to stop bits of the AI being called
- Healing code optimised, and now includes undead healing :-)
- New speakstrings, ones especially made for combat (Warcries!) and random arrays for random sayings in game
- HipS should work with NPC's in combat.
- Searching after combat has been added, with searching spells. This should stop them silly invisible people
- Listening is most ciraintly improved - they will move to those around cornors and re-attack anything that appears.
- AOE spells should be moved out of only if they are dangerous for the NPC.

#### Previous Updates

##### v1.2 Update

Fixed some bugs, and changed shouts for a better version (definatly smaller, and less of them). Made the random spawn in shouts actually random to the correct value. Changed some things to be faster. Added Door blocking objects option, and some more changes to intelligence. Also added in item checks (on spawn) so there are many less checks and so forth, speeding things up. In essense, I just have speeded and cleaned things up a lot more.

Items have been re-worked - they are not perfect (as talents, which I must use, are not), but cause much less lag. Giving a creature a scroll will make them check for it each time, but this is still being developed and tested. Any info would be appreciated greatly.

There is a system of DebugStrings that *can* be said, if you want them to. Just go to the bottom of j_inc_generic_ai and uncomment one or both of the lines. both will slow down the AI by a meager amount, but I use them for bugfinding. There are some uncommented ones OnDeath as well.

Also, there seems to be absolutly no crashes happening. If you want to report anything, private message me on the bioware boards, or post a comment at the NWVault page. Ideas are also most welcome - especially exploits, anything actually, that can help.

##### v1.1 Update

This includes a modified "nw_walk_wp" file that uses my AI's version of walk waypoints. This is to remove any conflicts that may happen, and removal of things that should not go. If you are not using the override version, this will not not be needed, and should not be imported.

##### v1.0

18/3 - Initial Release.