make an event move toward another event

frostwolf3

Veteran
Veteran
Joined
Jun 15, 2016
Messages
36
Reaction score
3
First Language
english
Primarily Uses
hey there,
first of all i'm terribly sorry if i'm posting in the wrong place, idk why i always end up in the wrong place if not then cool

I would like to make an event move toward a second event
I know I can make event move toward players but I don't need that
I would really appreciate it if i didn't have to use plugin, and i don't mind using scripting
thanks guys
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
An obvious greedy - though not optimal - solution would be to close the gap on the X axis and then on the Y axis. This provides the shortest theoretical path without taking passability into account.

If you are moving your event from a script call within the event itself you can do this:
Code:
ev = $game_map.events[@event_id]
destination_event = $game_map.events[other_event_id] # change this to be the other event ID
dist_x = ev.x - destination_event.x # if this is > 0 your destination is on the right, if it is < 0 it is on the left
dist_y = ev.y - destination_event.y # >0 means your destination is above, <0 means it is below
total_distance = dist_x.abs + dist_y.abs # this is your total distance
while (total_distance > 1)
  moved = false;
  dx = ev.x - destination_event.x
  dy = ev.y - destination_event.y
  if (dx != 0)
    x_mod = dx / dx.abs
    dir = x_mod > 0 ? 4 : 6
    if ev.passable?(ev.x - x_mod, ev.y, dir)
      ev.move_straight(dir)
      Fiber.yield while ev.moving?
      moved = true
  end; end; next if moved;
  if (dy != 0)
    y_mod = dy / dy.abs
    dir = y_mod > 0 ? 8 : 2
    if ev.passable?(ev.x, ev.y - y_mod, dir)
      ev.move_straight(dir)
      Fiber.yield while ev.moving?
      moved = true
  end; end; break unless moved;
  total_distance -= 1
end
The code should be something like this. I cannot check eventual mistakes because I cannot access the engine right now. However I am quite sure it is a bit too long to fit in your script box.

Another option would be drawing the path between those events using regions (if those events are fixed) and define a path according to those regions.

NOTE: the script call above stops if it is not possible to close the gap with the next step. It works in a similar way to "Move toward player" so if there are walls in the way it will have no effect at all. Be sure to use this wisely. Other ways to close the gap calculating the shortest path are way too long to be written here and I would really recommend using a script if you want something like those.

P.S. plugins are for MV, not for VX Ace so of course you will not be using them. XD
 
Last edited:

frostwolf3

Veteran
Veteran
Joined
Jun 15, 2016
Messages
36
Reaction score
3
First Language
english
Primarily Uses
@Heirukichi I honestly can't thank you enough for the code thank you thank you thank you
and i cant use a default path because the other event is constantly moving
and thanks for the tip ^_^
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
You're welcome, I just hope I did not make any mistakes when writing it. Not having syntax highlighting nor any way to complete words automatically really makes writing code much harder. If you add a touchscreen keyboard to the mix you get what is probably the worst possible combination.

However if you find any mistake and do not know how to fix it feel free to ask and I will try to help as much as I can. As a side note you should know that everything I wrote in that code can be done without using a script call. Event commands are enough to do that. You cannot check passability with them but if you check your event coordinates after telling it to move and they are the same it means the tile was not passable.
 

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

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,854
Messages
1,016,998
Members
137,562
Latest member
tamedeathman
Top