Tribute-based objectives with AI scripting

Suppose you have a custom scenario where, if you tribute 100 Gold to an AI player, said AI player ally with you. You could create a trigger with an Accumulate Attribute condition with a !Gold Storage value of 100. However, that would require the AI player’s Gold to always be below 100, preventing the AI from mining Gold or training Gold units.

A better way to do tribute-based objectives is to incorporate AI scripting. In your AI script, add the following lines of code:

(defrule
	(players-tribute 1 gold >= 100)
=>
	(set-signal 1)
	(disable-self)
)

In the scenario editor, create a trigger with an AI Signal condition. Set the AI Signal Value to AI Signal 1 and add your Change Diplomacy effects. Now, when you tribute the AI 100 Gold, the AI will ally with you regardless of how much Gold it currently has.

What if, instead of a permanent alliance, you want the alliance to last only 60 seconds every time you tribute 100 Gold? To do that, use the following lines of code instead:

(defrule
	(players-tribute-memory 1 gold >= 100)
=>
	(clear-tribute-memory 1 gold)
	(set-signal 1)
)

Note we’re using players-tribute-memory instead of players-tribute. This is because players-tribute tracks tributes through the whole game, while players-tribute-memory only tracks tributes given since the clear-tribute-memory command was executed, a useful feature for repeat tributes.

Back in the scenario editor, create two triggers, one named Signal1Trigger and the other named EnemyTrigger. For Signal1Trigger, create the following:

  • Trigger name: Signal1Trigger
  • Trigger Starting State: On
  • Trigger Looping: No
  • Condition: AI Signal. AI Signal Value = AI Signal 1
  • Effect: Activate Trigger. Trigger List = EnemyTrigger
  • (Diplomacy effects that makes AI ally)

For EnemyTrigger, create the follow:

  • Trigger name: EnemyTrigger
  • Condition: Timer. Timer = 60.
  • Effect: Activate Trigger. Trigger List = Signal1Trigger
  • Effect: Acknowledge AI Signal. AI Signal Value = AI Signal 1
  • (Diplomacy effects that makes AI enemy)

Note that set-signal and AI Signal combo will not work in maps played in multiplayer. For those you need fe-set-signal and Multiplayer AI Signal

1 Like