Gw Temp


Tutorial - 'ABS Enemy AI - Part 1' by Dimensionwyrm

An item about RPGMaker 2000 posted on


Another amazing tutorial by Lunchman, this time about programming enemy intelligence for ABses.


In this tutorial series I will explain how to program enemy AI for an ABS and tell you how to make a basic ABS. I will also be implementing a basic vision system later. In this part I will give you the basic ABS and programming a simple three-phase AI.

SWITCHES: "attacking", "Battle mode", "Enemy 1 dead"
VARIABLES: "Hero X/Y", "enemy X/Y", "enemy 1 HP", "Attack"
KNOWLEDGE OF: Moderate overall knowledge of RM2K, an attack battle animation for all four directions.

Making the Basic ABS


1)Make a common event , parrallel process. Start by setting the variable "attack" to zero. Make an enter password for the descision key or shift key in 2k3(I will explain it using 2k in this tutorial).Now make a fork condition to check if that variable is five.Here is the code:
<>variable ch:[0001:attack]set,0
<>enter passowrd:[0001:attack]
<>FORK Optn:varbl[0001:attack]-5

2)Within that make a fork condition to check if the hero is facing up. Within the branch case have it turn on the switch "attacking" and then show the battle animation for attacking up, no wait. In the else case repeat this except for right, etc. Then have it memorize the hero's position with variables. Lower Y by 1 for up, and so on.(+1x fir right, +1Y for down, -1x for left) Wait 0.2 seconds then shut off the attacking switch.
Here is the code as of now:
<>variable ch:[0001:attack]set,0
<>enter passowrd:[0001:attack]
<>FORK Optn:varbl[0001:attack]-5
<>FORK Optn:Hero-Up face direct
<>Change Switch:[0001:attacking]-ON set
<>Show Battle Anim:Hit UP, Hero
<>Variable Ch:[0002:Hero X]Set, Hero X pos.
<>Variable Ch:[0003:Hero Y]Set, Hero Y pos.
<>Variable Ch:[0003:Hero Y]-, 1
: ELSE case
:END case
:END case
Repeat it for each facing.
Now that the common event is gone time to make the enemy.


1)Make a simple map. 20x15 and fill it with grass for now. Now make the enemy and name it ENEMY 1. Have page 1 set to collision with hero. Don't set any preconditions. This is phase 1. Make its movement pattern that it charges at the hero. In the script flash the character, play a sound effect, and damage the hero. This page is simple so I won't give seperate script. Make page 2, or phase two. Make its preconditions that the variable "enemy 1 HP" is more than 15. Have its pattern custom, and have it move back a few spaces, then rush in and charge at the hero. The script is the same. Make a third page, or phase 3. Have its preconditions that the variaqble "Enemy 1 HP" is more than 30, or its last and strongest phase. If have its move ment pattern that it reduces transparency then rushes toward the character, runs to the side, then charges again. Make the damagge script do slightly more damage.
2)Make a fourth page. Have its precondition that it collides with you when the switch "attacking" is on. Memorize the enemy's place using the "enemy X" and "Enemy Y" variables. Now make two fork conditions in one another to check if the Hero X and Hero Y variables are equal to the Enemy X and Enemy Y variables. In the branch case for the second one have it turn on the damage the enemy but instead of lowering its health INCREASE it. Following that make a fork to check if the variable enemy HP is (Insert how high you want its HP to be here). In the branch case have it kill the enemy by playing a death animation then turn on the switch "Enemy one dead". In the else case have it knock back the enemy. Here is the code:
<>Variable Ch:[0004:Enemy X]set, Enemy X pos.
<>Variable Ch:[0005:Enemy Y]set, Enemy Y pos.
<>FORK Optn:Varbl[0002:Hero X]-V[0004]Equivl
<>FORK Optn:Varbl[0003:Hero Y]-V[0005]Equivl
<>Flash Character...: this event,0.5 sec.
<>Play SE: Damage1
<>Variable Ch:[0006:Enemy 1 HP]+, 1
<>FORK Optn:Varbl[0006:Enemy 1 HP]-35
<>Show Battle Anim:Death, Enemy 1
<>Switch Oper:[0003:Enemy 1 Dead]-ON SET
<>Move Event...: This event, Move speed up, Escape from...
:END case
:END case
3)Make a page 5. It doesn't move or anything, just a blank graphic with the start condition being the switch "Enemy 1 dead" is on.

There you go! Now you have a simple ABS and enemy AI. If I left anything out leave it in a comment.