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

The University

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: AI Scripting Guide: The World of AI Scripting (Approved)
« Previous Page  1 2  Next Page »
posted 11-06-09 07:44 PM CT (US)   
This article has been approved and can also be read at the University. - Luke

I am writing a comprehensive guide for AI scripting to encourage people to start AI scripting. This is only the first section. I will be adding to it periodically, so the actual guide will probably be much longer. I may split it up into separate guides if you all think it will be too long for one guide. It is aimed at an audience who is completely new to AI scripting or has only downloaded AI's.

Luke, If this gets submitted to the University on the main page (hopefully), please title it "The World of AI Scripting". Also, this guide is written to help others gain interest in AI scripting, so if you could help publicize this that would help out a lot. AI scripting needs to be revived! So now, onto the guide.

Here's the guide:



The World of AI Scripting:
By Leif Ericson


Chapter 1:


Prologue (Purpose):

In my opinion, far too few people know the power and enjoyment of AI scripting. Many of us have had the experience of playing against a powerful AI, but often we don’t even think of making our own. This guide is written to encourage you to throw away your misconceptions about AI and to reveal the true wonders of the world of AI scripting. I invite you to get your feet wet, to explore the wonders that AI can do for you, as a gamer, as a scenario designer, and as an Age of Kings enthusiast, so that your experience of Age of Empires II may be complete and fully enjoyable. The rest of us AI invite you to join us. Welcome to the world of AI scripting.

Introduction:

Welcome. You are about to join the thousands of people throughout the years who have experienced the joy of AI scripting. Those of you still out there who are unlucky enough to have not discovered this world, now is the time! The satisfaction of writing your own AI is far greater than designing your own scenarios. Now, let us jump in and I will show you all you need to get started with your first AI!

What are AI’s???

AI stands for Artificial Intelligence. The computer player uses AI files to tell it how to play the game. Now, before you get discouraged, let me dispel one common myth: AI scripting is not hard to understand. For many of us, the words “artificial intelligence” conjures up the image of thousands of lines of complex code that no one except a computer geek understands. AI scripting for The Conquerors is actually quite simple once you learn how. That is why I am here to teach you.

________________________________________________End of Section_____________________________________________

Section 1: What Do I Need?

First, we need to create our AI scripting toolbox. Here are the tools you need:

  • The CPSB (Computer Player Strategy Builder Guide) – you can find this by going to My Computer, right-clicking on The Conquerors icon, clicking open on the right-click menu, and opening the DOCS folder. This was the AI scripting guide that came with the game. Use it as a reference if you ever get stuck.


  • Notepad or WordPad - (Microsoft Word or other similar programs that have spell-check will think the codes in your AI are misspelled words and put an annoying squiggly line under your entire code, so I prefer to use Notepad or Wordpad). There is another text editor called AI Edit that is more geared towards AI scripting.


  • The SAMPLEAI – you can find this by going to My Computer, right clicking on The Conquerors icon, clicking open on the right-click menu, and opening the Goodies folder. This is a small AI that shows you the real basics, so I don’t encourage you to use it as a base for your AI, although you can look at it to get ideas.


  • So, now that our toolbox is ready, let’s put our hard hats on and head to work!

    ________________________________________________End of Section_____________________________________________

    Section 2: Your first rule (finally!):

    This guide is organized into sections. From now on, any code in bold print, except for headings, is code that you should put into your AI. Also, at the end of each section I will put a tip or note to wrap up the section. Now, onto AI scripting!

    First, let's talk about rules. Rules form the basis for every AI. The basic logic for rules is as follows: “if this is true, then do this”.

    Most rules follow this format:

    (defrule ;This starts the rule. Defrule is short for “define rule”.
    (fact 1) ;This is the “if” part of the rule. The AI checks if these facts
    (fact 2) ;are true. If all the facts are true then the AI continues onto the
    (fact 3) ;actions. Not all rules have 3 facts, but all have at least one.

    => ;This is the “then” part of the rule.
    (action 1)
    (action 2) ;If all the facts are true then these actions occur. Not all
    (action 3) ;rules have three actions, but all have at least one.

    ) ;this parenthesis ends the rule

    ……

    Now, let’s write our first rule. First open Notepad or whatever you’re typing up your AI with and type this rule:

    (defrule
    (unit-type-count villager => 0)
    =>
    (chat-local-to-self "I just made my first rule!!!!")
    )


    So, this rule checks to see if the AI has greater than 0 villagers. If it does then it sends a message to itself saying “I just made my first rule!!!!”.

    So, now that you know what rules, defrule commands, facts, and actions are, let me tell you a little bit more about rules. First, you can have more than one fact and/or more than one action in a rule, though you must have at least one of each in a rule.

    Also, you may have noticed that I used parentheses. In AI’s, almost everything is enclosed in parentheses, including facts, actions, and even the rules themselves. If you forget a parenthesis around one of your facts, actions, or rules you will get an error and the AI will not work. So watch for those parentheses.

    Also, many commands will use hyphens between words. I will explain this later.


    ________________________________________________End of Section_____________________________________________

    Section 3: Testing your AI

    Now, you’re probably eager to test out your rule. First, you need to save your AI. When you’ve chosen a name, type in the name and put a .per extension on the end of it. All AI’s are saved in the AI folder (go to My Computer/Local Disk (C)/Program Files/Microsoft Games/Age of Empires II/AI), so make sure you navigate to this folder before you save it.

    Next open up a new document and this blank document with the same name as your AI but with an .ai extension instead of a .per extension.

    So, the names of your two files could be:
  • My First AI.per
  • My First AI.ai

    The .per file includes all the code that the game reads. However, the game needs the .ai file to be able to open the AI file. So, every AI file you create will need two files, one with a .per extension and one with an .ai extension.

    Now, to see your AI at work, open up Age of Empires and get ready to start a random map game. To get your AI to play in the random map game, click on the arrow box to the left of your player file, and select the name of your AI.

    Screenshot

    Then, start the game, and watch the AI yell its message out.


    My AI isn't working!

    If your AI has an error in it a window will come up that looks like this. If no window pops up that means your AI is error free (horray!).

    The first line says which player has the error. Since player 1 has the error, something is wrong with the AI for player 1.

    The second line says what the AI file is that has the error (in this case My First Ai.per).

    The third line is the most useful. It will tell you which line the error is on, what type of error it is (more on that later), and it will show the words or symbols that are giving you the error.

    In this case, I put pillager in my AI in line 2 instead of villager, so I can edit my AI, save it, and restart the game and see if that fixed it.

    If you can't find your error go through these steps:

    1. Make sure your AI looks exactly like this: (copy it if you need to, but I would rather you typed it)

    (defrule
    (unit-type-count villager > 0)
    =>
    (chat-to-all "I just made my first rule!!!!")
    )

    2. Make sure you saved both a .per and an .ai file under the same name, and make sure they are saved in the AI folder.

    3. When setting up the random map game, choose all the game settings before you select the AI from the list.



    If you're using AI Edit, anything that is misspelled will show up in a green color. This allows you to see errors quickly, although it won't change colors if it's missing parentheses.

    ……

    You just made your first rule. Congratulations!


    The disable-self action

    Now, one thing that probably bugged you was that your message kept displaying over and over and over and over and over… To stop this rule from repeating you can add a disable-self action at the end of your rule before the last parenthesis. Whenever you place a disable-self action at the end of a rule, the rule will only run once.

    Your rule will look like this with the disable-self command:

    ;The use of the disable-self action

    (defrule
    (unit-type-count villager > 0)
    =>
    (chat-to-all "I just made my first rule!!!!")
    (disable-self)
    ;<~~~the disable-self action
    )

    Now, you can save your .per file and test your AI, and it will only send the message once. (Hooray!).

    Note:

    One thing to note is that anything following a semi-colon will not be read by the computer when it runs the AI. This allows scripters to write comments in their AI, for the benefit of the reader. The semi-colon can be placed either at the beginning of a line or in the middle of a line, as shown above.

    Tip:

    Rules cannot consist of more than 16 lines of code; otherwise you will get an error. Now 16 lines of code in one rule may seem a huge amount right now, but some of the rules in more complex AI’s will have at least 12 lines in each of them!

    Also, you can have a maximum of 999 rules in an AI, a number you will not likely reach at this point, but it’s a good thing to know.:)

    ________________________________________________End of Section_____________________________________________

    Section 4: Your first AI script

    Now the ability for an AI to chat is great, but your AI needs to be able to do more than just chat. These next rules will guide your AI through the Dark Age, the first step to making a great AI. Add these rules to the AI you made in Section 2.

    Before this, I want you to think of your own playing style. Your first AI should try to implement your style of play. How many villagers do you make in the Dark Age? Do you rush in the Feudal Age or boom to the Castle Age? What armies do you use? These are some example questions to think about when writing your AI. The rules I will give you will only form the base of your AI. Once you become comfortable with AI scripting feel free to make any changes to your AI or add new rules to it. My playing style will be different from yours, so my AI will not be the same as yours.

    First Rule: Building Houses

    However, I believe you and I will both agree that the first thing you do is build a house, unless you’re Huns. You could use this rule below to build a house:

    (defrule
    (can-build house)
    =>
    (build house)
    )

    However, this rule would be inefficient because the AI would build a house whenever it could, causing the AI to have an excess of houses and wasting labor and resources. Often in rules you will add more criteria (facts) to make your AI more efficient. Here is a better rule to use: (add this rule to your AI)

    (defrule
    (can-build house)
    (housing-headroom < 4)
    ;the difference between the current population and supportable population (not the
    ;amount of population houses support)
    (population-headroom > 3) ;the difference between the current population and the population limit
    =>
    (build house)
    )


    Housing-headroom and population-headroom make the AI more efficient. Checking to see if the housing headroom is less than 4 will make sure that the AI is running out of population room before it builds a house. Checking the population headroom will make sure that the AI won’t keep building houses when the AI is very close to the population limit. You don’t want your AI ending up with 100 houses because you forgot to check the population headroom!

    Next Rule: Training Villagers

    The next thing you want your AI to do is train villagers. You always want to train villagers constantly in the Dark Age. Here is a good rule to train villagers:

    (defrule
    (current-age == dark-age)
    (unit-type-count-total villager < 30)
    (can-train villager)
    =>
    (train villager)
    )


    You can change the number of villagers you want to make to any number. However, the best number of Dark Age villagers for AI’s is usually between 25 and 32, depending on its feudal age strategy.

    Building the Mill:

    After you train your villagers, the next step is to build your mill. In AI, there is a nifty fact called “resource-found”, which will detect whether a specified resource is found. This fact is especially useful when building drop-off buildings. Here is a good rule to build mills.

    By the way, this rule will not work if the AI is Huns. Why? This is because it tries to make sure a house is built before it builds its mill. Obviously, Huns will never have a house, therefore this rule will not run. As you get more experienced in scripting, you have to think about things like this.

    (defrule
    (building-type-count-total house > 0) ; We want to build a house before a mill
    (building-type-count-total mill == 0) ; Prevents the construction of multiple mills
    (resource-found food) ; Builds a mill only if forage bushes or deer is found
    (can-build mill)
    =>
    (build mill)
    )


    Building the Lumber Camp:

    The rule for building lumber camps is similar to those for building mills. We use the resource-found rule again, this time for wood. Usually we want our lumber camp built after the mill, so we add a fact to make sure a mill is built first.

    (defrule
    (building-type-count-total mill > 0)
    (building-type-count-total lumber-camp == 0)
    (resource-found wood)
    (can-build lumber-camp)
    =>
    (build lumber-camp)
    )


    Building Farms:

    Farms are a very important building for AI’s. AI’s cannot hunt boar and they have difficulties hunting deer, so an AI will want to make farms sooner. It will want to have enough farms so that almost all their foragers will be able to transfer to farms when the forage bushes are exhausted. One handy fact for building farms is the “idle-farm-count” fact, which checks how many farms are idle (pretty much self-explanatory). It’s useful to make sure the AI doesn’t build too many farms that don’t have any farmers on them.

    (defrule
    (current-age == dark-age)
    (building-type-count-total lumber-camp > 0) ; We want a lumber camp before farms
    (unit-type-count-total villager > 15)
    (building-type-count-total farm < 15)
    (idle-farm-count < 4) ; Only build farms if there are less than 4 idle farms
    (build farm)
    )


    Advancing to the Feudal Age!

    Our first AI is ready to advance to the Feudal Age! We want the AI to advance when it is done training villagers, and we want to make sure it has the buildings it needs.

    (defrule
    (current-age == dark-age)
    (building-type-count-total mill > 0)
    (building-type-count-total lumber-camp > 0)
    (unit-type-count-total villager >= 30) ; If you changed the number of villagers it trains, modify this number
    (can-research feudal-age)
    =>
    (research feudal-age)
    (chat-local-to-self "Feudal Age, here we come!")
    )




    Strategic Numbers:

    However, before we test the AI, there is something we have to add to the AI: strategic numbers (sometimes abbreviated SN’s). I’ll explain strategic numbers in more detail later, but for now it will suffice to say that strategic numbers affect the behavior of the AI. For example, without these strategic numbers, some villagers will explore instead of gathering resources or constructing buildings. I'll explain them briefly for now.

    (defrule
    (true)
    =>
    (set-strategic-number sn-percent-civilian-gatherers 50)
    (set-strategic-number sn-percent-civilian-explorers 0)
    (set-strategic-number sn-percent-civilian-builders 50)
    )


    These strategic numbers specify what percentage of your villagers are gatherers, explorers, or builders. So, ideally, 50 percent of our villagers will gather resources and 50 percent of our villagers will build buildings. Usually, we don’t want villagers to explore because they wouldn’t be gathering resources. There are times when we want villagers to explore - for example, if the AI can’t find its forage bushes - but we’ll take care of that later.

    One thing to note is that while 50 percent of our villagers are specified as builders, there won’t always be half of the villagers constructing buildings. If there aren’t any buildings to be built, the AI is smart enough to tell those builders to gather resources.

    However, when the time comes to construct many buildings we want to have a large number of builders, because AI’s are slow at constructing buildings. AI’s only use one villager per building, and they will only build one of each type of building at a time. For example, the AI will only build one farm at a time instead of three, though it can send another villager to build a mining camp while the farm is being built.

    Here’s some more useful strategic numbers:

    (defrule
    (true)
    =>
    (set-strategic-number sn-minimum-civilian-explorers 0)
    (set-strategic-number sn-cap-civilian-explorers 0)
    (set-strategic-number sn-total-number-explorers 1)
    (set-strategic-number sn-number-explore-groups 1)
    (set-strategic-number sn-initial-exploration-required 0)
    (disable-self)
    )


    These strategic numbers tell the AI how to explore. The first strategic number (SN) tells the AI the smallest amount of civilians (villagers, trade carts, etc.) the AI can use for exploring. Right now we want 0 villagers exploring. The second SN gives the cap or the maximum of civilian explorers the AI can use. We’ll set this to 0. The third SN gives the total number of explorers (both civilians and military units) the AI can use We only want one unit - the scout cavalry or eagle warrior - to explore, so we’ll set this to 1.

    The third SN gives the number of groups for explorers. This needs to be set to the total number of explorers. Originally, I believe Ensemble Studios intended the AI to be able to have two or more soldiers to be able to explore in a group, but they must have scrapped the idea for practical reasons. So now, AI’s will only use one soldier per exploring group, so matter what value you give this SN.

    The last SN tells the percentage of the map that the AI has to explore before it builds buildings. We can set this to zero to allow it to build buildings immediately.

    ;(Last Rule!!!)

    (defrule
    (current-age == dark-age)
    =>
    (set-strategic-number sn-food-gatherer-percentage 60)
    (set-strategic-number sn-wood-gatherer-percentage 40)
    (set-strategic-number sn-gold-gatherer-percentage 0)
    (set-strategic-number sn-stone-gatherer-percentage 0)
    )


    These strategic numbers set how many villagers are assigned to each resource. So, 60 percent of villagers will gather food and 40 percent will gather wood. We don’t want the AI to gather gold or stone until later. These percentages will usually get an AI through the Dark Age pretty well, but most AI’s will tweak them throughout the Dark Age. I’ll show you how to do this in my next guide.


    Dark Age is finished!

    Congratulations! You just made your first AI gather resources, construct buildings, and advance to the Feudal Age. You’re well on your way to becoming an AI scripter. In later sections, we will modify this code to make it faster or more efficient.

    I encourage you to experiment with different numbers and test out your AI. Add some new rules, change some numbers, add more facts to the rules, and just have fun and experiment. This is a great way to learn how to make your AI more efficient and also it gives your AI more of a personality. If you have time, you can read the CPSB and learn more facts and actions that you can use.

    When editing your AI, there is a shortcut so you don't have to close out of the game to edit your AI. You can press alt-tab or the start menu key to minimize the game, then make changes to your AI, then maximize the game, and restart the random map game you were previously testing your AI on. This is much faster and easier than opening and exiting the game every time!

    Extra Challenge:

    Try creating code to make the AI to build a barracks. Hint: remember the “can-build” fact and the “build” action. Also, to make it more efficient, add facts to check if it has built a lumber camp before it builds the barracks.

    Note:

    In AI scripting, symbols such as > (greater-than), < (less-than), or == (equal) are called relative operators ("rel-op" for short). Other symbols you can use are >= (greater-or-equal), <= (less-or-equal), or != (not-equal). This will be important when I teach you syntax of facts and actions. However, make sure you use two equals signs (==) when you want to say “equal”. Using one equals sign (=) will give you an error)!

    Tip:

    The AI runs the code from top to bottom. So, the first rule it looks at in our AI is the rule that chats “I just made my first rule.” Sometimes, if a rule is deeply buried in an AI, the AI won’t be able get down that far and the rule might not run, or it might run after a delay. In the future, the rules that are the most important should go at the top of your AI. So, try moving the advance to Feudal Age rule to the top of your AI, so that this rule will run quicker.

    ________________________________________________End of Chapter_____________________________________________

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´

    [This message has been edited by Leif Ericson (edited 10-16-2010 @ 01:26 AM).]

  • Replies:
    posted 05-02-13 10:15 PM CT (US)     51 / 70  
    Could you post a screenshot of your pregame screen? Do you have a dropdown list at all, or does it just not display any AIs?

    If it's the latter, you must be lacking an AI file. AIs need to AI files to work. One includes all the code (the .per file), and one file allows the AI to show up on the dropdown list (the .ai file). Do you have any AI files with an .ai extension?

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 05-04-13 11:35 AM CT (US)     52 / 70  
    I do not have a drop down list at all. I am on standard game, random map. It is age of conquerors full version, with the disc in. I can't think of why it wouldn't be there.
    posted 05-04-13 04:56 PM CT (US)     53 / 70  
    I did some tests on my computer, and I replicated your problem by deleting all the AIs in my AI folder. If you go to C://Program Files/Microsoft Games/Age of Empires II/AI, what do you see inside that folder? If you don't have any AIs in there, that would explain why you don't have a dropdown list.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 05-15-13 08:43 PM CT (US)     54 / 70  
    Sorry I cannot take a screen shot as it is on my windows xp. That computer is not connected to the internet, that wouldn't have anything to do with it right? When I bring up the ai folder, the files (including the two i made following your instructions) read as follows: AI (text document), AI Agressive (text document), AI custom.per (mine), document (text document), and AI custom.ai (mine). Thank you very much for taking the time to help me, as I am not very savvy.
    posted 05-16-13 01:20 AM CT (US)     55 / 70  
    Okay. Try this. Download The Horde AI from the Blacksmith (or any other AI) and put all the contents in your AI folder. Close AoK if it's open, and then launch the game. Go to the random map game menu and tell me if a button appears that you can click on to display a dropdown menu. If it appears, your AI might not have been saved in the right format.

    What program are you using to edit your AI files?

    EDIT:

    I just read that your XP isn't connected to the internet. You could try downloading The Horde and copying the files onto your XP with a flash drive if you have one. If that's not possible, I'll try a different tack. If you're using Notepad and you click Save As, in the window that pops up there should be some encoding options by the save button. What encoding setting is selected. It'll probably be either ANSI or Unicode. Mine is set to ANSI. You may want to change the encoding to that setting if it isn't already.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´

    [This message has been edited by Leif Ericson (edited 05-16-2013 @ 01:30 AM).]

    posted 05-17-13 08:23 PM CT (US)     56 / 70  
    Great, I figured it out. Thank you so much for the help!!!
    posted 05-18-13 03:30 PM CT (US)     57 / 70  
    You're welcome. What solved the issue? I'm curious.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 05-23-13 06:48 AM CT (US)     58 / 70  
    Yo dude, I have a simple question. I really want to do AI scripting to for making my custom scenarios but I don't know where I can find my files because I use AOE2HD with Steam. So the folders are not 'goodies' and within 'Docs' there is no AI files. Can you help me out please?

    Thank you,

    Bram
    posted 05-24-13 10:15 PM CT (US)     59 / 70  
    I looked through my Steam directory, and I didn't find those files. I'm not sure if they came with the Steam version of the game. I'd be willing to email the CPSB file to you if you like. You can find the Sample AI here. This file is very similar to the Sample AI anyway.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 07-18-13 07:35 AM CT (US)     60 / 70  
    This is a great introduction to AI scripting. However, I noticed a few things:
    - '(unit-type-count-total villager => 0)' should be '(unit-type-count-total villager > 0)'. Then again, perhaps this was a deliberate syntax error designed to illustrate AI debugging.
    - The farm building rule lacks a '(can-build farm)' condition. I have read that if such a condition is missing from a rule, it can cause all sorts of bugs.
    - The first and third SN rules should include a '(disable-self)' action, since they only need to execute once.

    Do you know if there are any tutorials currently available that include UserPatch elements (e.g. boar hunting)? All the tutorials I have seen are for 1.0c.
    posted 08-20-13 04:55 AM CT (US)     61 / 70  
    I would like to have simple AI, where computer player (player 2) starts imeadetly attacking player 1 (human) whit everything he got and could build, but still using defined in-game AI.

    Can someone do that and send me file, pleas?+
    biznis.luka@hotmail.com
    posted 08-20-13 06:59 AM CT (US)     62 / 70  
    Good work Leif, maybe it should mention this tutorial is for 1.0C.

    For example "AI’s cannot hunt boar". This is not true anymore for userpatch.
    posted 08-20-13 11:14 AM CT (US)     63 / 70  
    I made this guide almost three years ago, so that's why I didn't mention it. I should probably update it.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 08-20-13 11:04 PM CT (US)     64 / 70  
    @balakul
    Post your request in the AI and RMS Scripting forum, and someone should offer to help.

    [This message has been edited by EmperorJustinian (edited 08-20-2013 @ 11:06 PM).]

    posted 01-12-14 07:26 AM CT (US)     65 / 70  
    Now its actually four years. Where is Chapter 2? I want to see it!!!! This AI Scripting Guide is great, but it only applies to RM Maps! I want to see an AI Scripting guide that applies to more complex maps, such as RPG's -- where the AI are doing much more complicated things. That's where I am having problems.

    I am just pasting from a post I made in the forum regarding my problems with AI ---

    "I have several maps (with lots of scenery and TONS of triggers) where the AI is lagging. They are taking so much time to process the LOADS of units they have. And also how they will use these units against what we have. So the AI's units are going ballistic, moving everywhere. The map is lagging so very bad whenever we test it. In one of my maps, one AI has over 2000 units and the other AI has about 500. This creates far too much lag. I don't know how to fix. Is this something that AI Scripting can fix. If so, how can I fix it? If not, how do I fix it another way? Any help would be appreciated!!

    And, on the same lines, my AI, at times, do not fight back. I will be playing in my RPG, destroy a gate, and the boss inside doesn't attack me. I kill them with ease --- no fight back. Is this related to the AI problem posed above? It's odd how they would not fight back against me. And lag? That's quite odd... Hmmm... Any suggestions? Help? Advice?"
    posted 05-03-14 06:09 PM CT (US)     66 / 70  
    While I'm no AI expert, I would be inclined to believe that the vast numbers of units you are using have caused the lag, especially if you have an old computer.

    AI scripting only directs an AI's actions, so while very complex, poorly organized scripts may cause lag, I do not believe it is an AI's fault in this case. Unless you have an AI like that, AI scripting / editing won't eliminate the lag problems. As for the not fighting back, make sure teams are locked as enemies, and that you were enemies in the first place.

    The problems with troop management, however, are very fixable. The commands
    (set-strategic-number sn-percent-attack-soldiers)
    (set-strategic-number sn-number-attack-groups)
    (set-strategic-number sn-number-defend-groups)
    (set-strategic-number sn-maximum-attack-group-size)
    (set-strategic-number sn-minimum-attack-group-size)
    (attack-now)
    are basic troop management options. More can be found in the CPSB under the heading "Appendix A - Internal Strategic Number (SN) parameter documentation"
    Also, make sure to use these commands
    (set-strategic-number sn-number-explore-groups 0)
    (set-strategic-number sn-maximum-explore-group-size 0)
    (set-strategic-number sn-minimum-explore-group-size 0)
    to prevent the AI from using troops to explore.
    That's all I've got for you, so if you have more questions, take a look at the CPSB.
    Good luck, I hope this helps!

    [This message has been edited by Artur Hawkwing (edited 05-03-2014 @ 06:13 PM).]

    posted 04-09-15 06:15 PM CT (US)     67 / 70  
    it keeps telling me Line 367: ERR2005: Invalid Identifier: defrule

    (defrule
    (can-research ri-careening)
    =>
    (research ri-careening)
    )
    (defrule;350
    (can-research ri-hand-cart)
    =>
    (research ri-hand-cart)
    )
    (defrule
    (can-research ri-town-patrol)
    =>
    (research ri-town-patrol)
    )
    (defrule
    (building-type-count-total monastery == 0)
    (can-build monastery)
    =>
    (build monastery
    )
    (defrule
    (unit-type-count monk <= 5); og prob line 367
    (can-train monk)
    =>
    (train monk)
    )
    (defrule
    (can-research ri-atonement)
    =>
    (research ri-atonement)
    )
    (defrule
    (can-research ri-sanctity); line 373 after 1st change
    =>
    (research ri-sanctity)
    )
    (defrule
    (can-research ri-fervor); line 373 after 2nd change
    =>
    (research ri-fervor)
    )


    i don't know y
    i have removed it with ";" (yes the whole thing from "(defrule" to ")" but now it says Line 373: ERR2005: Invalid Identifier: defrule and i still don't know y but when i removed it with ";" it says Line 373: ERR2005: Invalid Identifier: defrule and it keeps telling me the same as the last someone please help meeeeee
    BTW this is my 3rd day working on my 1st AI
    posted 04-09-15 06:50 PM CT (US)     68 / 70  
    You forgot the ')' after monastery.

    (build monastery)
    )

    But can you next time post your problem here:
    http://aok.heavengames.com/cgi-bin/forums/display.cgi?action=ct&f=28,8,,10

    The university section is not for general AI questions, only for questions regarding the articles themselves.
    posted 04-09-15 07:12 PM CT (US)     69 / 70  
    thank you!!!!!!!!!!!!
    i hate when its 1 thing
    because i usually can't see all my mistakes since i'm kind of dyslexic thanks again
    PS. i won't post here the next time i have a question like this
    posted 06-03-20 04:44 PM CT (US)     70 / 70  
    Where re the rest of the chapters? I am interested in making some of the soldiers immobile. I want them to move only if they see an enemy or when they are attacked.
    « Previous Page  1 2  Next Page »
    Age of Kings Heaven » Forums » The University » AI Scripting Guide: The World of AI Scripting (Approved)
    Top
    You must be logged in to post messages.
    Please login or register
    Hop to:    
    Age of Kings Heaven | HeavenGames