Members | Sign In
All Forums > Mission Scripting
avatar

Scripting AI... Is it me, or is it just incredibly difficult?!

posted Apr 12, 2013 23:07:12 by xavierwise.tsn
OK, so the thing I struggle with most when I am writing a mission is scripting AI. I know some things, but I don't know enough, and it is a real pain to try and sort the AI to get allies and enemies to do what I want them to do! Here is what I know...

Set Property commands: The ones listed below can be used on both Enemy and Neutral ships

topSpeed - sets the maximum speed a ship will move. (2.465 ~ Warp 1)
throttle - how quickly a ship will accelerate to its maximum speed.
turnRate - the speed at which a ship will turn. (0.006 is the turn rate of a battleship or light cruiser. 0.008 is a fast turn rate, equivalent to the turn rate of a scout. 0.004 is equivalent to the turn rate of a dreadnaught.)

You can also choose the Add Property command, which will just add a value to the current value set. I do not believe you can use negative values to subtract for the property.

Add AI commands:

Follow comms orders (neutrals only) - will allow you to send comms orders to neutral vessels. It seems to override other AI commands.
Direct Throttle (enemy and neutrals) - this will set the vessel on a heading (in degrees). The Throttle sets how quickly the ship will accelerate to its top speed.
Point Throttle (enemy and neutrals) - this will set the vessel on a heading towards a particular point on the map. The Throttle sets how quickly the ship will accelerate to its top speed.
Target Throttle (enemy and neutrals) - this will set the vessel on a heading towards a particular named object on the map e.g. a ship, anomaly, base etc. The Throttle sets how quickly the ship will accelerate to its top speed.

Clear AI command stack: this will clear all AI command previously set

Every other command seems to be self explanatory, however they rarely seem to work how I expect. All the above commands I have tried and tested and know how they work. If you know how other commands work and have tried and tested them, then please add below! I need help with understanding what all the different commands do so I can more accurately control both enemy and allied ships in game. Post what the command does and who it can be applied to!
page   1
9 replies
avatar
BrianKuragiman said Apr 13, 2013 16:03:57
It is simple once you learn to think like the AI Stack. Everything overrides, everything else. It's all about the order you put your stack in. The very first thing I always do for enemies is clear out the AI stack. I believe they have a default behavior but seldom is this what I want or need.

Remember this one simple rule; The first thing you put in your new stack is the default action your AI will do until one of the other conditions in the stack is met. (This explanation assumes you are using the Artemis Mission Editor).

<create type="enemy" x="51865.0" y="0.0" z="21922.0" angle="160" name="KR01" raceKeys="Kralien enemy" hullKeys="medium" fleetnumber="1" />
<clear_ai name="KR01" />
<add_ai type="ATTACK" targetName="TSN Bison" value1="3.0" name="KR01" />
<add_ai type="CHASE_PLAYER" value1="5000" value2="3000" name="KR01" />


In this little basic example, our enemy, a Kralien, pops up and immediately heads for a transport to destroy it. It will follow this command above all other things... UNLESS, the player gets too close. At that point they will break off their attack on the transport to engage the Artemis. If the Artemis flees out of range the enemy will break off pursuit and attack the transport again.

Just remember this one thing, order is everything, and the first thing in your order needs to be that unit's overall goal when it arrives on the map. If you want it to escort, then make that your first command in it's stack. If you want it attack a station without fail, put it first in the stack.

Second thing to remember, if you clear the stack, you MUST put a command to chase the player somewhere in your stack or else the enemy will never engage you. You can fly right along side waving at them and they'll just wave back.. probably give you a thumbs up Elvis smile. You can even nuke them, spit at them, flip them off and they won't engage you unless you taunt them because taunting adds a new AI command to their stack if it is successful. This CHASE PLAYER command should usually be your SECOND command in their stack if their goal is not the player's death right off the bat.

I am no expert on this but this is what I have discovered when coding my own missions. It kind of sucks to have to micro manage their stack to get them to do things but then that is also a strength because you can fine tune their behavior to make them do exactly what you need them to do for your mission. It would have been nice if you could assign a default behavior PACKAGE to them when setting them up on the map. Alas. Back to editing!
[Last edited Apr 13, 2013 16:07:51]
avatar
Mike_Substelny said Apr 14, 2013 22:11:44
Those are great tips, BrianKuragiman. I would add two more:

The CHASE_ANGER block will allow an enemy ship to turn toward and shoot anything that attacks any member of its fleet, even if that target is not within the range set by the CHASE_PLAYER block.

I believe that as soon as you create an enemy or neutral ship it is assigned a random map exit point. If no conditions in its AI stack are met, the ship will proceed toward that point until it leaves the map. In the example above, once TSN Bison is destroyed the Kralien will head for its exit point. Unless a player ship comes within 5000 of the Kralien it will leave the map.

When a player Communications officer tells a neutral "proceed to your destination" he/she is ordering that neutral to leave the map via its exit point.
"Damn the torpedoes! Four bells, Captain Drayton!"

(Likely actual words of Admiral David Farragut, USN, at the battle of Mobile Bay. Four bells was the signal for the engine room to make full steam ahead).
avatar
RyanDriskel said Apr 15, 2013 18:54:38
I've been having a bit of trouble with this recently. It all makes sense to me, but I am not getting the results I want.

USING Artemis Mission Editor, though quite capable of working with the xml directly.

I've created my own fighter group (using TSN friendly, Fighter small) launching system for comms (ps: would be great if scripters could add block commands in the comms screen!). Of course, I did this BEFORE I found the scripts already posted online, but as it is I prefer my general implementation. They work just fine except for one thing: until comms gives an order they refuse to fly. They will rotate to point at the closest enemy, but they won't move. I've tried just about every add_ai command out there. I would prefer, on launch, that the fighters ATTACK the closest enemy, but if DEFEND would work, I'd go with that instead. On the key press to recall the fighters, they fly back properly (using TARGET_THROTTLE).

Because the fighters point toward the enemies, SOMETHING must be resolving. I'm not sure if there is something I'm missing on the AI command, or if I need to set another property. I have topSpeed and turnRate adjusted. If I don't clear out the ai first, they just fly off into nowhere (assume exit point), but that makes me think the throttle values are working.

<clear_ai name="Fighter A1" />
<add_ai name="Fighter A1" type="CHASE_ENEMY" />

I've tried adding values to the block, as one would when dealing with nebuals, it made no difference.

Any help would be awesome.
[Last edited Apr 15, 2013 20:57:57]
avatar
RyanDriskel said Apr 15, 2013 19:28:18
Just found this in another thread:

"When I am scripting I have a create event for any ships (usually at the same time the system is created) and then a separate event called "De-42 AI" or something. In that event I add in all the AI commands I want. Putting AI commands in the same event that creates the ship doesn't work."

I'm betting that is my issue. --EDIT: NOT AN ISSUE, I was able to add_ai in the same event as the create.

Update: This is not the issue. I tried executing the add_ai CHASE_ENEMY command with a keystroke with the same result. The fighters will rotate towards the closest enemy, but they never move.

Update 2: Got it working! Had to add_ai TARGET_THROTTLE with target ARTEMIS first. That seems random but I guess it "gets them moving"
[Last edited Apr 15, 2013 21:42:11]
avatar
BrianKuragiman said Apr 15, 2013 23:27:21
Good finds on that Ryan. I haven't even begun to screw around with fighter craft and the like so this will be a good reference for later.

Just to reaffirm what you have up there; I have NEVER had an issue with the AI taking commands that are issued in the same script as the creation script, so long as the AI commands come after the create command. :)
avatar
TravisHead said May 23, 2013 18:35:12
Gents,
Having similar AI-related issues and was about to start a thread but thought here might make more sense.
I am trying to get neutral destroyers to defend a DS but I can't seem to get them to DEFEND.
I can get them circling via POINT THROTTLE but I want them to stop that and attack any time an enemy engages them, or comes within X distance.

So far the DEFEND AI command does not seem to work, even if I clear the AI stack first.

Basically I want the defenders to circle the DS's, but engage any hostiles that approach. I then have an event to recall them to the DS again if they stray too far.
So far the closest I can find is to target the enemy ships directly but I do NOT want to have to add an event telling every defender to potentially attack every possible attacker independently.

Has anyone done this before or had nay luck with the DEFEND command?
avatar
TravisHead said May 23, 2013 18:43:34
I think I may be an idiot. I just noticed the "CHASE ENEMY" option.
Haven't tested but now i'm totally red-faced.
avatar
Mike_Substelny said May 23, 2013 20:21:17
The DEFEND block is only supposed to work if the player's Communications officer has given a neutral ship orders to "defend X." The parameters of the DEFEND block give the distance at which a enemy can approach X to trigger the neutral into action.

If the Comms officer has not issued a "defend X" order then that block does nothing.
"Damn the torpedoes! Four bells, Captain Drayton!"

(Likely actual words of Admiral David Farragut, USN, at the battle of Mobile Bay. Four bells was the signal for the engine room to make full steam ahead).
avatar
TravisHead said May 24, 2013 11:56:54
Ya, chase does exactly what I wanted.
Thanks for the desc on Defend, Mike. My Artemis skills are little rusty after 3 months of diapers and sleepless nights.
Login below to reply: