• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[GUI] Triggering AI for an RPG

Level 8
Joined
Jun 1, 2008
Messages
341
THE BASICS OF TRIGGERING REALISTIC AI IN GUI
WARNING - THIS IS A TUTORIAL OF DIFFICULTY 8/10 DO NOT ATTEMPT LIGHTLY
WORK IN PROGRESS




Section 1: The Theory
Artificial Intelligence is one of the single most complex elements of game computation, it requires many checks and calculations regarding real-time positions, facing angles,
damage/health calculations and many other variables.

This Tutorial is going to go over how we can make an efficient AI using GUI in the World Editor that will be able to interact with an RPG/ORPG as a professional human player (who happens to make no mistakes, ever) would.

So What should it do?

Basically, in a typical RPG/ORPG, a player will need to do the following:
  • Attack opponents
  • Follow a movement structure
  • Cast spells
  • Buy new items/abilities
  • Use provided methods of transportation
  • Collect gold
  • Interact with other players
Sidenote
For obvious reasons i.e. so that the AI doesn't actually do any hard work for the players or alternatively so that the AI doesn't steal the players job, I have chosen to leave Completing Quests out of the list.
How can we go about resolving each of these problems using GUI?
Believe it or not its actually really quite simple; lets go through the list and look at what the possible solutions for each scenario might be:

Attacking Opponents
To make a computer controlled hero attack we need to check for nearby enemies, we also need to insure that the hero does not openly enter a fight with a foolish amount of health or mana. It's important to include in our attacking triggers some sort of a retreat option for when health is too low to continue safely.

To make our hero AI somewhat even more professional we should try to make sure it does not enter into stupid fights, for example where the opposition has 10x the hero's health, but we must also take into consideration the abilities the hero has.

Sidenote
Attacking is one of the more difficult problems with GUI AI however when thought out right and executed nicely, it can really enhance the fun factor and challange in a game.
Movement Structure
It doesn't take much effort to make a functioning movement system in GUI, the trick is to make sure its not buggy. Sure just about anyone can make a hero go from one location to the other at certain times in the game, when certain conditions are true. However it is such an enhancement when the movement isn't stopped bacause the hero encountered an enemy on the way or something like that.

For movement systems i generally will link my attack trigger in with some basic movement or vice versa to optimize. This also gives the advantage of being able to detect when the hero should not move due to obsticles etc..

A problem that is almost always encountered, is that destructables or doodads will often block the path and of course doodads are undetectable via GUI. It doesn't matter so much with destructables and it can actually add to the game experience if the AI actually destroy inanimate objects such as tree's gates etc..
Using Spells/Abilities
Obviously and classically; Abilities and Spells are usually linked with attacking triggers. This makes the most sense as they will generally be used in combat.

However not all spells are indeed used in combat, some, i.e. healing spells are used afterwards, or others such as an adrenaline spell, i.e. roar are used at the begining of a battle or indeed just as a method of moving around the map faster.

So Spells are not contained in any single trigger but should be distributed among the attack and movement triggers. However it is also wise to have a trigger devoted only to spell useage, for spells like healing for example when a hero's health drops below a persentage boundary, similarly with escapist spells like blink.
Purchasing Attributes
Although not all RPG's involve purchasing skills/attributes, its something to bare in mind. A computer player cannot be ordered to buy an item from a shop, it must be totally triggered from the payment to the item creation to the adding of skills.

It depends really on what kind of purchasing system you have, for example a dialog system is a big No! In fact dialogs just look ugly and generally should not be used in RPGS or in my oppinion any maps. However a favoured method that also makes AI easier to provide for is that of the buying items that are individually triggered to a spell.
Using Transportation
This is perhaps the most simple and yet most complex to understand for those new th the ideaology. All that needs to be achieved in this problem is to get from one point to another. However if there in no route that will provide passage to the location then other transpotation is obviously needed. Its up to us to insure the hero knows when to use transpotation, and which to use.
Sidenote
To make sure its obvious; by transportation methods i mean triggered routes that will allow a player to get from one unreachable spot to another. For example a teleport system or a triggered train/aircraft system that can move your hero.
Particularly on large open maps with different islands or cliff levels the algorithms behind checking path mapping are particularly important to understand. This will be a big topic and difficult for many to understand but it will be explained later in full.
Earning Gold/Income
Very basic idea and implementation, however there are many ways to allow a computer player to gain gold. A periodic income, Orders to slay creeps for a bouty or even actaully sending the hero on a quest and giving rewards, such as items which can also be sold for more gold.
Sidenote
Referring to what i said earlier, in this tutorial i will not be showing how to send the AI on quests as that skill should come to you from everything else i'm showing. Also its not somehting i think should be done on a personal preferance level.
Player Interaction
You may have figure that this is indeed the most difficult problem but the idea behind getting it to work is to provide the players more oppertunities to interact with the AI giving the illusion of a more interactive AI. Also commonly AI's are given phrases that they can use to ask the players for help depending on their circumstances, i.e. low health, low gold etc..

Sidenote
To solve this problem you need to think creativly about things that players would normally do and incorporate the same things but for a preset AI.

Section 2: Initialisation
This is where the fun begins.
So first things first and as you should have guessed by the section name this is the part of the tutorial where we will be setting up things that should be done either at the start of a relevent event or at map initialisation.

Lets jump straight in then:
What is it we're going to do first?
The very first thing we need to do is to set up the AI players detection. This is a pretty simple task and can be done in a numerous amount of ways, however i have shown only one, of which i have found to be most reliable and simple.

In my example i have chosen to use 10 players leaving one (player brown) for creeps and a second (Dark Green) for neutral units, i.e villagers etc.. We will see why this is important later. Just know that 10 is always a good number for players in RPG's. You will also notice i have used some Global Variables as listed below, insure you declare these variables before you attempt to enter the triggers.

Player GroupsIntegers
Easy AITempInteger
Normal AI
Insane AI

  • AI Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (TempInteger1) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • ((Player((TempInteger1))) controller) Equal to Computer
                      • ((Player((TempInteger1))) slot status) Equal to Is unused
                      • ((Player((TempInteger1))) controller) Equal to None
                  • (Player((TempInteger1))) Not equal to Player 11 (Dark Green)
                  • (Player((TempInteger1))) Not equal to Player 12 (Brown)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Melee AI of (Player((TempInteger1))) Equal to Easy AI
                • Then - Actions
                  • Player Group - Add (Player((TempInteger1))) to ComputerPlayersEasy
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Melee AI of (Player((TempInteger1))) Equal to Insane AI
                    • Then - Actions
                      • Player Group - Add (Player((TempInteger1))) to ComputerPlayersInsane
                    • Else - Actions
                      • Player Group - Add (Player((TempInteger1))) to ComputerPlayersNormal
            • Else - Actions
The above initialisation trigger should give you the basic understanding of getting an AI to actually be counted as an AI. If the AI is not determined upon map initialisation then problems will occur.

So as can be seen we have run checks for each of the players using an integer count as (All Players) can sometimes not pick up the targets we might want to include. The checks include, if the player is simply not playing, i.e the slot was closed. It also includes, if the player has been assigned a difficulty computer setting or if the player is not Brown or Dark Green.

You should also notice that there have been checks to decide which groups to put the players in. If the player was not given a difficulty in the lobby room, then it will come under the else catagory and thus will be assigned a difficulty of Normal.

So now that we have the AI we can refer to it using the player groups to find its difficulty setting.

FEEL FREE TO LOOK OVER THE TUTORIAL SO FAR SUGGESTING IMPROVEMENTS AND CHECKING FOR MISTAKES ALTHOUGH I WILL BE CHECKING TOO FEEDBACK ON THE CURRENT STAGES WILL ALSO BE GREATLY APPRECIATED, BOTH GOOD AND BAD
 
Last edited:
Level 2
Joined
Aug 15, 2009
Messages
13
I like that someone is writing about AI. GJ and finish it as soon as possible :)
 
Level 8
Joined
Jun 1, 2008
Messages
341
I appologise for the delay in progress, school is killing me whilst my band has just released our first album so things have been hectic.
MortAr- by a realistic AI I mean one that will have the illusion of being an actual player, this includes player chat, irratic and spontaneous decisions and a number of other features. Rather than this being a coding tutorial, this page is more based on theory and ideas that can be transferred into other game types however I plan to upload a number of maps I made a while back all with different AI but all equally great maps to play due to the AI.
 
I'll leave this in a GY for a week, just let me know if you are willing to update it eventually. You don't have to be rushed to update it though, just notify me whether or not you can update it.

Nice tutorial, but unifinished. It will be graveyarded in a week if I receive no notification.

~Graveyarded, maker inactive. It's a shame, we could've gotten a pretty quality AI tutorial.
 
Last edited:
Top