Building an AI

Tutorial for Generals Gen

Avatar of Calamity_Jones

Calamity_Jones

Category: Code
Level: Expert
Created: Wednesday July 29, 2009 - 7:24
Updated: Sunday October 11, 2009 - 8:10
Views: 4592
Summary: A step by step guide to building an AI for your mod.
Rating
  • Staff-
  • Members-
  • Average-

0 votes

Page 1 2 3 4 5 6 7 8
Original Author: Calamity_Jones

Now we want our AI to build the rest of his base, or if you have very few buildings in your mod, you'll just want extras of what's already there.

You can do this with more prerequisites for example, perhaps set it to build the next few buildings once it has finished building 2 turrets. Or you can make the AI wait for a while. Personally I would not build anything else at this stage because your AI will be running out of money and will need to either start building units or try to find more cash.

What I have is this:

TYPE: [nsAD][N]
NAME: "###_N_Build Additional Structs"
              
Code

*** IF ***
    Counter 'CAD_MASTER' IS Equal To 3
*** THEN ***
Build a building of type '[Extra Building 1]'
Build a building of type '[Extra Building 1]'


Remember how our master counter increases? It uses a counter of how many teams of units have died. This means that the AI will wait until 6 attacks have failed before making any more buildings. This is handy because the AI might be able to catch the player unaware and score a quick victory. If not, it ups the ante. Simple but elegant!

Right, now we go the the folder called "###_Cash Supply". This is where the AI does it's dodgy dealings.

Add this script to start: (Action in Player/Set)

TYPE: [nsAD][ENH]
NAME: "###_Cash_Builder Bug Fix"
              
Code

*** IF ***
    True.
*** THEN ***
Player '<This Player>' gets $ 1200


Just set the money to whatever your building vehicle costs, or the cost of what the AI starts with, as it has to pay for it.

Now, you can make your AI do some cheating. Don't worry about it though, the AI isn't as smart as us humans, it needs a bit of help. The standard AI in Generals and ZH cheats like a bastard :p Generally this comes in the form of some large one-off cash bonuses at a certain time, or if the AI accomplishes something. You can also give it a constant supply of money. Here's how:

TYPE: [nsAD][NH]
NAME: "###_Cash_Warfactory Boost"
              
Code

*** IF ***
     Player '<This Player>' has Greater Than or Equal To 1 unit or structure of type '[Warfactory]'
*** THEN ***
Player '<This Player>' gets $ 5000


This is a one-off, and will give the AI 5000 as soon as it owns a warfactory. (If on Normal or Hard difficulty) If you set up some more things like this that might be activated in late game (i.e. by buildings it takes a while to get) you should set the evaluation to every 1 second.

To give the AI an uninterruptible constant cash supply, change the type to [nsAnd][N] and set the evaluation to once per second and set an amount for normal, and duplicate for hard. Basically, every second the AI will get whatever amount you have set. Simple, huh? You can of course give them money on easy too, but easy is supposed to be easy... no? :p

Right, now run to the "###_Generals Powers" folder and add this script: (Actions in Scripting/Timer)

TYPE: [nsAD][ENH]
NAME: "###_Set Skillset Determine Timers"
              
Code

*** IF ***
    True.
*** THEN ***
Set timer '###_Choose Skillset 1' to expire between 8.00 and 14.00 seconds.
Set timer '###_Choose Skillset 2' to expire between 8.00 and 14.00 seconds.


This script will set off two counters, and the one to expire first will choose the skillset that the AI uses with the next two scripts.

Now add these: (Condition in Scripting, Actions in Player/Set and Scripting/Script)

TYPE: [nsAD][ENH]
NAME: "###_Set Skillset 1"
              
Code

*** IF ***
    Timer 'CAD_Choose Skillset 1' has expired.
*** THEN ***
Player '<This Player>' uses skillset number 1 (1-5).
Disable Script '###_Set Skillset 2'.


TYPE: [nsAD][ENH]
NAME: "###_Set Skillset 2"
              
Code

*** IF ***
    Timer 'CAD_Choose Skillset 2' has expired.
*** THEN ***
Player '<This Player>' uses skillset number 2 (1-5).
Disable Script '###_Set Skillset 1'.


Of course, you're not limited to two, you can have up to 5 skillsets. These scripts in themselves will not fire Generals Powers though. You need some more to do that. For each generals power that is fired on a location, you'll have to add a pair of script like these: (Condition in Player/Special Power)

TYPE: [nsAnd][ENH]
NAME: ###_[Power] Ready"
              
Code

*** IF ***
     Player '<This Player>' is ready to fire Special power '[Power]'.
*** THEN ***
Enable Script '###_[Power] Fire'.


This one just checks to see if the power is ready for use. The second: (Action in Player/Special Power)

TYPE: [nsnand][ENH]
NAME: ###_[Power] Fire"
              
Code

*** IF ***
     Player '<This Player>' is ready to fire Special power '[Power]'.
*** THEN ***
Player '<This Player>' fire Special power '[Power]'
Enable Script '###_Artillery Ready'.
Disable Script '###_Artillery Fire'.


Simply add pairs of these for all your offensive firing powers. Things like artillery, carpet bombs, stuff like that.

Return to top