banner



Rpg Maker Mv Pet System

This is going to be the showtime part of a serial on how to build a basic Tactical Battle System in rm2k3. It will include stuff how to deal with the health, some simple AI and more. In this role I'm going to show you how you can make your heroes (or whatever else y'all'd like) motion within a given range of tiles.

A tiny alert: this will presume at least intermediate feel with rm2k3, so if you lot're new to the engine and find this quite baffling, it's because this tutorial isn't suited for beginners. This tutorial volition require noesis of Pointers as well as basic agreement of how coordinates work among other things.

This is going to be a lengthy tutorial. If you just desire to look at the code you tin can do so by downloading the sample projection: Download

The tutorial is divided into these sections:

- How to approach the problem
- How to create a bones field for motility
- How to employ these fields to events
- How to expand on the move field to accept unlike terrain into consideration

How to approach the trouble

This department is purely theoretical and near how to recall virtually approaching custom systems in general and this one in specific. If y'all're only interested in the implementation you tin skip this part and continue to the next section.

This is a kind of system where yous but tin't just start coding without a plan of how it should piece of work. The kickoff thing you do when trying to create a organization like this is to effort to think of the requirements the system should fulfill, so requite some thought to what problems could ascend which makes this hard. So let'southward look at how a move system like this would commonly look. Something similar this, correct?

The yellow square marks the actor and the blue fields the possible locations it tin move to if it tin can movement iv tiles during it's move. And this shape looks relatively simple to recreate if you know a trivial about eventing. Heck, maybe it would be as simple as taking the coordinates of the start position, and then start moving the consequence around, subtracting it's new coordinates with the old ones, then multiplying any negative answer with -1 and add them together. That would allow the player to motion within the aforementioned pattern, and that should work... correct?

All the same if the crimson square marks an obstacle, then we would only want the player to only exist able to motility within the blue surface area, but with the above method you'd still be able to movement at the green area, since the coordinates would still want to create the shape, and simply just preventing the thespian to move onto obstacles won't be plenty. And thus we've located a problem which we need to handle. Ideally you desire to find think of all problems earlier you fifty-fifty beginning eventing. Ideally. Of grade, that's rarily how it will piece of work when you're creating custom systems and you shouldn't dwell too long on trying to recall of all possible bug which can occur, but you lot should try to think of equally many equally possible, so that y'all can consider them when trying to event a solution. This will generally pb to cleaner lawmaking which is easier to read and change if a trouble do occur. In rm2k3 this is likewise important in terms of organizing your variables properly, since all are global, and it's a pain to use them if they're scattered all over the array.

Then what we want for this event, is to show the possible tiles the hero can move to while keeping the obstacle trouble in mind. Since nosotros'll start with a basic version, that's all we'll be looking at for starts, and we'll expand on it afterwards.

To practise this, we could use events to "seek out" the possible tiles while they double as graphics besides, which is probably the most practical solution when physically showing where the player can movement. This gives rising to another trouble though. In rm2k3 we can't create new events at runtime, pregnant they will have to exist present at the map the game starts and with that in heed nosotros will have to think how far it maximally should exist possible to move, since this will make up one's mind how many events we'll need to have ready given a total free area. The formula for amount of tiles needed for a shape like that is given past:
f(n) = 2n(n + 1) + i
with northward existence the range in question. This means that for a range of 4 we'd need 41 events (if we include the tile on which the player is standing, which we will be doing afterwards on besides). This does nonetheless also mean that for a range of xx nosotros'd need as many as 841 events for the possibility of having a totally gratuitous surface area to move within.

841 is a pretty loftier number in terms of having that many events on the map, So we should probably consider having a considerably lower maximum. A maximum range of 6 requires upwardly to 85 events, and is the highest range we can get without needing more than 100 events, so we will be going for that in this tutorial. This is of course something yous can adapt yourself later on, the signal is just to be aware of the limitation decide where the limits should be set up.

Allow's head back to the idea of having the events "seek out" the possible tiles for movement. This could exist accomplished by doing several iterations where the issue tries to lay other events around itself if the range hasn't been "used upward" nevertheless. Nosotros could kickoff at the hero position, identify an event there which looks above, checks if there are any obstacles or ill terrain at that place or perhaps already an event which marks it possible to move there. If not, it volition place a new tile there and and then look to the right, so down, then left. And then the first iteration will exist done and you could reduce the range by 1, since now we have placed all the tiles you could move to with a range of 1. We'd then move onto the next iteration where we'd utilize the events we just spawned to spawn new events. One time we've let all those events tried to spawn in one case, nosotros'd accept completed the second iteration and take all possible tiles to move at with a range of two. And thus we keep to the next iteration, and so the next ane, until we've reached the maximum range. Commonly it takes a couple of tries to arrive at an thought like this (depending on how experienced one is), but one shouldn't be discouraged past ideas non working, and try to learn from them instead and so start over if it doesn't work out (maybe even inquire in the help section of the forum if you're actually stuck).

How to create a basic field for movement

Okay, and then we take an idea of what nosotros want the solution to practice, just how practice nosotros implement it in terms of event code? Well, nosotros tin start with the building blocks of the field which will exist used to brandish movement. They're going to consist of several pages which we volition be using for doing stuff to that specific event.

The first folio will look like this. Calling this page will return the coordinates of this issue to some temporary variables chosen Cell X and Cell Y. The keyword here is the utilize of "this". Past calling events directly we tin can control them more easily with variables. There is support for making variables signal at the coordinates of an outcome, just would require some other outcome to store all the coordinates by mitt into variables, and this would likewise arrive harder to tell which effect's coordinate is relevant for this particular case. In other words, the employ of "this" is a powerful tool we'll make much use of.

This is the second page which again makes use of "this" to move the event to a desired location, given past the same variables used in the previous page.

And this page causes a recursive similar behaviour. Information technology's called with a like call, and so calculation 1 to the Cell Ptr which decides which event to call by it's ID. The Cell Page Clear variable is set to 3 so that it e'er call this page. The event itself moves dorsum to an initial position, effectively removing it from the play surface area, before calling the adjacent of it's kind until reaching a designated "stop event" which is completely empty at page 3, making this chain of calls come to an end.

The above page is empty, and then that action key won't trigger any event script, and the two above that again are but for graphic representation. And that'southward how are events for the moving tiles will look. The good thing about them is that there's no special variable fix to any of them, meaning you can copy one time and paste as many as you want without having to fiddle with them further, which is especially good considering the potentially large amount of them nosotros'll be having when wanting to move longer than vi tiles during a turn.

Something important is that they all demand to form a consecutive sequence in terms of consequence ID's in society for united states to exist able to call them properly, and too for non making the chain of phone call events which resets their position go awry. Also, there's need for an empty upshot with 3 pages with the event ID following the last move tile, so that the clear concatenation will come up to an stop and not cease upwardly trying to phone call some non existing result page.

And at present we need to make use of these events. The idea is to identify an issue at the thespian location, which and so checks the tile to a higher place, then right, so below and finally left. If these tiles are free it'll spawn new motility events onto these, and we'll continue a new iteration. This means that the events will should exist spawning in the following order:

The different colours denote different iterations and the numbers at which point they are spawned starting at one, which is where the player will be located. Try to follow the sequence and make sure you understand why they are spawned in that society and endeavour to figure out how the sequence would go on for the next iteration.

At that place are two cardinal variables needed for producing this blueprint. One variable which points to the current event which is to spawn new events, and the variable which points to which event to spawn, based on the consequence ID's. In the sample lawmaking, variable 0022 Cell Ptr handles the current upshot tile, while 0021 Cell New handles which effect to spawn.

In the sample code, the ID of the first motility tile starts at two and continues to 89, with 90 being the "stopper issue". As thus, we get-go by setting both Cell Ptr and Cell New to ii, since this is the starting point. When then fix a variable Jail cell Check. This 1 marks at what ID Prison cell Ptr should exist to betoken that the current iteration is over. Since the get-go iteration start and cease at the showtime result, that is at effect ID ii, this is what we'll fix it at as initial value. If the Cell Ptr is at the same outcome as the one given in Cell Check, Cell Check volition have the value of Cell New at the end of spawning all events nearby that event, since Cell New will incorporate the ID of the concluding spawned issue.

Around at present, it volition probably be a bit difficult to keep track. If this is the case, so you lot should employ the grid higher up showing in what order they are spawned to help you agreement how this works. In the Filigree, Cell Cheque would offset have been 1, and then set to 5 since that's the last value Jail cell New had upon having spawned tiles at all neighbour spaces. So it would spawn events at all free tiles around #2, then #3 and such until #five, which is the aforementioned as Cell Cheque, and ways that it will updated over again, this fourth dimension to 13, since that's the electric current value of Cell New.

For each iteration, nosotros will subtract the Range variable with one, and every bit presently equally it reaches 0 the event ends. This is done by the branch right below characterization 1. The next stride is to recollect the coordinates of the current event. This is washed by calling on the event with Cell Ptr as ID and as variable Cell Folio Coordinate as page. Prison cell Page Coordinate is gear up to 1, which equals the page returning the coordinates of the current event. In one case this is washed it starts checking the tiles effectually it.

Remember that the coordinate system in a computer usually has a reversed y-centrality, meaning that subtracting by i to the y coordinate ways you'll go up. This is what nosotros desire, so we subtract the electric current y value by one, and then use the commands Shop Event ID and Shop Terrain ID to figure out if the tile is free. If the terrain = 1 and Cell ID = 0, that ways in that location'due south nothing continuing in your way then with that, we'll add 1 to Cell New and use it to phone call an effect with same ID and at page 2, which we recollect to change information technology'southward location to that given in Jail cell X and Y, which at this point is right above the current event.
Post-obit this, nosotros add 1 to both Cell 10 and Y to become the tile to the right and echo the process.

The just difference for the different directions is that nosotros accommodate the coordinates appropriately. At the end we bank check if Cell Ptr equals Cell Check as explained in a higher place, and set Cell Cheque to Jail cell New if so, likewise as reducing the range by one. At the end, we increase Jail cell Ptr by 1 in order to continue to the next event, and we and then get back to characterization 1, thus looping until the range is reduced to one. Something you'd might consider adding is an boosted co-operative which would ensure that Jail cell Ptr never goes above 89 due to some problems, which would probably stop in an error message.
In that location might not be any demand to, simply extra safety doesn't hurt, especially if something goes unnoticed and a player somehow manages to observe that bug. Peradventure calculation a message proverb something forth the lines of "something which shouldn't have happened occured at event xyz". (There is in fact 1 problems which can occur given the right circumstances with the current event. I challenge You to figure out what information technology is)

This is all we need to create a basic field for move. Adding a niggling event running on parallel process which checks for key input so calling this event volition create something like this:

Just remember that you volition have to set the Prison cell Range variable to a value likewise equally setting Cell X and Jail cell Y to the coordinates of the role player prior to calling the consequence.

How to utilise these fields to events

Now we tin can create a field assuasive us to move due north amount of tiles, but that's no adept unless we take some fashion of applying it to the events we want to movement. As such nosotros'll add together 2 events which will want to brand move. Alex and a Demon.

Over again, we make utilize of events pages and "this" for the sake of retrieving data nosotros may desire. Both Alex and the Demon are akin event wise, almost merely differing in terms of graphics. Folio 1 returns the coordinates, page 2 makes the issue walk i step in a direction given by a variable and the concluding picture sets the range for this event. Alex has been given the range of 5, while the Demon just has three. The last page is empty to prevent interference by triggering of action key at the upshot. Also notice that they are set to "above". This is for artful reasons making the hero, in the form of a cursor, announced below them.

Nosotros want to exist able to trigger their movement ranges upon clicking on them, and not otherwise, so we'll need an event which handles key input.

At first, nosotros await fundamental input from the histrion. One the action central is been pushed, the coordinates are stored into Select X and Select Y, which will recollect the original position, and nosotros and then store the event ID of that position. If there's no event in that location. Now nosotros'll demand 4 new variables. Marry ID Start, Ally ID End, Foe ID Start and Foe ID Cease. Ally ID Starting time will contain the everyman ID of the events which make upward the player events, and Ally ID Finish the highest. The Foe ID's works the aforementioned just for the Foe's. This means that also their ID's has to be arranged to form a sequent sequence. Scattering their ID'due south nearly will brand it considerably harder to check for their ID's, especially if there are many of them. If yous're unsure whether you might demand more than, just make infinite alee of time past creating some empty events working as placeholders. Also remember y'all'll be able to adjust the ID's whenever yous desire past variable operations.

If the position where you pressed the activity push at contained a playable movable issue, the Select coordinates volition be stored in Jail cell Coordinates in preparation for calling Create Motility Field. Nosotros also take two switches Enemy Motion and Player Movement. These control the colour of the move tiles. Blue for the Alex and cerise for the Demon. The Telephone call event in at that place calls the folio which sets the range variable. We'll use Select ID for to refer to the event, and another variable containing a constant equaling the page we want.

Later this, nosotros may call Create Motion Field, then nosotros call an event to handle moving the events almost and afterwards nosotros set Cell Ptr to 2 and calls it's Clear Page, and then that nosotros tin can remove all the move tiles subsequently having moved the event. Now permit's take a closer look at the event moving the the player (and demon) near:

At the top, I've set a switch on which prevents triggers a parallel procedure which prevents the hero from moving as long as the parallel procedure is active. This is followed by a key input which checks if the action button is being held down by not waiting for the key to be pressed, and goes to the next loop once it'south not held downward anymore. This is done then that there won't be a need to check the "wait until key is pressed" for the second central input too without instantly ending the event (since activity push has been set as trigger to terminate motion).

The reason why we'd want the wait for keypress to exist unchecked is to let for more soft movement of the events past not having to constantly press in the direction they wish to go. Once a management is pressed, information technology is stored in the variable Select Direction, and if y'all payed attention to page 2 in the Alex effect, you'd see that the directions it'd move at for the dissimilar values corresponds to the values retrieved by the key inputting process. The value is stored into another variable to allow for ease if the another case would take apply for moving the events past their consequence pages. In this example it would brand more sense to employ a temporary variable rather than using the key input variable again, though it would salvage united states of america one variable functioning in this particular instance.

Following this, nosotros adjust the coordinates of the events current position for it's management by a bunch of branches and then jump to a label below. When you have a lot of branches in a row like this while all the same having more code to execute after it, it would be beneficial to add together a characterization at the end of the branches and jump to it in one case one of the branches is taken since only i tin can be taken anyway in this instance.

After jumping to the characterization, we Store the event ID of that position and bank check if it equals an event ID higher than 0 and lower than ninety, pregnant that it'd be one of the movable tiles. This ensures that the event can't motility outside of it's move field. It's motility page (i.e. folio 2) is chosen making it move in the given direction, waits a niggling to preclude lag, so jumps dorsum to the top, making it loop until action is pressed. And thus the events tin motility freely to any of the positions inside their move field.

This IS a clumsy method for moving the events about, just it'south very simple. In the next tutorial, we'll be looking at an alternative method for moving the events about.

Expanding on the Move Field

The move field we have right now is very bones, and we might want terrain to make a departure in the same way as Advance Wars did, that is, making some areas crave more "steps" to cross than others. In this section we volition add woods, taking two steps to cross rather than merely one similar normal grass will. To do this, we'll have to modify our Create Motion Field event. The picture above illustrates how this works in action. And now we'll take a look at how information technology works behind the scenes.

For this system, nosotros tin can't simply rely on subtracting the range for each iteration, considering it volition vary depending on the terrain standing in the way, so we'll take to modify the event so that it takes into business relationship how many steps y'all'll have left at each of the events.

This graph basically illustrates how information technology would work. The Green cells signify woods and the numbers the corporeality of steps left from that tile. The cells with 0 are also tiles you lot'll be able to move to, they only mean that they have 0 range left to spawn more area for the actor to move onto. So with a solution like this, we'll need as many variables every bit the maximum corporeality of move tiles we can accept. In our example that would be effectually 88, though 100 sounds nicer, so in the sample projection variables 101 to 200 is set up bated for storing the range of left at the unlike tiles.

To deal with these we'll need 2 boosted pointers. Ane to retrieve the range left at the current tile, and one to store the range in the newly spawned tiles. Others than that the principle is nonetheless much the same.

As you lot might notice, Prison cell Check is at present gone, since it no longer serves any purpose.
Instead we now gear up Cell Terrain New to 102 every bit to point to the second cell to be created and with variable 101 being set to the range for the current event. We then load Jail cell Ptr into the variable containing the value of the current event ID and then add together 99 to go the equivalent range variable for that result.

To make up one's mind how many steps terrain takes, nosotros utilize the terrain values. Earlier any value autonomously from i would be impossible to walk on, now they indicate how many steps yous take left instead. To brand certain terrain unpassable it's user-friendly to but requite them a very high terrain ID then that it wouldn't be possible to walk on them without having to create a special condition.

As before we get the Result and Terrain ID from the position we want to spawn some other move tile onto. We then go the range left for the current tile, subtracts the terrain ID nosotros but got and check if it'south 0 or larger. If yes and there is no event blocking the way, nosotros can move there and nosotros store the upshot of Jail cell Terrain Tmp into the variable corresponding the new tile's range value through the Prison cell Terrain New pointer. Later on it's increased by one and so that it's fix to set the range left for the next tile.

Since we don't have range left in the same style every bit before, nosotros have to detect a new criteria to stop the loop, And in this case, it will have to exist once Prison cell Ptr has reached the same value every bit Cell New. This would hateful that no new move tiles could exist created and as such the loop will exist terminated.

And with that, nosotros'll have managed to adjust the event to accept terrain into consideration as well. This concludes this tutorial. For the next 1 we'll expect at how to make an object find a path from a bespeak A to a betoken B within a given range while navigating through any kind of obstacle.
Y'all tin can notice the next tutorial here Path Finding Tutorial

A sample project containing the code from this tutorial tin can exist found here:
Sample Project

Source: https://rpgmaker.net/tutorials/527/

0 Response to "Rpg Maker Mv Pet System"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel