GIBMAKER'S PATHFINDER

RPG Maker XP

Efficiently find a route to a target in the least number of steps regardless of map complexity

  • Gibmaker
  • 11/21/2014 03:12 AM
  • 5127 views
Pathfinding script for RMXP. Guaranteed to navigate any type of obstruction in the minimum possible number of steps, without brute-forcing the entire map, but longer solutions will obviously take longer to devise.

Will return an empty move list if no route exists, but it will exhaust the entire map if no route exists which is time-consuming so it's best used in cases where a route is guaranteed to exist.

References to Pathfinder must be inserted into the Game_Character#passable? method and I couldn't find an elegant way to accomplish this without just replacing the entire method. I am sorry. Take this into account if you have customized Game_Character#passable? in other ways.

Usage:
Pathfinder.new( Game_Event, Game_Event )
Pathfinder.new( Game_Event, int(target x), int(target y) )

* It's recommended to initialize using event references wherever possible, since it will use the event's properties to determine passability.

Public members:
#move_routePath formatted as an RPG::MoveRoute
#first_directionFirst direction of movement in the route (2/4/6/8)
#path_coordsList of coordinates of all tiles stepped through
#path_dirsList of all directions moved (2/4/6/8)


Simple step-toward-player implementation:
event.force_move_route( Pathfinder.new(event, $game_player).move_route )


Move player to given coordinates:
$game_player.force_move_route(Pathfinder.new($game_player, x, y).move_route)

Posts

Pages: 1
NeverSilent
Got any Dexreth amulets?
6299
I tried this script out, and I'm not sure whether I missed something about how to correctly implement it, but I get the following errors:

As soon as I had inserted the script into a test project, this error kept occuring whenever I touched an event with the player character:




So in order to test if the script in itself works, I put the command into an autorun event, but this is what happened:




If this is all just due to me being clueless about how this script is supposed to be used, I apologize. But I thought I should at least mention it and ask what I can do about it. Thanks.
Gibmaker
I hate RPG Maker because of what it has done to me
9274
Argh, that was just another unrelated modification. I got rid of the reference to pass_through_events.
Pages: 1