/======================================================\ < C A T E R P I L L A R F A Q B Y : D R A K U L > \======================================================/ v e r s i o n 1 . 0 Note: This FAQ requires prior knowledge of RM2K and it's event scripting language. I will be using specific elements including variables, fork conditions, and cycles. Please be sure you know the basic concepts of events and event commands before you attempt to follow my examples. What is this FAQ about? ----------------------- This FAQ will explain how to create a group of NPCs events that will play follow the leader with your main character. These NPCs can be used to visually represent other members of your party, or just about whatever you want. Why did you write this? ----------------------- Well that's a simple one. I liked the way RPG Maker 95 had the members of your party following the lead character. In RPG Maker 2000 when a character joined your party, well he kinda just disappeared, like he jumped into the main heros pocket or something. There is a simple way to add just one following character, but it doesn't work well when you add a third or fourth NPC. So I had to figure out a better way and this is that way. Getting the basic idea. ----------------------- To better understand the techniques I will be showing you, you should first take a look at these five steps. They are the basic method for the caterpillar scheme: 1. Determine Leader's Current X,Y Location 2. Determine NPC's Current X,Y Location 3. Determine Leader's Relative Location to the NPC 4. Move the NPC Left, Right, Up, or Down according to the Leader's relative location. 5. Repeat We need some variables! ----------------------- The first thing we are going to want to do is create a set of variables that will hold the leader's cartesian values. (i.e. X and Y coordinates). For this example the main hero will be our leader. Create two variables HERO-X and HERO-Y that will hold his X and Y coordinates respectively. We'll start out with a single NPC follower, so lets create a set for him too, call them NPC1-X and NPC1-Y. Adding the first event. ----------------------- OK, now that we have our variables all set its time to put them to use. After you have set your hero's start position on the map, create an event on one of the adjacent squares and name it NPC1. Leave all the Event Conditions blank and set the character graphic to whatever graphic you wish. In the Movement Type box select Stay Still (all movement will be determined through a cycle in the Event Commands window but we'll get to that). Make sure that you set Event Start Condition to Parallel Process and set the Priority Type to Common Char Above. The Movement Speed must match the speed your leader is set to, if you have not changed the default setting for your hero this will be Fast(Standard). For now you can set the Animation Type to Common/Without Stepping, but it can be set to whatever best suits your NPC needs. Creating the first NPC. ----------------------- OK, now we get to the hard part. I will try to step though the code slowly and explain each step. First thing we need to do is create a loop and throttle it, otherwise the loop will just run as fast as it possibly can, and that will be hell on your processor. So add a cycle event to the window and inside of the cycle event put a wait event of .1 which will look something like this: <>Cycle <>Wait 0.1s. <> :End Cycle <> Now that we have our loop setup, we need to get our hero's X,Y coordinates and store them in the proper variables. To do this we will use the Change Variable event. Insert this event directly below the wait event then set the following on the Variable Management Dialog. Create Variable must be set to One and 0001:HERO-X, Operation should be set to Set , and Operand should use the Charac option with the fields Hero and X Coordinate. When you click OK you should end up with something like this: <>Cycle <>Wait 0.1s. <>Variable Op:[0001:HERO-X] Set, Hero X Pos <> :End Cycle <> Now create another Change Variable event, and set it up to record the hero's Y coordinate. And then create two events to record NPC1's X and Y coordinates. After you finish you should see this: <>Cycle <>Wait 0.1s. <>Variable Op:[0001:HERO-X] Set, Hero X Pos <>Variable Op:[0002:HERO-Y] Set, Hero Y Pos <>Variable Op:[0003:NPC1-X] Set, NPC1 X Pos <>Variable Op:[0004:NPC1-Y] Set, NPC1 Y Pos <> :End Cycle <> At this point we have the basic update position code done. This loop will track the positions of the party leader and this one NPC follower. We will now need to determine where our leader is in relation to this NPC. So that we can move this NPC in the correct direction. Let's start out looking to the north of the NPC. To do this we will have to create a Fork Condition (which is basically an IF statement). Add a Fork Condition below the last Variable Change and set it to a variable condition of 0002:Hero-Y. We now want to use the variable NPC1-Y as a comparison value. To do this, set the check value to variable and 0004:NPC1-Y. Then select a comparison value of smaller. You'll end up with this: <>Cycle <>Wait 0.1s. <>Variable Op:[0001:HERO-X] Set, Hero X Pos <>Variable Op:[0002:HERO-Y] Set, Hero Y Pos <>Variable Op:[0003:NPC1-X] Set, NPC1 X Pos <>Variable Op:[0004:NPC1-Y] Set, NPC1 Y Pos <>Fork Optn:Varbl[0002:HERO-Y]-V[0004]Small than <> :Excepting Case <> :End Case <> :End Cycle <> OK that's great so far, but we need to set an action based on this condition. In this case the action will be to move this NPC in the correct direction. To do this create a Set Chara Movement event in between the initial Fork Condition and it's Excepting Case. Set the Object Character to NPC1, set the Movement Frequency to 8, and insert "Step Up" into the Movement Route. Make sure that Repeat Action is set to OFF by unselecting it's check box. You should now see code similar to this: <>Cycle <>Wait 0.1s. <>Variable Op:[0001:HERO-X] Set, Hero X Pos <>Variable Op:[0002:HERO-Y] Set, Hero Y Pos <>Variable Op:[0003:NPC1-X] Set, NPC1 X Pos <>Variable Op:[0004:NPC1-Y] Set, NPC1 Y Pos <>Fork Optn:Varbl[0002:HERO-Y]-V[0004]Small than <> Set Chara's Movement: NPC1, Up <> :Excepting Case <> :End Case <> :End Cycle <> Now if this event determines that the main hero is north of NPC1, NPC1 will continue moving north until either the case becomes FALSE or it cannot move north any longer. Of course this event only covers one of four directions, but I'm sure by now you've gotten the hang of things and will be able to handle the rest of it from here on in. Just in case I wrote out the complete event listing for one NPC. Complete event listing. ----------------------- Below is a listing of what your code will look like in the Event Commands window. It may vary slightly depending upon the variable and event names you chose to use, but overall it should look very similar. I have added some comments in to clear up what's going on. They are denoted by <>Note: <>Cycle <>Note: <>Note: THROTTLE PAUSE <>Wait 0.1s. <>Note: <>Note: GET COORDINATES <>Variable Op:[0001:HERO-X] Set, Hero X Pos <>Variable Op:[0002:HERO-Y] Set, Hero Y Pos <>Variable Op:[0003:NPC1-X] Set, NPC1 X Pos <>Variable Op:[0004:NPC1-Y] Set, NPC1 Y Pos <>Note: <>Note: HANDLE CASE (NORTH) <>Fork Optn:Varbl[0002:HERO-Y]-V[0004]Small than <> Set Chara's Movement: NPC1, Up <> :Excepting Case <> :End Case <>Note: <>Note: HANDLE CASE (SOUTH) <>Fork Optn:Varbl[0002:HERO-Y]-V[0004]Large than <> Set Chara's Movement: NPC1, Down <> :Excepting Case <> :End Case <>Note: <>Note: HANDLE CASE (EAST) <>Fork Optn:Varbl[0001:HERO-X]-V[0003]Large than <> Set Chara's Movement: NPC1, Right <> :Excepting Case <> :End Case <>Note: <>Note: HANDLE CASE (WEST) <>Fork Optn:Varbl[0001:HERO-X]-V[0003]Small than <> Set Chara's Movement: NPC1, Left <> :Excepting Case <> :End Case <> :End Cycle <> Adding sequential NPCs. ----------------------- If you were able to follow the above steps, this should be quite simple. All you need to do is create a new event for each NPC and reference the coordinates of the NPC in front of it, rather than the hero. For instance, NPC1 referenced the leader's X and Y position, well just treat NPC1 as the leader for NPC2, and NPC2 as the leader for NPC3 and so on until you finish. Keep in mind that each new NPC will also need a new set of variables to track it's own position. The Slip Through event. ----------------------- As you may have noticed the initial script for creating an NPC follower has some limitations. You can't back track in certain narrow areas and it is possible for your main hero to become entirely trapped in other areas. This is where a Slip Through event comes in handy. Simply adding two extra events in each Set Chara Movement can prevent such errors. Just enclose the movements with a Start Slip Through and a End Slip Through event, like this: Start Slip Through Step Up End Slip Through it's just that easy. Do it for each Set Chara Movement and you will gain 100% freedom of movement. The only draw back is that when you stop moving all the NPC followers overlap or rather "underlap" onto your main hero's tile. This will leave your hero visible on top, below him will be the NPC1 then NPC2 and so on. When you start to move they will line up behind you and follow as they normally would. I'll work on a more visually pleasing Slip Through, but for now this method seems to handle lot of the little errors that we've seen pop up without the Slip Through added in. Things to keep in mind. ----------------------- 1. This code is in no way perfect. In fact there are still a few glitches which still need to be addressed. If you need any help or come across any problems please let me know. I'll try my best to help out and correct them. 2. When moving to a new map, you will need to recreate all the NPC followers that were on the previous map. Simply copy and paste them into the new map. However make sure you paste them adjacent to the teleport event. That way they will continue to follow directly behind you. Don't forget you'll have to use switches to place the NPCs at various locations if you have more than one teleport on map. 3. If you plan to use this technique to implement a follow scheme for party members that may or may not be in your party at the time you enter the map, it might be useful to set the "Hero Need" event condition for each member. 4. The leader does not need to be human controlled. It can very well be another NPC leading the group. Very useful when you want to split your party up or to create a NPC with random movements that has something following him. A boy and his pet dog for instance. ^v^ ^v^ ^v^ Drakul@MyEZMail.com