NPC AI Issues

I’ve been struggling with the general NPC AI overall in my module so I’ve come seeking help from the best. I have been trying to use Jasperre’s AI 1.4. Regardless of my set onspawn choices, feats, stats and abilities I give my NPC. They won’t cast spells, won’t equip their weapon they have in hand in the editor. They simply turn into a unarmed melee npc.

Unsure if there is a better AI system I should be using or possibly I missed a large step with installing this as it just doesn’t seem to work very often to what I have set? All I have is the imported ERF files (the overwrite version), which are what I’m using on the NPC scripts. Or maybe I’m missing a big setting in the onspawn that enables things?

I am using the AWW waypoint system, so I had to make adjustments to the heartbeat script to use the aww waypoint script, but even without the NPC following a waypoint, they still won’t cast spells they have learned, and have the feats and stats to cast. Real only addition I’ve made to the onspawn script is a script that runs at the end which adjusts it’s vTag for the waypoints it will follow.

Attached is my Onspawn script used for my healer NPC who doesn’t heal… I’ve had several iterations, but enabling or disabling options doesn’t seem to do much for me.
onspawn .txt (38.3 KB)

I suspect these scripts may apply to non EE version. Hoping there is something similar I can import to test out that might be newer that works well with EE.

I should read before posting.

The onPerception is the main script for interaction with the world, why isn’t it J_ai? Do you execute the JAI script within that script?

So for onPerception you might have some custom stuff, but then:
ExecuteScript(“j_ai_whateveritis”, OBJECT_SELF);

That’s what I initially worked with. I just tested with the J_AI_onprecieve script set on the NPC healer again and nothing changes for it’s behavior after building/save and loading up the server to test it. These are fresh j_ai scripts as of yesterday, I imported them and overwrote what I had preexisting.

I’ll keep playing with it.

Think I found a issue. Compiling issue that occurred sometime recently and I didn’t notice. However, something with the aww waypoint system scripts is causing compiling issues with anything j_ai related. Anytime my aww include file is added to J_ai script it conflicts with a MAIN function from some core game script. That prevents me from applying the waypoint script onspawn, but in how the NPC is spawned, I’m attempting to push that command from the script that is actually spawning them.

Make sure you have not uncommented the main() line at the end of aww_inc_walkway.nss. It should be commented out like this:

//void main() {}

I’s commented.

So when I add the aww include to any j_ai script I get:
x0_i0_match.nss: ERROR: DUPLICATE FUNCTION IMPLEMENTATION (GetHasEffect)

If I comment the (GetHasEffect) out from the aww inc, it then gives:
x0_inc_generic.nss: ERROR: DUPLICATE FUNCTION IMPLEMENTATION (main)

Don’t know the specifics to help there.

Unequipping item: there is an ee check that wasn’t as strictly enforced in 1.69, make sure npc has the feats to use the item and any requirements on it about race/class/etc are met (only useable by item props).

Not having an on conversation script seems weird. that’s how radial commands and all the silent messages npcs pass to each other are processed (there’s engine handling that defaults to starting their dialog on gui I think…)

That’s more like what you get when you have too many symbols for the compiler to handle. I thought that might have been fixed with EE. Strange errors in base game include files…

Thanks! I’m still figuring out each important bit to NPC AI.

It just seems that j_AI scripts or it’s includes somehow reference the base game includes, and that is somehow messing with me adding the AWW include to their files. I tried executing J_AI at the end of the aww heartbeat script. But it totally tanks the waypoint walking, and NPCs just wander around. I tried the reverse, using j_ai and executing the aww script. Same issue. And any attempt I’ve made to incorporate the AWW commands for walking waypoints into the J_AI script won’t compile. I’ve even imported the AWW overwrite which adds in the changed default scripts so just telling a NPC to walkwaypoints should make it use aww functions, but not much difference.

Right now the only thing that works, is removing j_ai scripts, and using nwn’s default npc scripts and the modified aww heartbeat, perception scripts. Just can’t get it to work with the aww waypoints - which is weird, they are just basic 1-11 waypoints. J-AI acts like it has none and just putters.

Just a quick example of what’s going on in the module. Two factions. NPCs spawn on both sides, they walk meet halfway across the map and fight. MOBA style map.

I got the two script systems to play - sort of. All J_AI scripts are set, I think what worked was swapping the walk script J_AI was calling, to aww script. Just ironing out some other issues with their walking scripts. They seem to walk 5 seconds, putter, and then stop, walk back to previous wp then continue on but very slowly. I suspect it’s because the J_AI Heartbeat runs, executes the aww script I have set. So somewhere it’s trying different things for some reason.

This is what I’m doing if anyone can spot the problem.

This was edited on the J_AI onspawn:

 if (GetWalkCondition(NW_WALK_FLAG_CONSTANT))
        {
            // Execute the script that handles waypoint movement.
            ExecuteScript("ANW_C2_DEFAULT1", OBJECT_SELF);

Commented out some following putter and animation script which helped a little with them stopping so frequently.

Still haven’t seen a single spell cast yet, so still have that issue for some reason. Doesn’t seem to matter if the NPC has the feats, stats, and spells available to their level. I see buffs fired off from most NPCs I’m working with, they just really don’t want to cast defensive or offensive spells. The caster behavior is only set within the J_AI onspawn script? I set the healing functions, ranged functions, to cast long dist spells first, or buff first. But nothing comes of it.

Have you figured this out? If not I’ve got an AI system you can try for NPC’s.

2 Likes

Unfortunately I have not @Philos. This roadblock resulted in me taking a bit of a break until I had more time to dump into adjusting and testing.

I’d be more than happy to test out your system in my module.

I found your AI upload from a few days ago, I’ll give it a shot.

I actually started making progress with some of the previous AI scripts. Just comes down to my ignorance with scripting and knowing what’s being called via the scripts and how badly I’ve messed some things up by overwriting some of the default scripts, and mixing and mashing systems together.

One thing I’m struggling with is a single NPC that is triggering some what appears to be debug dialog, with a buzzer sound every time it triggers - which is often - and I can’t seem to figure it out. Another NPC with the same scriptset do not behave the same way. Only difference is the Rogue uses daggers and Ranger uses a bow.


Setting for No: 0 Yes: 0

I’ve searched all the applied scripts on the NPC and those words don’t exist. I’ve commented out any userdefined calls which are not needed and there are no vars on the NPC that would be pulling in other functions.

Has anyone run into this before or have a suggestion where to look?

Could it be coming from an assigned feat?

Also - How are all of you debugging scripts ingame? I’ve literally only ever just save my module, Restart my server, load in via internet list in game, make my way to the area all just to test very minor changes. Is there a way to analyze a NPC’s scripts being run ingame directly?

Easiest way to debug scripts is probably to have them compile into the development folder for instant updates, and a lever to clear the area or restart the module.

I’ve never seen that error.

Do you use NWX?

My server does, and I’ve setup a local server using WSL1. Then I have my server and toolset use the same documents folder so I can work then test locally without moving files around.
Another way if you don’t use NWNX is to make a smaller test module to work on specific code then update the server once its functioning and do final testing there.

Alot of it depends on your server environment around NWNX.

I also tag my debug with the name of the script and line number so they are easy to check. AI debugging can get crazy.

I would also put some debug lines at the beginning of all the your event scripts that run on the NPC’s. This will help you see what scripts are executed when and in what order to see where the issues are happening. Just a simple WriteTimestampedLogEntry(GetName(OBJECT_SELF) + “OnHeartbeat!”); for example.

Thank you both.

No NWNX. It was too complicated of a setup for me when I tried to use it upon starting my module 5 years ago. And since - haven’t had a need for it.

Trying out the log entry now. I’m sure i could recreate the NPC and get around this, but I’m very curious what’s causing… and just like that it’s no longer occurring - I cleaned up some unnecessary feats, and I think that was causing it.