Event Position Locking
 | submitted by ExaltedLegions on Mon Apr 07, 2008 10:32 pm This tutorial will teach you how to lock the position of events so that when you return to the map, it is in the same spot you left it in. |
Intro…
This may not seem like something that most would deem “important”, but I’m sure not everyone knows how to do this. Most maps we create have events moving around. That’s pretty much standard. However, isn’t it pesky when we leave the map and enter it again only to find the events restart in the same exact position every time? This tutorial will teach you how to lock the event’s position so that when you return to the map, it is in the spot you left it in. One use for this that comes to mind is a room with a switch. Ex: You put a box on the switch, the switch activates, and a cave opens. When you leave the map and return, the box isn’t on the switch anymore! Let’s remedy that!
Note: This tutorial doubles as a “Lets Learn Switch Activations” too (not the coding switches either).
Tutorial: Event Position Locking
Compatibility: RM2k/RM2k3/RMXP
Coding Difficulty: 2/5
Basic Knowledge: switches, variables, change event positions, fork conditions
Customizability: 4/5
Required Variables/Switches:
Create four variables:
xxxx: Box_X
xxxx: Box_Y
xxxx: Target_X
xxxx: Target_Y
Literary Terms (as used in this tutorial):
SE: Sound Effect (RPG Maker XP)
Frame: 20 Frames = 1 Second (RPG Maker XP)
Event Position Locking:
We need to start by creating three events:
1st Event: “Target Switch”, Push Key, Character Graphic of a switch that a box can go on, passing.
2nd Event: “Box”, On Hero Touch, Character Graphic of a box, fixed direction.
3rd Event: “Event Position Locking”, Parallel Process, No Character Graphic.
We can now skip the 1st event because it requires no coding. That leaves us with moving the box. Go to the 2nd event (Box) and create four fork conditions for each direction the hero can face (all within the next one’s else case). In each fork condition perform a move event, this event, direction the hero is facing. It should look like:
[Code]:
<>Fork Condition: Hero is direction Down
<>Move Event: : This Event
: : <>Move Down
<>
: Else Case
<>Fork Condition: Hero is direction Up
<>Move Event: : This Event
: : <>Move Up
<>
: Else Case
<>Fork Condition: Hero is direction Left
<>Move Event: : This Event
: : <>Move Left
<>
: Else Case
<>Fork Condition: Hero is direction Right
<>Move Event: : This Event
: : <>Move Right
<>
: Else Case
<>
: End
<>
: End
<>
: End
<>
: End
Now if the hero/heroine touches the box, it will move the direction he/she faces. If you really wanted to, you could do it so the hero/heroine could push, pull, etc. but I won’t get into that. If you really need explaining then just p.m. me and ask!
Finally, we arrive at our third event. Start off with a wait of 1 frame. Why we do this will be explained later. How will RPG Maker know when the box is on the switch? We record the (x , y) positions and continuously check them! Create four change variable codes. These will be used to store the position (x , y) of the Box and the (x , y) of the target the box must reach. So for example:
[Code]:
<>Change Variable: [xxxx: Box_X] set [Box] X Coordinate
Do that for (x , y) of the Box, and the (x , y) for the target. When you are done you should have:
[Code]:
<>Change Variable: [xxxx: Box_X] set [Box] X Coordinate
<>Change Variable: [xxxx: Box_Y] set [Box] Y Coordinate
<>Change Variable: [xxxx: Target_X] set [Target] X Coordinate
<>Change Variable: [xxxx: Target_Y] set [Target] Y Coordinate
Now create a fork condition (no else case) that checks if xxxx: Box_X is equal to xxxx: Target X. Inside this new fork, create another fork condition (no else case) that checks if xxxx: Box_Y is equal to xxxx: Target Y. Then in this new fork, turn on a switch, play music, whatever you want to happen when the box is on the switch.
[Code]:
<>Wait: 1 Frames
<>Change Variable: [xxxx: Box_X] set [Box] X Coordinate
<>Change Variable: [xxxx: Box_Y] set [Box] Y Coordinate
<>Change Variable: [xxxx: Target_X] set [Target] X Coordinate
<>Change Variable: [xxxx: Target_Y] set [Target] Y Coordinate
<>Fork Condition: Variable [xxxx: Box_X] same Variable [xxxx: Target_X]
<>Fork Condition: Variable [xxxx: Box_Y] same Variable [xxxx: Target_Y]
<>Play SE : ‘Cheering’, 80, 100
<>
: End
<>
: End
Okay, now that’s done, but what if the box is moved off the switch? Go back to the two fork conditions we just made and turn the else cases on. In these else cases, turn off the switch that was previously turned, or whatever you need to do to undo what you just did.
[Code]:
<>Wait: 1 Frames
<>Change Variable: [xxxx: Box_X] set [Box] X Coordinate
<>Change Variable: [xxxx: Box_Y] set [Box] Y Coordinate
<>Change Variable: [xxxx: Target_X] set [Target] X Coordinate
<>Change Variable: [xxxx: Target_Y] set [Target] Y Coordinate
<>Fork Condition: Variable [xxxx: Box_X] same Variable [xxxx: Target_X]
<>Fork Condition: Variable [xxxx: Box_Y] same Variable [xxxx: Target_Y]
<>Play SE : ‘Cheering’, 80, 100
<>
: Else Case
<>Stop SE :
<>
: End
<>
: Else Case
<>Stop SE :
<>
: End
You’re now all done! Just kidding. Now we focus on the event position locking. When on the map with the box, switch, etc. go to the Database => Common Event => and create your own. In the Common Event, create a change event position, box, by variables: xxxx: Box_X and xxxx: Box_Y.
[Code]:
<>Change Event Position : [Box], By Variables [Box_X][Box_Y]
That’s all you put in the common event. The only thing that goes into here is changing event positions to their respective variables. Add as many change event positions as you like, but take notice!
*Event ID’s vary by map. Try to keep events that get their position locked to share the same ID.
*If there are many Event ID’s you are locking in a certain map, give it it’s own common event because if you were to call it for maps with one or two being locked, it would glitch and try to lock them all.
Why a common event? Let’s see…
Now create another map with an area to teleport into this one. In the event, add:
[Code]:
<>Set Screen Tone : (-255,-255,-255,0) @0
<>Teleport : [Map w/ Box and Switch], [whatever (x , y) position the hero arrives at]
<>Call Common Event : Event Position Locking
<>Set Screen Tone : (0,0,0,0) @0
Let’s break it down. We set the screen black in 0 frames and then we teleport to the new map. We now call the common event, which, now that we’re on the right map, will move the box to its correct location. But if you enter the map again, then that other event begins processing and it’ll just reset the (x , y) right? It would, but we added that wait event that gives the common event enough time to process. We set the screen back to its original color in 0 frames and you’re done!
Editing Instructions:
Remember:
*Event ID’s vary by map. Try to keep events that get their position locked to share the same ID.
*If there are many Event ID’s you are locking in a certain map, give it it’s own common event because if you were to call it for maps with one or two being locked, it would glitch and try to lock them all.
*Change the box to whatever you want: NPC’s, Monsters, etc.
*A target is not always needed! Only if you’re doing switch activation do you use a target.
*Event Position Locking only requires the 2nd and 3rd Event. The 3rd Event only needs:
[Code]:
<>Wait: 1 Frames
<>Change Variable: [xxxx: Box_X] set [Box] X Coordinate
<>Change Variable: [xxxx: Box_Y] set [Box] Y Coordinate
Copy and paste these two change variables (editing as needed) for every other event you want to “lock”. You also need the teleport coding.
Summary:
We started by making our box able to move onto the switch. Then we added an event to check coordinates so we’d know if the box was on the switch. After that, we created two fork conditions to check if the box was right on the switch and if it was, hurray! Finally, we created a teleport event that used our common event allowing the box to be “locked” into position upon moving between maps.
Closing…
And now you’ve learned “Event Position Locking” and “Lets Learn Switch Activations”. This tutorial veers off some of the more “unknown” ones I do, but I felt like doing it so I did.
Next up, I’m going to add the second addition to my A.I. Pathfinding tutorials. I’m also working on creating an Auction House (with smart A.I. Bidders). It’s halfway done and was inspired by my recent playing of Final Fantasy IX. So, if you’ve been to the Auction House in Treno, you can expect something along the lines of that.
Problems? Comments? Suggestions?
P.M. me and I’ll try to help. Advice and criticism is welcome!
*However, don’t P.M. me with a question that I’ve already answered in the tutorial.*
—ExaltedLegions—
——An ExL Team Production——