Triggering Events Through Typing

Article written by Magnum Zero
Published on 08-07-2004
Tags: , ,

Introduction

We all play those campaigns (here by referred to as CPXS or CPNS) where you type a password to open a gate or you type ‘1’ to say yes to that chubby blacksmith to buy a sword. You wonder how they did it, right? (Not the smith… the designer.) Well, your awe is over! In this AI guide you will find multiple ways to pull off this seemingly impossible feat! Yay! The first step is to create your AI. To do this, open Notepad. Notepad is a program that can be found in your start menu, programs, then, accessories. Notepad is where you will type the coding for your AI. Once you have finished the coding save it as: AINAME.per (Make sure the drop down menu under it says all file types). Now, drag it into your AOK AI folder. Wait, one more step! Create a new notepad document and save it as: AINAME.ai (Make sure the drop down menu under it says all file types). Drag this into the AOK AI folder. What this file does is make AOK recognize your AI .per file. Now, the important part. In your Scenario (hereby refered to as SCX) go into players. Select and ALLIED player and change the personality to your AI. This is the player that will be used for the food trick. Now, let’s get started!

The Food Trick

This, in my opinion, is the easiest and best suited method for the people new to Age of Empires II. This method uses the “accumulate attribute”? Condition as a recognition tool for the trigger. This is a method that can be used without AI goals. Say you want to unlock a gate with a number password. In this case, the pass word will be 62.

Coding for the AI:

(defrule
(taunt-detected 1 62)
=>
(cc-add-resource food 1)
(disable-self)
)

ANALYZATION:

(defrule————————————Defines the rule
(taunt-detected 1 62) ———————Detects player one’s taunt of 62
=>
(cc-add-resource food 1) —————-adds food to the computer player with the AI
(disable-self)——————————-Disables the adding of food
)———————————————End

Triggers:

Trigger X
Loop: no
Starting state: your choice
Objective: your choice

Condition: Accumulate Attribute 1 food for player with the AI
Effect: Unlock Gate

Of course, in this method, you can use gold, wood, or stone also. But, you must pay attention to the following things:

That there is now way for the computer to get one of this resource before you want it to. This can easily be avoided by increasing the amount of attribute accumulated. Example:

(defrule
(taunt-detected 1 62)
=>
(cc-add-resource food 150)
(disable-self)
)

That adds 150 food instead of 1 food. But, then you must change the corresponding trigger like so:

Trigger X
Loop: no
Starting state: your choice
Objective: your choice

Condition: Accumulate Attribute 150 food for player with the AI
Effect: Unlock Gate

The above change makes the trigger search for 150 food from the AI instead of 1 food

Advanced Method

With this method, you don’t have to worry about player’s typing taunts too early and messing up the game.

These are for taunts 60 & 61. They are assigned to the third player.

(defrule
(event-detected trigger 1) <——————————–Ai detects that a trigger fires.
This will be the trigger close to the place where you want the player to use the taunt.
=>
(acknowledge-event trigger 1)<——–Resets the trigger so it can be re-used.
(acknowledge-taunt 1 60) <———–Resets the taunt incase it has already been typed.
(acknowledge-taunt 1 61) <———–Resets the taunt incase it has already been typed.
(set-goal 1 1) <——Activates the following:
)

(defrule
(goal 1 1) <————Taunt detection must use this to work. If the goal isn't complete, the rest is void.
(taunt-detected 1 60) <——Detects that player one taunted 60
=>
(acknowledge-taunt 1 60) <——Resets taunt 60
(cc-add-resource food 1) <——–adds 1 food for "60"?
(set-goal 1 0) <—–turns off the taunt detecting until Ai signal 1 is sent again from the triggers
)

(defrule
(goal 1 1) <————Taunt detection must use this to work. If the goal isn't complete, the rest is void.
(taunt-detected 1 61) <——Detects that player one taunted 61
=>
(acknowledge-taunt 1 61) <——Resets taunt 61
(cc-add-resource stone 1) <——–adds 1 stone for "61"?
(set-goal 1 0) <—–turns off the taunt detecting until Ai signal 1 is sent again from the triggers
)

The triggers are:
Trigger X – Looping no – off (This trigger activates the Ai script)
Effect: Ai script goal – Ai trigger 1

Trigger Y – Looping no – start on
Condition: Accumulate attribute – Player 2 – food – 1
Effect: Tribute – Player 2 to Gaia – food — 1<——This way the same 60-61 system can be used again
Effect: Open Gate/Kill object ETC.
Effect: deactivate trigger Z (The choice 2 trigger)

Trigger Z – Looping no – start on
Condition: Accumulate attribute – Player 2 – stone – 1
Effect: Tribute – Player 2 to Gaia – stone – 1
Effect: Close Gate,/Kill object ETC.
Effect: deactivate trigger Y (The choice 2 trigger)

Now simply activate trigger “X”? every time you want the “taunt” Ai system to work.

Create more triggers, for further choices, and activate them when required in your scenario/Campaign.

Method 2: AI Signals

I know this method seems daunting, it isn’t. This is how to do AI taunt systems without messing around with resources.

AI:

(Defrule
(taunt-detected 1 1)
=>
(acknowledge-taunt 11)
(set-signal X)<——Sends signal to triggers
)

(Defrule
(taunt-detected 1 2)
=>
(acknowledge-taunt 1 2)
(set-signal H)<——Sends signal to triggers
)

*Replace “X”? and “H”? with number

Triggers:

Trigger X-Looping no- Starting state on
Condition: Ai signal X<———–Gets signal from Ai saying that the player taunted 1
Effect: Lock Gate/Kill object
Effect: Deactivate Trigger X (if you want)

Trigger A-Looping no- Starting state on
Condition: Ai signal H <———–Gets signal from Ai saying that the player taunted 2
Effect: Unlock Lock Gate/Kill object ETC.
Effect: Deactivate Trigger X (if you want)

That’s it!! It is much easier than resources. You can also use the advanced method here:

Advanced AI Signal Method

This is used to keep the player from taunting and opening/closing that gate too early or whatever.

Trigger Q – Looping no – off
Condition: When a player’s unit steps in an area where you want taunts to be workable/accumulate attribute. ETC.
Effect: Activate Y and Z

Trigger Y – Looping no – start off
Condition: AI Signal X
Effect: Deactivate Trigger Z
Effect: Open Gate/Kill object ETC.

Trigger Z – Looping no – start on
Condition: AI signal H
Effect: Close Gate/Kill object ETC.
Effect: Deactivate trigger Y