Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Path Finding--Please I need it fast

I need ( to anyone who can make it or point me in the dirrection of it) a pathfinding script that can use variables, Example

Set Variable ( player 1-x) = player's [X- map]
Set Variable ( player 1-y) = player's [Y- map]
(this is what I need \/ )
Script { scene_pathfinding_[event id] [variable x] [variable y]}
and it can work with parrellel process's.
I need it mainly for events.
I need it because I have big maps, and alot events all the time moving
to other events, and it will take years to do, with (event movement)

Just in case you can do this sort of thing without a script, this is what I
tried but it kept hitting trees and water.

>Control Variables: [0026: dominion-E-1-X]=[EV002]'s Map X
>Control Variables: [0026: dominion-E-1-Y]=[EV002]'s Map Y
>Control Variables: [0051: Rachel-X]=This event's Map X
>Control Variables: [0051: Rachel-Y]=This event's Map Y
>Control Variables: [0051: Rachel-X]-=Variable [0026: dominion-E-1-X]
>Control Variables: [0051: Rachel-Y]-=Variable [0026: dominion-E-1-Y]
@>Conditional Branch: Variable [0051: Rachel-X]<=-2
@>Set Move Route: This event (Ignore If Can't Move)
: :$>Move Right
@>
Else
@>Conditional Branch: Variable [0051: Rachel-X]>=2
@>Set Move Route: This event (Ignore If Can't Move)
: :$>Move Left
@>
Else
@>
: Branch End
@>
: Branch End
@>Conditional Branch: Variable [0051: Rachel-Y]<=-2
@>Set Move Route: This event (Ignore If Can't Move)
: :$>Move Down
@>
Else
@>Conditional Branch: Variable [0051: Rachel-Y]>=2
@>Set Move Route: This event (Ignore If Can't Move)
: :$>Move Up
@>
Else
@>
: Branch End
@>
: Branch End
@>



It gets to them but it doesn't dodge elements in the way,
I'm a variable artist not a scripter, PLEASE, I need this as fast as possible.
 
Sorry, I don't know if this counts as a bumb but i thought that it should be told before someone tries to make this script....
Can whoever can help me, can you make it "wait for movement to complete"
compatable?
 
Last I checked, Nears Pathfinding works fine with variables. I used it for my Event based battle system:

Near_Fantastica's Pathfinding:
Code:
#==============================================================================
#   â–  Path Finding
#   By: Near Fantastica
#   Date: 24.09.05
#   Version: 1
#
#   Player :: $game_player.find_path(x,y)
#   Event Script Call :: self.event.find_path(x,y)
#   Event Movement Script Call :: self.find_path(x,y)
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  alias pf_game_character_initialize initialize
  alias pf_game_character_update update
  #--------------------------------------------------------------------------
  attr_accessor :map
  attr_accessor :runpath
  #--------------------------------------------------------------------------
  def initialize
    pf_game_character_initialize
    @map = nil
    @runpath = false
  end
  #--------------------------------------------------------------------------
  def update
    run_path if @runpath == true
    pf_game_character_update
  end
  #--------------------------------------------------------------------------
  def run_path
    return if moving?
    step = @map[@x,@y]
    if step == 1
      @map = nil
      @runpath = false
      return
    end
    dir = rand(2)
    case dir
    when 0
      move_right if @map[@x+1,@y] == step - 1 and step != 0
      move_down if @map[@x,@y+1] == step - 1 and step != 0
      move_left if @map[@x-1,@y] == step -1 and step != 0
      move_up if @map[@x,@y-1] == step - 1 and step != 0
    when 1
      move_up if @map[@x,@y-1] == step - 1 and step != 0
      move_left if @map[@x-1,@y] == step -1 and step != 0
      move_down if @map[@x,@y+1] == step - 1 and step != 0
      move_right if @map[@x+1,@y] == step - 1 and step != 0
    end
  end
  #--------------------------------------------------------------------------
  def find_path(x,y)
    sx, sy = @x, @y
    result = setup_map(sx,sy,x,y)
    @runpath = result[0]
    @map = result[1]
    @map[sx,sy] = result[2] if result[2] != nil
  end
  #--------------------------------------------------------------------------
  def setup_map(sx,sy,ex,ey)
    map = Table.new($game_map.width, $game_map.height)
    map[ex,ey] = 1
    old_positions = []
    new_positions = []
    old_positions.push([ex, ey])
    depth = 2
    depth.upto(100){|step|
      loop do
        break if old_positions[0] == nil
        x,y = old_positions.shift
        return [true, map, step] if x == sx and y+1 == sy
        if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
          map[x,y + 1] = step
          new_positions.push([x,y + 1])
        end
        return [true, map, step] if x-1 == sx and y == sy
        if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
          map[x - 1,y] = step
          new_positions.push([x - 1,y])
        end
        return [true, map, step] if x+1 == sx and y == sy
        if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
          map[x + 1,y] = step
          new_positions.push([x + 1,y])
        end
        return [true, map, step] if x == sx and y-1 == sy
        if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
          map[x,y - 1] = step
          new_positions.push([x,y - 1])
        end
      end
      old_positions = new_positions
      new_positions = []
    }
    return [false, nil, nil]
  end
end

class Interpreter
  #--------------------------------------------------------------------------
  def event
    return $game_map.events[@event_id]
  end
end
 
You follow the instructions for setting up a path (in the topic. It's on creationasylum I believe... search "path finding" there), and for trg_x, trg_y, src_x, src_y, you just put variables instead, like $game_variables[1] would be the value stored in variable 1.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top