|
|
In this tutorial you will learn…
How to make a respawn system
How to set the map ID, player-x and player-y values to variables…
…and how to use them
Hi there! A little while ago, someone asked me how to create a system whereby after losing a battle, the player respawns at the last save point. At first, I
couldn't work out at all how to do this, but with a little poking around in the script editor, I have come up with a system that will hopefully enable you to
do this - and use the same commands for other things. So, let's get going!
For this system, you will need:
ê Three variables
ê A common event
ê A modified Scene_Gameover script (linked)
In this tutorial, as well as going through how to install and use this script system, I'm going to go through the workings of it so that anyone out there who is
a budding scripter (like me!) - or who just wants to know how it works - you'll be able to see the inner workings of it. There are also two ways of doing this
system: the first way is to make it so that the player respawns at the last point that they saved at - and the second is to respawn at a specified map location,
such as the last inn that they visited.
Okay, fisrt things first, we'll look at the method that respawns to a specified location - you're going to need
this modified script, so download that and stick it somewhere safe. Now, open up your project and go into the
script editor. Scroll through the script list until you find the Scene_Gameover script, somewhere near-ish to the bottom. In the script editing pane, highlight
everything, and press delete. Don't worry; I know what I'm doing! Now, open up the script that you downloaded, highlight everything, copy, and then paste into
the blank script pane. Okay? Now you should have a Scene_Gameover script looking like this:
Okay. Now, there's one more thing that you need to do before you test this. You'll notice that, if you scroll down, there is a section of the script where it
looks like this:
Now, I've spoken a bit about these values in the script, but for a more comprehensive guide, I'll go through them here as well. Basically,
$game_variables[x] is the syntax for accessing the in-game variables from within the script editor. So, for example,
if in-game, your first variable is 001: Random Weather, then it will use the random weather for the respawn map ID - which isn't quite what we want! So, what
you need to do set aside three blank variables for use with this script, and take a note of their numbers. These variables will be set in-game, from an event
such as speaking to an innkeeper, etc. I have made a sample system so that you can see what it might look like. Here are the events in my Innkeeper event:
As you can see from the variable commands, this system will set the respawn variables to being the player's current position. So, when the player reaches the
gameover screen, he will respawn to that point. If you want to know where the map ID and player X and Y variable values are, you'll find them near the bottom
of the control variable box:
And the player X and Y commands are just above…
Obviously, you can use other events to set these variables; just make sure that you set them before the player has a chance to get to the gameover screen,
otherwise the script will crash your game!
Okay, now, we need to make sure that the variable values fit with the script. Firstly, you need to take a note of the numbers of the variables that you have
used, and which number is which value. For me, the map ID is variable 5, the player X 6, and the player Y 7. So, open your script editor and go to the
Scene_Gameover script that we've pasted in. Scroll down to where you see the syntax that we pointed out earlier, with the variable names. Now, you need to
change the numbers in the square brackets so that the variable descriptions in the script match up with the variables that you've used in-game. So, I'll set
the first value to 5, because my map ID variable was in-game variable 5. Follow? My script would look like this:
You see how they match up? Okay, now we're ready to test our system! Of course, you can change the text in the message box to say whatever you like, but the
first command will always be respawn, the second return to title, and the last will be shutdown, unless you do a bit of scripting yourself.
Great! Now we've got that working, and you know how to change the respawn location using in-game variables, how do we set it so that the player respawns to the
last save point? Well, there are three ways to do this. Firstly, if you have a system whereby you have events as save points throughout your game, then you can
use the above method and just set the three variables every time the player saves. Your event might look something like this:
This will use the previous script to set the variables to the last save point.
The second method is to do a little modification of the script that runs when you save a game. Go to the script Scene_Save, and scroll down until you see the
syntax # Write save data. Underneath this, you need to add the following:
| CODE: |
|
$game_variables[MAPID] = $game_map.map_id
$game_variables[X] = $game_player.x
$game_variables[Y] = $game_player.y
|
But make sure that you change the MAPID, X and Y
letters to the numbers of the variables that you are using in your other script! This method allows the variables to be reset every time the game is saved, so
that the player will always respawn back to the last save point. However, you can also change the in-game variables in your events. Bear in mind, however, that
if the player saves the game after you have set the in-game variables, they will be reset to the last save point's values.
Your modified Scene_Save script should look like this:
The final method is just to use the other modified scripts that I have bundled with the script pack. Inside the .zip file, you will find a folder called
Respawn From Last Save. Inside this folder, there are three text files: Scene_Save.txt, Game_System.txt, and Scene_Gameover.txt. As you would with any other
scripts, just paste these whole text files over the ones in your game. This will allow you to respawn from the last place that you saved or loaded the game, and,
if you start a new game and get to the gameover screen, start from the very beginning point - without losing your progress.
Here is the complete script pack, ready for you to use:
And there we have it! A comrehensive respawning system. I hope you manage to get it to work for you. If you have any suggestions for improvements to this script,
any questions or problems, try dropping me a line on my Contact page. See you soon!
:: << Previous Tutorial ::
:: Home ::
:: Next Tutorial >> ::
|
|