Looping event movement

centaur66

Villager
Member
Joined
Apr 18, 2019
Messages
27
Reaction score
2
First Language
english
Primarily Uses
RMXP
I tried to do this while making events in xp and I got a result I wasn’t entirely happy with it. One of the areas in the game is a long stretch of road and I wanted to have cars driving by. The way I did it on XP was I made ‘player touch’ events to trigger a car event, but it became too repetitive. I was wondering if there was a way to have the cars reach the end of the road and then loop back where they started. Bonus points if I can randomize the car sprite? Thanks in advance.
 

Ebanyle

açspasl~d~dfflass
Veteran
Joined
Sep 2, 2016
Messages
338
Reaction score
200
First Language
Portuguese
Primarily Uses
RMVXA
You could use the automatic set move route to make the cars move, but I'm not sure if there's any way to make them go to the other side quickly in just set move route. You could use a Parallel Process event, but not only Ace does not sit well with too many of these processes, I think it wouldn't work. For example, lets say we will use the same paralell process for all of the cars movement. We would set various mouve routes that moved them, and then set event location below them. But these move routes would need to don't wait until they're completed, so the events would keep teleportating themselves. That would be weird. Of course, you can use separate parallel events for each car, but depending on how is your project now that could be... not recommended. If you want to, set at least 1 frame wait at the end of each one.

You could also use a script call moveto(x,y), but apparently it doesn't works when the characters are off_screen. Try using Vlue's Eventing Fine Tuning though, it has a moveto command.
As for the randomization, I think you just could set the same movement (with moveto) about 3 times in each car, just using different graphics each time. You could use a random variable and make something like "if variable is value bla change graphic to bla bla bla" but I don't know if conditions can be set inside move route, so I'd prefer to simple change the car graphic in the event move route.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
@centaur66 yes, a way to loop them exists, and on top of it you can even make it more realistic. You only need one parallel process to handle cars and, depending on how many lanes there are in your street, I recommend using a single car event for each lane.

When they reach the end of the road, you can set a new event location for each car and put them back at the beginning of the road. However, characters cannot walk outside the boundaries of the map (coordinates < 0 or >= $game_map.width) as the passable? method of Game_Map returns false.

For this reason you might have to handle your map in a way that both the beginning and end of the road are not visible, otherwise you will have to teleport those cars and it is not going to look very realistic.

Another option would be using sprites instead of events, the player can pass through them, but this way they can step on tiles with coordinates that are not in the map range.

If you want to do i with events then you can just create a parallel process like this:
Code:
cars = [id1, id2, id3] # put more event IDs here
cars.each do |id|
  car = $game_map.events[id]
  next if car.moving?
  mw = $game_map.width - 1
  mh = $game_map.height - 1
  car.moveto(mw, car.y) if (car.x <= 0)
  car.moveto(0, car.y) if (car.x >= mw)
  car.moveto(car.x, 0) if (car.y >= mh)
  car.moveto(car.x, mh) if (car.y <= 0)
  car.move_straight(car.direction)
end

As I said, this will make cars teleport when reaching the beginning of the road or the end of it, so create your map so that those parts are not visible.

@Ebanyle there is no need to use multiple parallel process events to handle that and there is also no need at all to wait for car movement completion before moving anything else. As a matter of fact, having multiple parallel process events is always a bad idea. I cannot think of something that can be done with multiple parallel process events, which cannot be done with just one.

Parallel process events are actually executed one after another, even if they are called "parallel process". This means that if you create multiple parallel process events, the engine still runs them one after another, which means you could as well put their contents all in the same parallel process.
 

centaur66

Villager
Member
Joined
Apr 18, 2019
Messages
27
Reaction score
2
First Language
english
Primarily Uses
RMXP
@centaur66 yes, a way to loop them exists, and on top of it you can even make it more realistic. You only need one parallel process to handle cars and, depending on how many lanes there are in your street, I recommend using a single car event for each lane.

When they reach the end of the road, you can set a new event location for each car and put them back at the beginning of the road. However, characters cannot walk outside the boundaries of the map (coordinates < 0 or >= $game_map.width) as the passable? method of Game_Map returns false.

For this reason you might have to handle your map in a way that both the beginning and end of the road are not visible, otherwise you will have to teleport those cars and it is not going to look very realistic.

Another option would be using sprites instead of events, the player can pass through them, but this way they can step on tiles with coordinates that are not in the map range.
Thanks for your reply, I’m not quite sure what you meant when you said ‘another way would be to use sprites instead of events’. I had extended the map farther than th eolaye rdoukd access on rogmaker XP, so thank you for reminding me to do it here I would have forgot.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
another way would be to use sprites instead of events
I mean that you could create a completely new sprite object (more or less the same as using show picture) and then move it around. If you use pictures instead of events it works in the same way (as they can move to negative coordinates), but they will not hit the player. You could even use a combination of both pictures and blank events if you want to. However, the best option is to have a bigger map and just transfer your events with the code I previously wrote.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
any time you need to add complex movement options to the movement route, you can use the script option and input them yourself.
BUT, if the input is too complex, you might want to modify the movement route object itself, and add your checks for your special case.
then you can just go into the movement route option of the event, specify a variable that would trigger your check, and use the default movement instructions, and everything will self adjust.

but I'm not sure if there's any way to make them go to the other side quickly in just set move route
same point here.
not directly through the move route tool, but modifying the move route object, RPG::MoveRoute
you can add a new procedure called Send_To(x,y), and call that through the script input.

Bonus points if I can randomize the car sprite?
that would involve preparing the events in advance, before the map is loaded, or having the events out of view and resetting them in between passes in front of the player.
there's a number of ways to do it, but if we're talking one single car visible, you can set the event to autorun, and have the event itself set it's own properties and then send itself underway, and the checking for loop and the sprite change would be handled at event level and not at move route level.

be mindful that having lots of moving events causes the map to increase it's update calls, so it can become laggy.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
that would involve preparing the events in advance, before the map is loaded, or having the events out of view and resetting them in between passes in front of the player.
Is it not easier to just put each different car sprite in the same character sheet and change the car graphics each time the event is moved from one edge of the map to the other edge of the map? It only requires a random integer from 0 to N (N is the number of different cars - 1) and then all you have to do is change the index attribute for the event character to be that random number.
Code:
set_graphic(car.character_name, rand(N))
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,377
Reaction score
8,536
First Language
English
Primarily Uses
RMMV
So a long while back, I did sort of a log jumping type game - hop across the river on logs moving along a river. I'm pretty sure I used Galv's Event Spawn Timer script to accomplish the logs floating across the screen to create a continual loop effect. https://galvs-scripts.com/2013/02/23/respawn-timer/
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
Is it not easier to just put each different car sprite in the same character sheet and change the car graphics each time the event is moved from one edge of the map to the other edge of the map? It only requires a random integer from 0 to N (N is the number of different cars - 1) and then all you have to do is change the index attribute for the event character to be that random number.
Code:
set_graphic(car.character_name, rand(N))
yes, that's why I asked if it's only about one car or several.
you don't even need a sprite sheet.... you can use one sprite, and just change it's hue, if it's set up correctly.

that all falls into the part of "resetting the event", which comes after the "checking for destination", which is all driven by the move route.
the core of the matter is having a move route or an event logic that would handle the moving, the checking and the reset, which leads back to the moving.
everything else, is adjustable.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top