Jasperre’s AI


I worked on AI for Neverwinter Nights, under the guise of Jasperre, where I managed to get a rewrite of the NPC battle AI done. Still said to be competitive today, despite me not updating it for a while, I was working on a Neverwinter Nights 2 version but never got anywhere – see below.

The newest (and least buggy) version of the AI is 1.4 beta 3, which fixed some logic errors and restructured part of the AI.

Download locations:

Quick changelog on the beta’s:

  • Fixes logic errors that I found.
  • Fixes some bugs in the code, most detailed at the forums.
  • Beta 2: Quickfix for something in beta 1.
  • Beta 3: Fixed bad bug with beta 1 and 2 causing creatures to not properly cast spells.
  • Beta 3: Fixed logic for polymorph spells. People can have advanced crossbow feats and now be turned into trolls any more.

I used to have a Neverwinter Nights Guild for this project (linked here for those who uses the wayback machine). I didn’t really feel the need to back this up or constantly keep acting on the reminders. If you have any serious feedback, comments or anything, post them below 🙂

BePower Update

Here is a project I’ve not yet checked out but looks to fix a ton of errors in my code. Thanks to BePower it appears! I have no idea what’s really changed under the hood, apart from fixes, but a glance looks good and I’m happy for people to rip it apart – other projects have existed based on my code. I am not going to officially incorporate this, for two reasons: 1. BePower is awesome and deserves full credit for the separate update. 2. As I say below, I don’t like some parts of the code and intended to rewrite them basically entirely (with similar functionality) meaning this kind of fix would have been moot I hope! 🙂

I actually only realised after writing the above he’s the same person who prompted me to re-do this page…*slaps forehead* thanks dude 🙂

Future Updates

I stopped working on a new version (either a proper 1.4 update to add to the vault – after all I called the last release “Least buggy”, or a full rewrite for NWN2) due to, basically, getting annoyed at Neverwinter Nights 2’s poor scripting support – ie; bugs everywhere (yeah, saying there were bugs got me nowhere), meaning the AI would actually be harder to write, or just more dumb, then the original game. There was no additional functionality, and a good-as update Henchmen AI mod was, truly, for combat AI probably just as good as a custom-made item. Cest la vie!

It’s tempting to go back to this and continue the newly revamped project I was working on. This would be nothing done soon, and the game is so old it isn’t like there is a huge demand for it, but it might satisfy my urge to rewrite the thing so there is no huge spell routine (which picks a spell to run). I will also be checking out Dragon Age, which has a similar pseudo-turn-base feel with parties of monsters – and I expect, the same kind of scripts that ran on Neverwinter Nights 1! I’ll have to see 🙂

24 thoughts on “Jasperre’s AI”

  1. Hi Jassperre, maybe you remember me I was member in your NWN2’s AI guild! However I came back to NWN2 this year and wanted to use your AI. So I downloaded this file and adapted it (quite easily) for NWN2.

    So I’d like to have your word about this. Is it ok to publish it on the vault (I really did nothing but rename spells and feats and comment out what could not be changed) or would you prefer to publish what you’ve done yourself, or send it to me so I or someone else finish it eventually or maybe you don’t want it published at all?

    I can send you what I’ve done if you want to check but I’m convinced you went past that anyway.

    Please let me know.
    Thanks for the great AI!

  2. You can put it on the vault, just give me some credit like BePower did. 🙂 If you do, send me a link and I’ll add it here – NWN2 sadly went a bit backwards with AI (I’m surprised it fully worked, some of the functions I used got half broken!) so I kind of just gave up with it, sadly!

  3. Ok fine, I will thanks. I was hoping to get some code from you hehe. It got better with the last patch (I had given up myself too at that time). They added some fun things like a possibility to create instances from areas.
    As for your code fully working I have not 100% tested it so I wouldn’t say so it’s probably terrible for warlocks but I tested some PC vs Clone fights with CopyObject() they were doing much better than with regular or TonyK’s AI.

    There also might be some glitches with the action stack which is quite tricky to handle in NWN2. I think I understood how it works though and will try to improve the things I can (like adding the missing spells and feats).

    I’ll make a demo mod then post it on the vault and keep you informed.

  4. Good stuff, only it’s “Jasperre” not “Jassperre” – I had enough trouble distinguishing myself from “Jassper” in the original NWN community, haha! (If only Bioware allowed name changes on their site, heh).

  5. Just a quick query…using your AI on NWN 1 still and having a few issues with a sorcerer that won’t attack with a dagger when engaged in melee…fires off her spells fine from range…but once the PC rushes her..she just stands there taking hits until she dies without even reacting…any thoughts?

  6. I installed your AI on a module 6 years ago, and have recently pulled it out from storage. One thing I’m trying to find is where spontaneous conversion for clerics is treated. I understand the basic game is *not* supposed to convert spells? PCs are getting annoyed by NPCs spamming Inflict X Wounds upon them back to back.

  7. Okay Joshua, seems I never added a flag to sort NPC’s doing that or not – easiest thing would be to alter

    AI_ActionCastSpontaeousSpell in j_inc_generic_ai

    And put something like return FALSE; as the first line or comment out all of the function except for return FALSE;

    This would stop healing spontaneously too which might help or hinder; if so you could check for what nSpellID is and if it matches a healing spell, continue as normal, else fail.

  8. Thanks, I’ll try that. Wouldn’t be bad if it was only doing it a few times, but the way it was working the NPC decided that ALL spells needed to be spontaneously converted to Inflict.

  9. 1.5 would have made it so there was less..predictability. Never finished it though, alas! Since they go “all out” inflict wounds sometimes seems like the best option due to the lack of cleric offensive spells sadly.

  10. Speaking of flags, do you remember off-hand which script was used as the “toggle” one to change flags for desired behavior? I was searching around, and couldn’t find it.

    Related to this, some of my PCs have asked about target priorities of NPCs since they seemed to be focused on attacking casters and will ignore their pets or other bodyguards. Might be more realistic but is making playing a low-level mage very hard.

  11. The spawn script sets the settings – nw_c2_default9 – it affects all default NPCs. It is rather extreme since I put the “best” settings on to drop into a higher level game module and not take tons of effort to make it all intelligent.

    The settings for targeting are named as AI_SetAITargetingValues. These are the best to mess with to get it to be more fair. These use the stats of the enemy with a importance value to choose what to attack, so yes, attacking mages a lot due to them having low AC, saves, etc.

    Essentially AI_SetAITargetingValues will filter a list of all targets – eg; a party of 4 with 2 summons – will get more and more limited as the categories work. They’re sequential so removing some of them (uncommenting) will alow others to be used only. Try just having the range one, or perhaps a larger band on all of them – set AI_SetAITargetingValues numbers to be 4 and 10 then it’ll get a minimum of 4 targets (the lowest 4) and a maximum of 10 (if there are lots which fit).

    Otherwise uncomment everything but the range, mantal and saves line to make it fairer on mages. See how that goes. Remember to recompile everything as well (and also beta 3 fails to include some spawn override scripts like the lycan spawn script so some monsters may remain unaffected).

    That was one area I was going to upgrade if I ever went back to it funnily enough 🙂

  12. Thanks, I’ll look at that.

    In a way, it makes sense that they would target the mage, as PCs will typically do the same for NPCs. However, PCs don’t have the huge supply of bodyguards that an NPC mage does, and they don’t always have the luxury of casting all of their spells at once expecting a single fight.

    Couple this with the tendency in NWN for fighter-types to be much more powerful than their PnP counterparts(and mages are only moderately better), the tendency for module designers to add extra HP to monsters due to damage bloat, and you end up with mages sometimes having a pretty challenging time, especially if they solo.

    On a different topic, I’m having complete AI failure when I create an NPC with Bard levels. I’ve tried it on default NWN AI, and on yours, and in both cases they pretty much just sit there and use Song and/or Curse Song repeatedly until the PCs beat them down. Any thoughts?

  13. Nope, no idea why a bard won’t cast spells at least, unless it was a bug with the functions. I remember testing bards especially due to their new sub classes and improvements with epic levels, and they seemed to work fine. Basically in my AI they are treated as sorcerers. Maybe there is a bug with the NPC creator/leveller where it isn’t adding spells or abilities they usually have?

    Also you could try the Henchman AI which does some basic changes, it’s possibly going to work better for bards if mine fails completely!

    You can also try making the bard song only have a % chance to come into effect – see AI_AttemptFeatBardSong. It usually runs first rather than casting spells.

    TBH It probably is a buggy function (not seeing the fact it has the spell effect maybe?) maybe due to the later NWN patches? Not sure 🙂

  14. Any Chance you can or are going to work on this a bit more, with the NWN EE coming out and the new support of Beamdog?
    If so I might possible have some requests, like dragons casting ranged spells while flying 🙂


    1. Only if they update the game significantly scripting-wise, not sure about dragons flying but the limits like using items and some feats or abilities being unable to be used stopped me adding more to it.

    1. No it is not NWN2 compatible, I tried to look at porting it over but it’s a very different ruleset and set of spells, and frankly was a lot more buggy when first released to make it worthwhile (severral things I used just didn’t really work).

Leave a Reply

Your email address will not be published. Required fields are marked *

Website and journal of Andrew Armstrong