Another In Progress Script.
Won't be the best in the world, but will use a method a little different than the others.
def find_path(event_id, tile_x, tile_y)
path = Path.new(event_id)
path.find(tile_x,tile_y)
end
class Path
def initialize(event_id)
@map = $game_map
if event_id == 9999
@event = $game_player
else
@event = @map.events[event_id]
end
@open_tiles = set
end
def find(tile_x,tile_y)
@paths = []
if @event.lock?
return p 'Error : Event Position Locked Cannot Move'
elsif !@open_tiles.include?([@event.x,@event.y])
return p 'Error : Movement Not Allowed From Current Possition'
end
@x = @event.x.deep_clone
@y = @event.y.deep_clone
border = [[@x, @y - 1], [@x + 1, @y], [@x, @y + 1], [@x - 1, @y]]
total_possible_paths = 0
for tile in border
total_possible_paths += 1 if @open_tiles.include?(tile)
end
for i in 0..(total_possible_paths)
@paths[i] = Possible_Path.new
# Code to Map Path Goes Here
end
distances = []
for i in 0..(@paths.size)
distances[i] = @paths[i].distance
end
@best_path = @paths.find{ |path| path.distance == distances.min }
end
def move
# Code to move Goes Here
end
def set
temp = []
for x in 0..(@map.width / 32)
for y in 0..(@map.height / 32)
temp.push([x,y]) if @map.passable?(x,y,0)
end
end
return temp
end
end
class Possible_Path
# Code for Storing Path Information Goes Here
end
class Object
def deep_clone
file = File.open('cloning.txt', "wb")
Marshal.dump(self,file)
file.close
file = File.open('cloning.txt', "rb")
data = Marshal.load(file)
file.close
return data
end
end