|You must be logged in to post messages.
Please login or register
AI and RM Scripting
|Topic Subject:||A Newbie's Guide To AI Scripting|
|« Previous Page 1 ··· 4 5 6 7 Next Page »|
posted 02-01-03 04:23 PM EDT (US)
Welcome to my article about AI Scripting. If you want to know what AI
scripting is, or how to do it, you've come to the right place! This guide
will teach you the basic principles of creating AI scripts, and some more
advanced techniques to improve your abilities. This guide was made with the
intent of teaching people how to make AI for scenaio design purposes, but
hopefully everybody will be able to make use of it! Happy scripting!
Before I get underway with my guide, you'll probably want to
know what the topic at hand is all about. What is AI scripting all about?
Well, AI stands for
means methods that a computer uses to simulate thought. It tells it how to
make decisions based on your interactions, and what to do in certain
situations. Almost every time you make your computer do something, it is
What form does it take?
The AI that we will be dealing with in this guide is merely a set of
instructions, typed into a text editor, and used in certain ways to create
effects. That's all you will need to create AI, a text editor (I recommend
NotePad if you are using Windows).
Don't worry if you didn't quite take all that in just yet. AI is a tricky
subject. Here's what we have learned so far:
Well, at least you know what AI is now. It is used differently
with all things, and you'll probably we itching to find out what it can be
made to do in-game.
In Star Wars: Galactic Battlegrounds, you can create custom AI scripts or
edit existing scripts to edit how the computer plays in-game, i.e. its
stategy. The computer has a default AI script built into it that tells it
how to play, but creating your own script will change that. Do you want the
computer to rush faster? Do you want it to be more agressive? AI scripting
can make that happen. It can also be used in conjunction with the scenario
editor, and interact with triggers to create powerful effects in-game. AI
for SWGB is a ver powerful tool
What you should understand by now:
It's time to learn how you put these scripts into the game, so
you're all set for when you can create them yourself. It's actually quite
simple to put a created script into effect in the game, but it's a step that
many beginners stumble over for some reason
Right, to get a script into the game, you need a script
understand this yet, it's just to show you an example of a custom script in
a game. First, open up NotePad (I always use it, but if you don't have it
for some reason, a simple, easy to use text editor is the best). Then,
copy/paste the following into your new document:
That is the script we will use for now. I'll explain what it
Right, now you have your script, you need to save it. However, AI scripts
cannot just be saved as regular text files. You can try it, but it won't
work! We need to save it as a .per file.
What is a .per file?
For the game to understand the script, it needs to be a .per file. If it
isn't, the computer will skip over it and won't think it's a script.
How do you make it into a .per file?
That is easy. When you save your notepad file, save it as myfirstai.per, and
set the file type to "all files." Of course it doesn't have to be
myfirsai.per, it can be immobile.per, agressive.per, bigbuttocks.per, or
absolutely anything you choose, as long as it is something with .per on the
end. The name you give it now will be its name in the game. For now, save it
Where do I save it to?
You save your .per file into your SWGB/Game/AI folder. If you don't save it
there, it won't work
You've got your .per file and saved it to the right directory, but there's
one more step that you need to take before the computer will recognise the
AI script in-game. This step, however, is much easier. Open up NotePad and
create a new document. Then, without typing anything, save it as
myfirstai.ai. If you saved your .per file under a different name to
myfirstai, then just save the .ai file under the same name as that, instead.
They must have the same name apart from the .ai and .per endings. Save the
.ai file to the same directory as you did the .per file (SWGB/Game/AI). The
.ai file doesn't at all affect the script, it just tells the computer that
there should be a script called samenameasdotaifile.per in the AI folder.
If you have follwed these steps correctly, your new AI will be all ready for
you to use. To test it, run SWGB. Go to the screen where you configure your
random map settings, and for Player 1, under name, set it to myfirstai.
Then, start a random map, with any settings. Upon entering the game, you
should constantly receive chat messages saying "My first AI Script." If you
do, it worked. If you get an error message, or it doesn't give you chat
messages, then you've done something wrong. Go back and double check all of
the instructions I gave you.
Summary of what you now know:
So, now you know what an AI script is, and how to install a
custom script, but you don't know how to write them yet
tutorial will teach you just that - how to write AI scripts.
Let's start by defining a rule. An AI script is made up of
many rules that tell the computer how to make decisions. They basically
programming experience, that is a simple if-then statement.
Here is how a rule is layed out:
Of course, this isn't a valid rule, as where it says fact and
action, you must replace the text with valid facts and actions (I'll go over
those later). This is just to show you how a rule is set out. The
fact and the beginning of the action(s), and the
that into your mind now, and you won't go far wrong. Everything behind the
type whatever you like after a comment, and you won't get errors. You don't
have to have them, but they are convenient.
Now let's look at a valid rule. We'll use the one you used in your first
For now, I'll tell you that the fact,
myself saying "My first AI script")
Now, try and guess what this rule does. Highlight the below text to check
If you have more than 0 food (the fact), you will recieve a chat message
from yourself saying "My first AI script" (action)..
Did you get it right? Good
Well, an AI script is made up of almost all rules, so you're not far off
being able to write your own scripts
write facts and actions.
Summary so far for this chapter:
You know what facts are and how they fit into a rule, you just
need to learn how to write them.
Facts are generally layed out like so:
The game stat is something in the game which can be recorded and has a
value. For example,
general rule, all game stats have a dash (-) for spaces. There is a list of
all available game stats below.
The rel-op (standing for Relative-Operator) is the method used to compare
the game stat with the value. These are the rel-ops:
!= (not equal to)
The value could be anything fitting to the game stat. For example, the game
tech-level-3, or tech-level-4. Just use whatever applies. In most cases,
it is a number.
So, here are some examples of complete, valid facts:
Of course, there are some facts which are exceptions to the
needs no rel-op or value. The fact
a value of a building. For example,
There are also the facts
always true, and the False fact is always false (duh :)).
Rules can also have more than one fact. It would be set out like
If you have more than one fact in a rule, all facts must be
true before the action takes place.
Summary of chapter so far:
Right, now you know how to create facts, here's a list of
different facts you can use: