AI scripting - how to get the AI to attack set points with a random chance?

I’m trying to script the AI to attack set points under the conditions that buildings exist on those points.

There are 5 sites, and the player has to build a Monastery on each of them. I need the AI to, on a timer, determine if each of those points have a Monastery and, if they do, pick one of them at (pseudo)random to attack.

This seems to be vaguely possible with triggers, but I’m not putting 120 triggers just for a secondary AI to launch waves at some Monasteries.

Does anyone know how to script the AI to do this, and also more generally how to script the AI to attack a certain player, both organically and on flare command?

You wouldn’t need 120 triggers if the buildings are in fixed places. Just 5 looping triggers, each one being a condition with object in area (monastery, player 1) + a timer and enemy’s move attack there as effect. It’s very simple, I don’t know if it’s easier with AI.

How good is your AI coding?
Try here

This is exactly what you are looking for.
First example is task all of AI owned eagle scouts to the center of the map. Second one is task nonlumberjacks near all lumbercamps to trees near that lumber camp.

With triggers may be easier, but with AI it feels more organical and natural

Wouldn’t that direct them to attack each specific place every time that the timer ran, though? The goal is for it to be entirely unpredictable for the player, so they can’t just station their army in one spot and ignore the other objectives.

My AI scripting has been iffy at best; I can write a full script that the AI can parse, but it doesn’t always obey it. I’ll give a defrule for something like “train cavaliers” and it’ll just… not do it, even though it meets the requirements. It’ll chat to itself, so I know the script is working, but it won’t train the unit.

It can’t hurt to give it a try though; it can’t be worse than my previous plan of 120 triggers covering each assortment of buildings.

1 Like

If by unpredictable you mean random then you could add a chance condition to each of the 5 triggers. I’m not too familiar with that (used it only once) but it should be fairly simple: you need to divide 100 per 5 hence the first trigger has a 20 chance of activating, then 40, 60, 80 and finally 100. Also each trigger has to activate the one following and deactivate the one before so they won’t have to loop anymore I think but you’d rather want a sixth trigger to loop and activate the first of the 5 at time X.
Let me know if that makes sense.