You must be logged in to post messages.
Please login or register

AI & RM Scripting
Moderated by Sebastien, Leif Ericson

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: AI scripting F.A.Q. (ask your questions here!)
« Previous Page  1 2 3 ··· 10 ··· 15  Next Page »
posted 03-17-09 10:14 PM CT (US)   
Mod Note: Most of the AI scripting community has migrated to Discord and the AI Scripters Forums. You will be more likely to get your questions answered there.

I will update this as I come up with ideas.

Question: "What does A.I. stand for?"
Answer:Artificial Intelligence.

Question: "How do I use AIs?"
Answer: you simply install them into the "AI" folder and look for the drop down list (normally titled "computer", click on it) when starting a single player game/skirmish.

Question: "What do I write AIs in?"
Answer:Notepad is fine, any text editor is fine. Be warned though, if the text editor encodes the text using hidden sybols, you will get an error in game that you cannot solve. Notepad never inserts these and therefore is the wisest choice.

Question: "How do I write AIs?"
Answer:On your installation cd there is a text file titled "CPSB". It contains all the available commands and parameters. If you have any questions, please post in the correct topic. (I warn you that there are some "strategic numbers" that are known not to work. I will post these and most likely have them stickied.)

Question: "Why won't my custom AI show up on the list?"
Answer:You must have two files for a custom AI to show up on the list of oppenents. Both files must have the exact same name, the exception will be in their extensions. One must have ".ai" (I recommend putting notes or nothing in here) and one must have ".per", this is where the code goes. Most AI's however are designed to use the first ".per" file to load other ".per" file

Example:
(load "MyNewAIFolder/TrainingList")
Syntax: (load ""foldername"/"filename"")

Question: "What is a rule?"
Answer: A rule is the basic back bone of AIs. A rule will be in the form of:

(defrule
(conditions)
=>
(actions)
)
Example:

(defrule
(game-time > 30) ;in seconds
=>
(chat-to-all "30 second mark!")
)
Question: "What is "defrule"?"
Answer:It's a simple rule starter and short for define-rule.

Question: "What's with the parenthesis at the end?"
Answer:You mean:
Example:

(defrule
(conditions)
=>
(actions)
) ;<---Here?
it is what ends a rule

Question: "How do I use "or"?"
Answer:"or" means if this OR this condition is true, than continue.
Syntax:
(or
(condition 1)
(condition 2)
)

Example:

(defrule
(or ;<---- This is the "or" starter
(game-time > 30) ;this is in seconds
(civilian-population > 2)
) ;<--- This is the "or" ender.
=>
(chat-to-all "Game started!")
)
Question: "Why is there a semicolon?"
Answer:It is to mark the presence of an author's comment. So the AI compiler/reader won't try to read it as an executable line in the rule.

Question: "Can I smush the parenthesis together?"
Answer: If that's what you are comfortable with. Make sure your ending and beginning parenthesis are where they need to be. Using the last example...
Example:

(defrule
(or(game-time > 30)
(civilian-population > 2))
=>
(chat-to-all "Game Started!"))
Question: "Can I write the lines side by side?"
Answer:Again, if that's what you are comfortable with, using the last example:

(defrule(or(gametime > 30)(civilian-population > 2))=>(chat-to-all "Game Started!"))
The "AI reader" will still read it the same way

Question: "How do I use "and"?"
Answer: This is another logical operator just like "or".
Syntax:
(and
(condition 1)
(condition 2)
)

Example:

(defrule
(or(game-time > 60)
(and(game-time > 30)
(civilian-population > 2)))
=>
(chat-to-all "Game Started!"))
Question: "What if I want more than two conditions under "or" or "and"?"
Answer:You can stack them, please view my example with heavy attention.
Example:

(defrule
(or(game-time > 30)
(or
(civilian-population > 2)
(military-population > 1)
)
)
=>
(chat-to-all "Game started!")
)
-to place this example in syntax only, it will look like this:

(defrule
(or(condition 1)
(or <---- as "condition 2"
(condition 1)
(condition 2)
) <--- end the second "or"
) <--- end the first "or"
You can even compress that to:

(defrule
(or(game-time > 30)
(or(civilian-population > 2)
(military-population > 1)))
=>
(chat-to-all "Game started!")
)
Question: "How do I make sure certain conditions are excluded?"
Answer:Say for example, you want to keep your town safe and don't want to attack if your town is under attack. There is a condition that can detect this. "(town-under-attack)". This is where the "not" condition comes into play.

Example:
;Say this would normally be your attack code.

(defrule
(military-population > 10)
(players-military-population any-enemy < 10)
=>
(attack-now)
)
;here it is using the "not" condition
;syntax is (not (condition 1))

(defrule
(not(town-under-attack)) ;force this condition to be only excluded
(military-population > 10)
(players-military-population any-enemy < 10)
=>
(attack-now)
)
Question: "Is there a version of "not" that can include more than one condition?"
Answer:Yes, this is called "nor" (neither this nor this)
Syntax:
(nor
(condition 1)
(condition 2)
)

Example:

(defrule
(nor(town-under-attack)
(game-time < 600)) ;5min is 600 seconds
(military-population > 10)
(players-military-population any-enemy < 10)
=>
(attack-now)
)
Question: "What are constants?"
Answer:Constants are user defined number constants. Constants are loaded only once in the game and can never change in value (non-goals). ALL CONSTANTS MUST BE AT THE HEAD OF THE SCRIPT!!!
Syntax:
(defconst "user definition" "value")

Example:
(defconst MaxFeudalVillagers 35)
;defconst stands for "define constant"

Question: "Why use constants?"
Answer: Say you set this 50 times in the script in different rules using this amount of villagers as a condition but, just using the number "35". Ask yourself what you would do if you needed to replace this number in every single rule? Try the replace-all function? No, you'd have to go through the whole script looking for it and changing it yourself. With constants, all you do is have to change the number in the defined constant.

Question: "What are all the symbols you can use in constants?"
Answer:Any casing of letters, symbols (on the keyboard, i.e. the "$" sign), or numbers. You cannot have spaces in the definition, example:
(defconst this number 35)

The compiler will just give you an error or a major bug. If needed you can just use the "_" symbol. Example:
(defconst this_number 35)

Question: "What are goals and how do I use them?"
Answer:Goals are variables that can save any value. Goals can be used as conditions and actions.
goal action syntax:
(set-goal "goal number" "value")
goal condition syntax:
(goal "goal number" "value")
Example:

(defrule
(condition)
=>
(set-goal 1 1) ;sets goal "1" to value "1"
)

(defrule
(goal 1 1); any other value in goal "1" will be ignored in this rule
=>
(action)
)
Or another prime example:
(defconst Attack_now 1)
(defconst YES 1)
(defconst NO 2)

(defrule
(condition)
=>
(set-goal Attack_now YES); compiler reads this as set goal "1" to value "1"
)

(defrule
(goal Attack_now YES); compiler reads this as "if goal "1" is set to "1"" do...
=>
(attack-now)
)
Goal numbers can only range from 1-70 per AI, anything above "70" will not save the value you assign it. Goal values can range from -32,000 and 32,000... the standard short integer I believe.

Question: "What are strategic numbers?"
Answer:Strategic numbers are goals that effect the AI's behavior directly. Example: "sn-camp-max-distance". This strategic number controls how far the AI is allowed to build a lumber-camp/mining-camp. The strategic number has a conditional and action syntax, they are as follows.
Strategic number conditionally: (strategic-number "strategic number title" "value compare symbol" "value")-The value compare symbol are "<,>,=,<=,>=" signs.

Example:

(defrule
[b](strategic-number sn-max-camp-distance < 10)[/b]
=>
(set-strategic-number sn-max-camp-distance 10)
)
Strategic number action: (set-strategic-number "strategic number title" "value")

Example:

(defrule
(strategic-number sn-max-camp-distance < 10)
=>
[b](set-strategic-number sn-max-camp-distance 10)[/b]
)
Question: "Is it possible to get the AI to direct its attacks towards a specific sort of building?"
Answer:This only works well with monasteries and wonders. You can find a good definition of this strategic number in the CPSB.

Example:

(defrule
(players-building-type-count any-enemy wonder > 0)
=>
(set-strategic-number sn-special-attack-type1 wonder)
(set-strategic-number sn-special-attack-influence1 100)
)

(defrule
(enemy-captured-relics)
=>
(set-strategic-number sn-special-attack-type1 monastery)
(set-strategic-number sn-special-attack-influence1 100)
)
Question: "How many goals you can use in a single script? How many timers? How many rules?"
Answer: You can manage 40 goals numbered 1 to 40, 10 timers numbered 1 to 10 and only 999 rules. Conditional loads allows you to use more rules since some of them are not loaded by the game engine at the game start.
An example of a conditional load is:

#load-if-defined JAPANESE-CIV
(defrule
(game-time > 0)
=>
(chat-to-all "Konnichiwa, I am japanese")
(disable-self);this rule cycles once and once only
#end-if
Question: "How do I use timers?"
Answer: Timer are pretty simple, if you know how to use them. This code shows a simple usage of a timer, for training a villager every 15 seconds.

(defconst VillControltimer 10)

(defrule
(true)
=>
(enable-timer VillControlTimer 1)
(disable-self)
)

(defrule
(unit-type-count-total villager < 100)
(or
(building-type-count town-center == 1)
(timer-triggered VillControltimer)
)
(can-train villager)
=>
(train villager)
(disable-timer VillControltimer)
(enable-timer VillControlTimer 15)
)
Question: "My AI sometimes doesn't build docks, Why?"
Answer: In certain situations the AI is unable to build docks: in maps with ice (including Norse Lands!), in nomad maps and in all maps in which AI start the game without a town center.

Question: "Why does my AI have idle villagers on the map?"
Answer: There are few reasons for which an AI may have idle villagers. All villagers over the 100th will be idle. If the sum of sn-food-gather-percentage, wood, gold and stone percentages is less than 100, you may see idle villagers, and naturally if all resourches are finished villagers will be idle. Also, check that your sn-maximum-wood-drop-distance, sn-maximum-food-drop-distance, sn-maximum-gold-drop-distance and sn-maximum-stone-drop-distance are set adequately high. Also, if you have sn-number-forward-builders or sn-initial-exploration-required set to anything other than zero, that can/will be a problem.

Question: "How large can a single rule be?"
Answer: If a rule is too big the game will give you an error message. Remember that a single rule can contain up to 16 "elements". Elements are facts, actions and conditions: "or", "not", "and" and such. so the following rules contains 8 elements

(defrule
(current-age >= feudal-age)
(or
(building-type-count farm < 10)
(idle-farm-count >= 2)
)
(not(town-under-attack))
(can-build farm)
=>
(build farm)
)

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.

[This message has been edited by Leif Ericson (edited 08-19-2020 @ 02:59 PM).]

Replies:
posted 03-18-09 12:56 PM CT (US)     1 / 711  
This is a great start, if anyone wants to keep adding to it, they can post more info in the thread and Ai_user_101 (or me if he disapears ) can add it to the topic.

btw, I changed the name, as this thread can serve the purposes of the FAQ and question thread like it does in SD.

"And Matt is a prolific lurker, watching over the forum from afar in silence, like Batman. He's the president TC needs, and possibly also the one it deserves." - trebuchet king
posted 03-18-09 01:15 PM CT (US)     2 / 711  
On your installation cd there is a text file titled "CPSB". It contains all the available commands and parameters.
Would it be possible to download it off the site, or would that be illegal as far as the copyright is concerned?

(Not trying to break the law here, or get banned. Just trying to know if this is possible.)

"We are only supposed to stereotype the games, and not the gamers. I think I might have blurred that line with mine though? Oh well, if the shoe fits... " - AnastasiaKafka
From here
posted 03-18-09 02:28 PM CT (US)     3 / 711  
That'd be asking for files that came with the installation CD, so I seriously doubt it's available.

At any rate, this FAQ (and forum) might get me interested in trying to write my own AI.

- ک

Ladies and Gentlemen, wear sunscreen. If I could offer you only one tip for the future, sunscreen would be IT. The long term benefits of sunscreen have been proved by scientists, whereas the rest of my advice has no basis more reliable than my own meandering experience.

This message has been brought to you by procrastination and the letters K and V.
posted 03-18-09 03:39 PM CT (US)     4 / 711  
It's a good start, but IMHO the answers are sometimes short and choppy; an inexperienced user might not be able to 'get' some of them.

For an example:
Q: How do I use "or"?
A:"or" means if this OR this condition is true, than continue.

Example:
(defrule
(or ;<---- This is the "or" starter
(game-time > 30) ;this is in seconds
(civilian-population > 2)
) ;<--- This is the "or" ender.
=>
(chat-to-all "Game started!")
)
An inexperienced scripter probably won't gain much understanding of how to structure an "or" statement - does the "or" mean that only one of the conditions below is needed, or did the author just forget to add the first set of options? Overall it's a good start but I think it could be a little more thorough in answering the Q's.

That said, I'd be happy to lend whatever I can to this effort, although I'm afraid I'm hopelessly outclassed by AI_user and others .

YoshiX100000~AoKH's Official Playtester of All Short, Funny Viking Cutscenes by Varied Equine Species, PhD-Emeritus-Magna-cum-Laude-Esq.
Now in Fuschia!!

"I wish I knew what Yoshi's doing on the roof, especially in winter." ~Sissi
"Yoshi lived up to his name and split into 100000." ~Rocking Doom
posted 03-18-09 06:19 PM CT (US)     5 / 711  
Haha, instead of structure, I think the word your looking for is "syntax".

About being hopelessly outclassed, I think you're right :P .

I don't know entirely about it being illegal to hand out the CPSB since it's just info and not source code nor even something to install the game for you.

I'll upload it to the utilities section if a "higher up" will give me the okay.

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.

[This message has been edited by Ai_user_101 (edited 03-18-2009 @ 07:24 PM).]

posted 03-18-09 07:26 PM CT (US)     6 / 711  
F.A.Q. UPDATED!

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.

[This message has been edited by Ai_user_101 (edited 04-15-2009 @ 12:13 PM).]

posted 03-19-09 01:12 AM CT (US)     7 / 711  
Great stuff! Thanks for all of your hard work, Ai_user, we all appreciate it!

Have you ever checked out Stoyan Rachev's AI editor? I used it back when I started out and I found it very useful for editing because of the colored syntaxing.

» Your attractive master.
» "Because I before E is a LIE!!!"
posted 03-19-09 02:41 AM CT (US)     8 / 711  
His AI editor gave me nothing but bugs/errors when running games with my AI, Aroon. I stopped using it after a day or two.

BTW, I first asked you to make an AI forum back in 2005. Good to see everything happens in the end.

Signed,
DaVe.
posted 03-19-09 02:47 AM CT (US)     9 / 711  
I am too lazy to sift through the CPSB document so let me ask this here-

Suppose I want to make an AI that can Crush (Castle rush- Involves a faster castle and building a castle near your enemy by 18 minutes), I will need it to mine stone and thats possible, to put lots of villagers on stone and thats possible, but is it possible to get it to build castle in the player's town?

Heaven is only what we aspire to

Everything has a reason

The purpose of life is Karm (Work), Without Work, Our lives are but purposeless- Hindu belief
posted 03-19-09 05:21 AM CT (US)     10 / 711  
Suppose I want to make an AI that can Crush (Castle rush- Involves a faster castle and building a castle near your enemy by 18 minutes), I will need it to mine stone and thats possible, to put lots of villagers on stone and thats possible, but is it possible to get it to build castle in the player's town?
It's possible to get a castle built near a player's town, but that's about it. Have a look at using the build-forward action: (build-forward castle).

I've never used forward building however, so you may need to set one of the strategic numbers (sn-number-forward-builders I think).
posted 03-19-09 06:50 AM CT (US)     11 / 711  
Some AIs makes tower rush (see "goose" AI). I think that building forward castles is not a good idea since it would be built by only a villager and if the villager will be hit from a single arrow, AI will delete the castle losing a lot of resourches.

Forward builder strategic number is needed only in islands-team islands and similar maps
posted 03-19-09 07:48 AM CT (US)     12 / 711  
On a related note, why exactly does the AI delete a building when the villager building it is attacked?

˜*°..°*˜.°*˜˜*°.˜*°..°*˜°*˜˜*°.˜*°..°*˜
_-˜°**°˜-_ »Ruler« .° »of« °. »Hell« _-˜°**°˜-_
˜*°..°*˜˜*°..°*˜.°*˜˜*°.˜*°..°*˜˜*°..°*˜
posted 03-19-09 07:59 AM CT (US)     13 / 711  
The people who programmed the AI engine hate us, is the only reason I can think of. :P

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.
posted 03-19-09 08:38 AM CT (US)     14 / 711  
to get the resources back because the vil is probably dead soon, and the enemy would destroy the building.
posted 03-19-09 11:38 AM CT (US)     15 / 711  
Ai_user's answer seems more convincing. :P
Because Murloc, what if a Castle was done building 99%? I mean, just because I hit it with my arbalest (a single arrow), it destroys the whole bloody building? And it's not likely that I'm going to destroy the building straight away. It should be sending a few more villagers to get that building up.

˜*°..°*˜.°*˜˜*°.˜*°..°*˜°*˜˜*°.˜*°..°*˜
_-˜°**°˜-_ »Ruler« .° »of« °. »Hell« _-˜°**°˜-_
˜*°..°*˜˜*°..°*˜.°*˜˜*°.˜*°..°*˜˜*°..°*˜
posted 03-19-09 12:46 PM CT (US)     16 / 711  
You guys mean if you attack the builders, the AI deletes? Yeah, that makes no sense.

"We are only supposed to stereotype the games, and not the gamers. I think I might have blurred that line with mine though? Oh well, if the shoe fits... " - AnastasiaKafka
From here
posted 03-19-09 01:27 PM CT (US)     17 / 711  
Here's the answer to that, from the guy who was made it the way it is:
32) Why does the A.I. always delete partly built buildings if the builder is attacked (losing up to 649 stone for no reason) and why does the A.I. always send all its villagers to try to take down an enemy tower (which unneccesarily disrupts the economy)? In Rise of Rome the AI didn't make those mistakes!
A – sorry. The first was an attempt to keep the AI from just sending villagers one at a time to an unfinished foundation while you picked them off. The second was an attempt to keep a nearby tower from disrupting villager production, because the AI was not able to react to a tower by simply shifting its desired woodcutting area. Both were instituted by me to try to work around the AI’s limitations.
From here: http://aok.heavengames.com/cgi-bin/aokcgi/display.cgi?action=st&fn=3&tn=38338&st=22#post23

- ک

Ladies and Gentlemen, wear sunscreen. If I could offer you only one tip for the future, sunscreen would be IT. The long term benefits of sunscreen have been proved by scientists, whereas the rest of my advice has no basis more reliable than my own meandering experience.

This message has been brought to you by procrastination and the letters K and V.
posted 03-19-09 06:53 PM CT (US)     18 / 711  
His AI editor gave me nothing but bugs/errors when running games with my AI, Aroon. I stopped using it after a day or two.
I used it just for editing and got no errors. You played the game while editing the script I reckon?

» Your attractive master.
» "Because I before E is a LIE!!!"
posted 03-20-09 01:38 AM CT (US)     19 / 711  
Yes, but that isn't the reason. I think Berrys noticed the same issues that I did (6 years ago now).

Signed,
DaVe.
posted 03-20-09 04:49 AM CT (US)     20 / 711  
There is another good reason for which AI deletes buildings when the builder is hit: the AI building bug. When an unfinished building is destroyed, AI is unable to build new buildings of the same type. This will become deadly for farms (farm bug) but it is not nice also for houses and market. Sometimes it seems to me that that bug doesn't trigger, specially for military buildings like raxes and such
posted 03-20-09 11:33 AM CT (US)     21 / 711  
No, I was pretty sure that the building had to be target and completely destroyed before the villager finishes building it. :\

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.
posted 03-25-09 06:41 PM CT (US)     22 / 711  
*bump* (issues with the forum software).

"And Matt is a prolific lurker, watching over the forum from afar in silence, like Batman. He's the president TC needs, and possibly also the one it deserves." - trebuchet king
posted 03-29-09 11:24 PM CT (US)     23 / 711  
I just uploaded my training script series in the uploads section. It would be a great place to start if you have no idea how to start writing a script.

Angry about the bailout? Get educated http://www.mises.org
posted 04-04-09 06:18 AM CT (US)     24 / 711  
Number one frequently asked question: Can the AI hunt boar?
Answer: No.

Angry about the bailout? Get educated http://www.mises.org
posted 04-04-09 02:46 PM CT (US)     25 / 711  
Is it possible to get the AI to direct its attacks towards a specific sort of building? (eg outposts in my case)

For context, I want to use outposts to show the AI where to focus attacks. They are visible to the AI at all times (via map revealers).

1010011010
[ All_That_Glitters | Pretty_Town_Contest | Other_AoK_Designs | AoE_Designs ]
Member of Stormwind Studios
posted 04-05-09 09:25 PM CT (US)     26 / 711  
Is it possible to get the AI to direct its attacks towards a specific sort of building?
This only works well with monasteries and wonders.

Example:

(defrule
(players-building-type-count any-enemy wonder > 0)
=>
(set-strategic-number sn-special-attack-type1 wonder)
(set-strategic-number sn-special-attack-influence1 100)
)

(defrule
(enemy-captured-relics)
=>
(set-strategic-number sn-special-attack-type1 monastery)
(set-strategic-number sn-special-attack-influence1 100)
)

Angry about the bailout? Get educated http://www.mises.org
posted 04-06-09 01:02 AM CT (US)     27 / 711  
Directly from the CPSB:
sn-special-attack-type1
Sets the type of object (first slot) that the computer player particularly wants to attack. Must be a valid master object ID or –1 if no special attack type is desired.

sn-special-attack-influence1
Sets the multiplier used for the special attack type 1 rating in computer player target evaluation. Must be > 0 to influence the computer player toward attacking the special type 1, < 0 to influence the computer player away from attacking the special type 1.
No one has seen significant influence to include "smart" targeting in their scripts.

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.
posted 04-09-09 10:01 PM CT (US)     28 / 711  
Just an organizational Tip

Hypothetical Question: "I've got so many AI's! The folder is too cluttered! Help!"

Answer: Go to the folder, sort by Type. Select all the files with extension '.ai'. Right click 'Properties' and check 'Hidden'. Then under the Folder's menu bar, select 'Tools', 'Folder Options', tab 'View' and select 'Do not show hidden files and folders.' Half the unsightly mess is gone.

I also do this to scenario AI's, old test AI's, helper AI's like 'idle' or 'resign', readme files, etc. Keeps the folder looking spiffy.

[This message has been edited by Bothorth (edited 10-22-2010 @ 03:14 AM).]

posted 04-15-09 03:41 AM CT (US)     29 / 711  
Can i say some other things? ^^
Also you may add (edited post: questions added)

Q: how many goals you can use in a single script? How many timers? How many rules?
Q: How to manage timers?
Q: my AI sometimes doesn't build docks. Why?
Q: why my AI has idle villagers on map?
Q: how big can a single rule be?

[This message has been edited by DuckOfNormandy (edited 04-15-2009 @ 12:32 PM).]

posted 04-15-09 12:15 PM CT (US)     30 / 711  
FAQ Updated

@Duck,
can you edit your post to where it is just the questions. It's kinda long o.O.

@Bothroth,
a good tip, though one would have to unhide the specific file extension if they ever wanted to add a new AI themselves or might've mispelled it when saving the .ai file.

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.

[This message has been edited by Ai_user_101 (edited 04-15-2009 @ 12:17 PM).]

posted 05-23-09 02:48 AM CT (US)     31 / 711  
I checked this FAQ and couldn't get help about defined constants and goals.
I've been using and scripting AIs for long time but I never got into using constants and goals (that's very basic), please someone help me find a guide to it, which shows detailed examples.
posted 05-23-09 06:41 PM CT (US)     32 / 711  
You can define constants like this:

(defconst dark-age-villagers 30)
(defconst feudal-age-villagers 40)

and used in rules like this:

(defrule
(current-age == dark-age)
(unit-type-count-total villager < dark-age-villagers)
(can-train villager)
=>
(chat-local-to-self "Train Dark Villager")
(train villager))

(defrule
(current-age == feudal-age)
(unit-type-count-total villager < feudal-age-villagers)
(can-train villager)
=>
(chat-local-to-self "Train Feudal Villager")
(train villager))

Constants can only be defined once and can't be redefined.
You can set them to different values using conditional loads:

#load-if-defined POPULATION-CAP-200
(defconst max-pop 200)
(defconst half-pop 100)
#end-if

#load-if-defined POPULATION-CAP-100
(defconst max-pop 100)
(defconst half-pop 50)
#end-if

(defconst max-villagers half-pop)

(defrule
(can-train villager)
(unit-type-count-total villager < max-villagers)
=>
(chat-local-to-self "Train Villager")
(train villager))

You can also define constants in terms of existing names

#load-if-defined AZTEC-CIV
(defconst my-explorer eagle-warrior-line)
#else
#load-if-defined MAYAN-CIV
(defconst my-explorer eagle-warrior-line)
#else
(defconst my-explorer scout-cavalry-line)
#end-if
#end-if

(defrule
(unit-type-count-total my-explorer < 1)
(can-train my-explorer)
=>
(chat-local-to-self "Train Explorer")
(train my-explorer))

Goals are just settings that can be set to a value

(defconst train-unit 1); Goal 1 (you can have 40 goals)
(defconst nothing 0); Setting
(defconst civilians 0); Setting
(defconst military 1); Setting

(defconst attack 2); Goal 2
(defconst wait 0); Setting
(defconst now 1); Setting

(defrule
(not (goal train-unit civilians))
(unit-type-count-total villager < max-villagers)
=>
(chat-local-to-self "Not enough Villagers")
(chat-local-to-self "Set Train-Unit goal to Civilians")
(set-goal train-unit civilians)
(set-goal attack wait))

(defrule
(not (goal train-unit military))
(unit-type-count-total villager >= max-villagers)
=>
(chat-local-to-self "Enough Villagers")
(chat-local-to-self "Set Train-Unit goal to Military")
(set-goal train-unit military)
(set-goal attack wait))

(defrule
(not (goal train-unit nothing))
(unit-type-count-total villager >= max-villagers)
(military-population >= max-military)
=>
(chat-local-to-self "Enough Villagers and Military")
(chat-local-to-self "Set Train-Unit goal to Nothing")
(set-goal train-unit nothing)
(set-goal attack now))

(defrule
(goal attack now)
=>
(chat-local-to-self "Attack Now!")
(attack-now))

[This message has been edited by Bothorth (edited 05-23-2009 @ 06:51 PM).]

posted 06-03-09 11:15 PM CT (US)     33 / 711  
Hey I a question related to the AI but not about scripting. I really enjoy some of the AI that you guys make. So props to you! They are challenging and fun. But, I would love to play with others against these AI. Is there anyway to play against these AI in multiplayer settings? I can't figure it out. I think that would be pretty dumb if you couldnt test these AI out in multiplayer. If there is a way that I haven't been looking for the answer hard enough. Any ideas? Thanks

Paladin
posted 06-04-09 07:34 AM CT (US)     34 / 711  
From what I'v heard (never played MP), you must create a scenario (create random seeded map) and save the computer players as the certain AI and then make sure all players either have the same ai, scenario, or both.

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.
posted 06-19-09 04:13 AM CT (US)     35 / 711  
answer please: how to make so that the computer would not move and villagers don't work. Even when I do not put AI to the player, its units all the same move and villagers work.
posted 06-19-09 04:13 PM CT (US)     36 / 711  
Using A.i. I think it's impossible, but as for scenarios, I think using the "freeze units" actions on that computer player would suffice.

You can find me on steam: first_of_few

You can also find me at: www.aiscripters.com as 'Thegreatkazein' or 'Kazein'.
posted 06-20-09 00:15 AM CT (US)     37 / 711  
There is an AI with name something like 'Immobile Units', searching it on blacksmith should help.
posted 06-20-09 11:33 AM CT (US)     38 / 711  
"Is there anyway to play against these AI in multiplayer settings?
-Paladin1231

I believe you can(as long as there's at least one other human player)set players to "computer", but I don't think you can test an AI in MP.

"Preparation is not prevention. Just because you know what's coming does not mean you can stop it."
--Me

Something to remember: always know where you're going, but never forget where you came from.

The Age of Chivalry is upon us! Visit the only wiki devoted exclusively to Aoc:H by clicking on the preceding link. Oh yeah, and it works with the HD edition, too--just make sure to get this first.
posted 07-14-09 02:55 PM CT (US)     39 / 711  
http://aok.heavengames.com/blacksmith/showfile.php?fileid=4122

Immbolie Units AI, it's the most used AI among scenario designers, far from impossible.

Incidentally, where can I find a list of object ID #'s? It's not in the CPSB or RMSG.

[This message has been edited by Gaspar (edited 07-14-2009 @ 03:01 PM).]

posted 07-14-09 09:54 PM CT (US)     40 / 711  
Incidentally, where can I find a list of object ID #'s? It's not in the CPSB or RMSG
I too was looking for that, DukeofNormandy told me about them being in AIREF.doc, I didn't find it.

If you find it, be sure to inform me.
posted 07-17-09 06:46 AM CT (US)     41 / 711  
>Gaspar

Sorry to interrupt.
[EDIT]
I thought Tushar will post an reply but it seems too long to wait.

The file of unit IDs and so on is posted at this site.
aiscripters.fourm

>Sorry Tushar...

[This message has been edited by ARFFI (edited 07-17-2009 @ 06:58 AM).]

posted 07-17-09 06:50 AM CT (US)     42 / 711  
Tusher
My name is TUSHAR not tUsher

[This message has been edited by Tushar (edited 07-17-2009 @ 06:58 AM).]

posted 08-14-09 08:53 AM CT (US)     43 / 711  
I posted this separately, but figured I would here too in order to maximize response:

I'm a noob to AI scripting. I have been creating a custom campaign where, in once scenario, the Manchus (played amiably by a combo of the Mongols and Huns) are invading Ming China. You play as the Chinese with the help of fictitious Japanese Mercenaries.

Now for the question: at a certain point--say, half-an-hour to an hour--I want one of the Manchu hordes to attack. I have given the horde max. population and a serious military advantage, so all I want is for this horde to attack when I say to. How can/should I do this? I have tried several ways (triggers and writing my own faulty AI) but they made my editor crash when I tested them.

Thanks.
posted 08-26-09 06:06 PM CT (US)     44 / 711  
To meinlman88:

I have replied to your topic. Check out my tips and tell me if they work.
posted 09-07-09 06:38 AM CT (US)     45 / 711  
Hello everyone
I am new at AI scripting.
And i lost my CD too.Can anybody among you can post the
CPSB on this forum.
Thanks in advance
mayankshrm991 or Mayank Sharma
posted 09-07-09 04:11 PM CT (US)     46 / 711  
Mayank,
How do you play the game if you don't have the cd anymore?
posted 09-08-09 00:02 AM CT (US)     47 / 711  
Hopefully he means he lost the original cd but has the conquerors still.

EDIT: Either way, no you can't have any file provided on the cd.

"And Matt is a prolific lurker, watching over the forum from afar in silence, like Batman. He's the president TC needs, and possibly also the one it deserves." - trebuchet king

[This message has been edited by Matt LiVecchi (edited 09-08-2009 @ 00:03 AM).]

posted 09-12-09 09:17 AM CT (US)     48 / 711  
But I want someone to post it here.
posted 09-12-09 01:58 PM CT (US)     49 / 711  
And he said you can't have it.
posted 09-14-09 04:41 AM CT (US)     50 / 711  
But i suggest you to check the blacksmith to find many useful tools and infos, probably also those you don't find on CD documents
« Previous Page  1 2 3 ··· 10 ··· 15  Next Page »
Age of Kings Heaven » Forums » AI & RM Scripting » AI scripting F.A.Q. (ask your questions here!)
Top
You must be logged in to post messages.
Please login or register
Hop to:    
Age of Kings Heaven | HeavenGames