Jump to content

Feature: The AI Workshop

Recommended Posts

The AI Workshop


The AI Workshop is a feature that will be in the first version of the JK2 Enhanced mod (and may soon find its way into the JKA version of the mod). Basically, it gives you a completely unparalleled AI debugging and scripting tool. I developed this primarily as a debugging tool while I was tweaking the R2D2/R5D2 AI, but you might find it useful for video making, or even just a fun thing to screw around with.


The UI

When the AI Workshop is toggled on, you will be presented with a great amount of useful information. Each AI in the game (living or dead) will have a bounding box drawn around it, in the color of the alignment. Red is for enemies, blue is for neutral NPCs, green is for allies, and yellow for an AI that you have selected (with the workshop_select command).




In this picture: A dead stormtrooper (marked in red), an R5D2 (marked in blue) and a probe droid (marked in yellow, because i have it selected)



You will also be shown a ton of useful information about both an AI that you have under your crosshair and the one that you have selected, including currently active timers, whether or not the AI is using the scripted combat move, and the current scriptFlags of an NPC. If you have an NPC selected, you will also see a grey bounding box around whatever their current goalEntity is (which could be a navgoal, item, or something else).




In this picture: A rebel that I have selected is engaging some stormtroopers, including one that my crosshair is on.




Manipulating the AI

Not only does the AI workshop let you see information on the AI, but it also allows you to manipulate it as well. In the current version of this code there are only a few things that you can do with it:

  • Change the NPC's scriptFlags
  • Change the NPC's behaviorState (to like, BS_CINEMATIC or BS_DEFAULT for instance)
  • Inject timers
  • Change the NPC's weapon
  • Change the NPC's goalEntity




I have changed this stormtrooper to use a DEMP2, and put him in BS_SLEEP so he doesn't shoot me.



I have altered his scriptflags to make him always crouching and shoot in alt fire.



I have also made him impervious to force powers, with the appropriate scriptFlag.



Demonstration of the stormtrooper using an alt-fire demp shot. They don't really charge them, in case you are wondering. ;)



Teancum, therfiles, Stoiss and 6 others like this
Link to comment

So this is some sort of on-the-fly in-game AI modification tool? It would be really nice to have something like this (a visual AI tool) in a version of the GTKRadiant editor.

Yep. Sort of. AI modification and information gathering. It lets you see what the AI is doing in depth without having to set lots of breakpoints. In the future I plan on adding more features to this, like maybe setting navgoals or something. I was also thinking about adding a system of secondary waypoints which could be created in this tool, and loaded up when a map loads, like lugormod ents.

Archangel35757 likes this
Link to comment

@@eezstreet Could you possibly add a setting that'll give the npcs higher or lower accuracy.

This is actually not really possible because the accuracy is not something that is stored on the AI itself, to my knowledge. Rather it's just hardcoded. I could alter it though at a later point.




You can now alter the rank and class of an AI, and setting their weapon to lightsaber now works correctly. In JK2, giving an AI a lightsaber is enough to make them use the Jedi AI, apparently.




Bek, Stoiss, Maksman and 1 other like this
Link to comment

What have I done....

I gave an R2 unit lightside powers, and an R5 unit darkside powers, and tasked them with fighting. The R5 unit won, because it used lightning.

So I spawned some rebels to maybe deal with it. Nope. Gripped them all to death.

Finally I spawned in another R2 and they have been fighting for a while now.











Omicron, afi, Stoiss and 2 others like this
Link to comment

Okay, one last thing: I've added some new features to the old 'nav' debug command that's in JK2. I thought it was a pretty nifty tool, but it lacked everything that I needed.


You're now able to view the properties of a nearby waypoint (including the radius, id, flags, and all of the information about the edges that connect to it) and also select it.

Most importantly though, you're able to inject new waypoints and create new links ingame. In these screenshots, I have added two new waypoints, created a link between the two, and spawned an NPC at one. I then spawned a weapon (just a dummy entity really) and assigned it using waypoint_set_goalent. The NPC successfully walked from one waypoint to another. An amazing success!




Pictured: A stormtrooper at a waypoint. I've given him a goalEnt so he doesn't wander off trying to investigate my footstep noises. I could've set SCF_IGNORE_ALERTS on him now that I think about it.


Pictured: The same stormtrooper moving to a gun, which is near another waypoint.



Omicron and Maksman like this
Link to comment

Does Radiant have any way to load the .ent files (OpenJK) or even those .nav files that I assume this system uses? Would be interesting to be able to recompile maps using the custom entities that are supported in .ent files and the .nav stuff from this in-game editor.


If not, I wouldn't see any reason why we couldn't compile some custom versions of radiant with some method to load those files (basically the same thing as a prefab, but a different format right?)

Link to comment

Nope, Radiant doesn't use .nav files. Those files are actually binary. In theory you could make a tool to convert those to .ent files or .map files, but waypoint_navgoals aren't actually part of the navigation -- they get converted to blank ref_tags. So basically the only information you'd be able to pull is the classname, origin, radius, spawnflags, and whatever connections the way points have.

Link to comment

what we need are better AI team/squad tactics... like true soldiers would do-- act as a team/squad and not all individuals... i.e. They should use better tactics to achieve an objective (flank, provide cover fire, use objects as cover, fire&return to cover, etc.)


The best AI I've played in this regard was Rebellion's WWII Sniper Elite game.

Link to comment

Halo 3 had pretty neat AI where the leader would say to throw grenades and every single enemy capable threw grenades at you (this happened to me a couple times playing on legendary, nearly screamed when suddenly my crate I was using for cover became an airborne threat in addition to the 3 other grenades exploding around me.


There's definitely stormtrooper voice lines for it, but I don't know if there's actual "flanking" behavior. I remember it felt like there was sometimes playing on early Kejim missions.

Link to comment

A new day, a new batch of features.








  • You can now view the script_targetname of an NPC in the overlay.
  • You can now view (and set) any assigned scripts for different behaviorSets (angerscripts, spawnscripts, etc)
  • You can now view (and set) any parms for an NPC
  • You can make an NPC play dialogue
  • You can force an NPC to activate a behaviorSet (such as BSET_ANGER)
Link to comment

You can also view squad information as well:






Great work, @@eezstreet! :D This is really fantastic and powerful. I feel like this is a much more powerful and compelling version than my (grotesquely unfinished) NpcSP v2. Really excited to see where this goes.


Out of curiosity, how complex is the user interface with this? Or is it all console commands?

All console commands. If you want to make a UI for it, i'd be happy to include a console command to open it up.


EDIT: Here's a list of all the commands that are available: https://github.com/eezstreet/OpenJK/blob/jk2hd/codeJK2/game/jke_aiworkshop.cpp#L822-L856

Link to comment

Would it be possible to save that in an external file like you can save bot waypoints? That way you could edit existing sp maps without having to decompile them and/or without icarus scripting.

Sorry if this has been answered before

Archangel35757 likes this
Link to comment

Would it be possible to save that in an external file like you can save bot waypoints? That way you could edit existing sp maps without having to decompile them and/or without icarus scripting.

Sorry if this has been answered before

There is a save command, yes. It uses the .nav files that the game makes anyway.


EDIT: I'm assuming you meant the waypoints and not the NPCs. You can't really save the NPCs at any current time, unless you use a savegame.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...