Gw Temp


Tutorial - 'Territorial patrollers' by Awesome

An item about RPGMaker 2000 posted on


How to creat an event in which the enemy will run after the hero when he comes within a certain range


Intro: I actually posted this up to help someone in the forums, but I received some good comments about it, so I decided to make a tutorial out of it.
Basically, when you step within a couple of pixels of the enemy (I have it for 2 pixels), he will start following you.
Couple this with my 'visible enemies' tutorial ;) This is just for the enemy following you, not the actual combat.

Knowledge You need: Forks, X/Y Coordinates, Variables.

Lets get this tutorial started:

First of all create an event for your enemy, and have him walking in random directions. Make this event PARALLEL PROCESS, this is so it will always be trying to check if the hero is within range.

Now, create 2 variables, set them to the heros X and Y position.
Variable Ch[0001:HeroX]Set,Hero X pos
Variable Ch[0002:HeroY]Set,Hero Y pos

Now do the same for the enemy, (except use different variables), so:

Variable Ch[0003:EnemyX]Set,Thisevent X pos
Variable Ch[0004:EnemyY]Set,Thisevent Y pos

Now that we have the X and Y coordinates for both the hero and enemy, we must find the distance between them. How? We minus them. But we have store this into a variable. Since we cant do 0001-0003 stored into 0005, we must first make a copy of the heros X and Y. So...

Variable Ch[0005:Xdistance]Set,Var[0001]
Variable Ch[0006:Ydistance]Set,Var[0002]

Now, we have our heroes X and Y variables, all we need to do is take away the enemies X and Y, to find the distance between the 2.

Variable Ch[0005:Xdistance]-,Var[0003]
Variable Ch[0006:Ydistance]-,Var[0004]

Ok, now Xdistance and Ydistance are the distance between the hero and enemey respectivley.
Ok, now depending on how close the hero has to be, you alter this bit. But basically we do a fork condition to see how many pixels away he is

Fork Optn:Varb[0005:Xdistance]--2above (thats minus 2)
Fork Optn:Varb[0005:Xdistance]-2less (normal 2 ;))
Fork Optn:Varb[0006:Ydistance]--2above
Fork Optn:Varb[0006:Ydistance]-2less
Change switch [0001:enemy follow]-ON Set

What we've done, is if the enemy is 2 or less pixels in front or behind (behind is the negative), or 2 or less pixels to the left/right (left is negative) then a switch will be set.
Now, we need a new page for this switch. The conditions for this new page are that the switch 0001:enemy follow is on.
Now, in this new page, we have the enemy's route set to follow hero and repeat action, with speed/frequency decided by you.

This is as far as this tutorial goes ;) For the rest of the coding for the enemy (the battle and the enemy then dissapearing) checkout my 'visible enemies' tutorial on (isnt up at time of writing, but should be soon), or goto my site