Building an AI
Tutorial for Gen
|
|
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"
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"
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"
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"
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"
TYPE: [nsAD][ENH]
NAME: "###_Set Skillset 2"
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"
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"
Simply add pairs of these for all your offensive firing powers. Things like artillery, carpet bombs, stuff like that.
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
TYPE: [nsAD][ENH]
NAME: "###_Set Skillset 2"
Code |
|
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 |
|
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 |
|
Simply add pairs of these for all your offensive firing powers. Things like artillery, carpet bombs, stuff like that.