Here’s an AI script that keeps all units still with strategic numbers. This code snippet was taken form ADVANCED Immobile Units AI v1.1:
(defrule ;this rule has FACTS and ACTIONS to keep VILLAGERS still
(true)
=>
(set-strategic-number sn-maximum-food-drop-distance 0)
(set-strategic-number sn-maximum-wood-drop-distance 0)
(set-strategic-number sn-maximum-gold-drop-distance 0)
(set-strategic-number sn-maximum-hunt-drop-distance 0)
(set-strategic-number sn-maximum-stone-drop-distance 0)
(set-strategic-number sn-food-gatherer-percentage 0)
(set-strategic-number sn-wood-gatherer-percentage 0)
(set-strategic-number sn-gold-gatherer-percentage 0)
(set-strategic-number sn-stone-gatherer-percentage 0)
(set-strategic-number sn-cap-civilian-explorers 0)
(set-strategic-number sn-percent-civilian-explorers 0)
(disable-self)
)
(defrule ;this rule has FACTS and ACTIONS to keep TROOPS still
(true)
=>
(set-strategic-number sn-percent-enemy-sighted-response 100)
(set-strategic-number sn-hits-before-alliance-change 25)
(set-strategic-number sn-number-explore-groups 0)
(set-strategic-number sn-percent-attack-soldiers 0)
(set-strategic-number sn-task-ungrouped-soldiers 0)
(set-strategic-number sn-number-attack-groups 0)
(set-strategic-number sn-enemy-sighted-response-distance 10)
(set-strategic-number sn-total-number-explorers 0)
(set-strategic-number sn-relic-return-distance 0)
(disable-self)
)
Here’s a block of code that tells the AI to train 10 knights, 10 villagers and 2 rams:
(defrule
(unit-type-count-total knight-line < 10)
(can-train knight-line)
=>
(train knight-line)
)
(defrule
(unit-type-count-total villager < 10)
(can-train villager)
=>
(train villager)
)
(defrule
(unit-type-count-total battering-ram-line < 2)
(can-train battering-ram-line)
=>
(train battering-ram-line)
)
For the above code to work, make sure you already have Stables, Siege Workshops and adequate headroom. If you want unit counts to vary by difficulty level, check out this post I made.
If your scenario already has villagers and you don’t want the AI to get housed, add this snippet:
(defrule
(can-build house)
(housing-headroom < 4)
(population-headroom > 3)
=>
(build house)
)
As for other resources, the AI Scripting Encyclopedia is a great reference. You can also ask the AI Scripting Discord if you have any questions.
I just took a look at an AI script ffrom that scenario and yeah, that script is pretty complex, with a lot of constants, UP commands and references to other AI files. You definitely shouldn’t use those scripts as a reference if you’re a beginner.
A much simpler AI to look at would be the Greek AI in the Lepanto scenario (Conquerors-scn6 player 3). All that AI does are your basic train units and build buildings stuff. The Catalaunian Fields AIs are much longer, but they should be good reference if you want a make a relatively simple AI for a deathmatch-like scenario.