Copies someone move route

Discussion in 'RGSS3 Script Requests' started by CodeEmpress, Mar 5, 2014.

    Tags:
  1. CodeEmpress

    CodeEmpress Villager Member

    Messages:
    21
    Likes Received:
    0
    First Language:
    English
    Could someone help me? (I am new to rgss3)

    Well what I need is a script that copies the movement or a certain event.

    Example: Given we have two points A and B then Event 1 and 2

    Let us say Event 1 found a path starting from A and B. Then I want Event 2 to copy that path.

    What I wanna do is that under Event 1 I will create an Event 2 which is like a very fast dot that copies the path of Event 1. More like you are having a line and it shows where you are going.

    Thank you very much
     
    Last edited by a moderator: Mar 5, 2014
    #1
  2. ShadowLurk

    ShadowLurk Tanoshii~ Veteran

    Messages:
    226
    Likes Received:
    53
    What did you use for pathfinding? Most of the pathfinding scripts I see does not store an array containing their move routes, so by that reason, their path cannot be copied. If you do use pathfinding scripts, just call the same pathfinding method for the second event.
     
    #2
  3. CodeEmpress

    CodeEmpress Villager Member

    Messages:
    21
    Likes Received:
    0
    First Language:
    English
    I used PathFinding by jet from this link http://forums.rpgmakerweb.com/index.php?/topic/3064-pathfinding/

    it is based on A* algorithm(which stores the nodes for the path)
     
    #3
  4. ShadowLurk

    ShadowLurk Tanoshii~ Veteran

    Messages:
    226
    Likes Received:
    53
    Well, let's try this.

    class Game_Character attr_accessor :saved_found_path def save_path(x, y, dist = 0) path = $game_map.find_path(x, y, self.x, self.y, dist).reverse @saved_found_path = path.dup end  

      def execute_saved_path(ev = 0)

        if ev == 0

          src_char = self

        elsif ev < 0

          src_char = $game_player

        else

          src_char = $game_map.events[ev]

        end

        return unless src_char.saved_found_path

        path = src_char.saved_found_path

        if !@move_route.repeat

          @move_route.list.delete_at(@move_route_index)

          @move_route.list.insert(@move_route_index, *path)

          @move_route_index -= 1

        elsif path.length > 0

          process_move_command(path[0])

          @move_route_index -= 1

        end

      end

    def find_path_saved(x, y, dist = 0) save_path(x, y, dist) execute_saved_path end end class Game_Interpreter def save_path(x, y, ev = 0, dist = 0) char = get_character(ev) #modified line below (added distance parameter) path = $game_map.find_path(x, y, char.x, char.y, dist) path.reverse! path.push(RPG::MoveCommand.new(0)) char.saved_found_path = path.dup end def execute_saved_path(ev = 0, src_ev = ev, wait = false) char = get_character(ev) src_char = get_character(src_ev) return unless src_char.saved_found_path path = src_char.saved_found_path route = RPG::MoveRoute.new route.list = path route.wait = wait route.skippable = true route.repeat = false char.force_move_route(route) end def find_path_saved(x, y, ev = 0, wait = false, dist = 0) save_path(x, y, ev, dist) execute_saved_path(ev, ev, wait) end end 

    To find move path while saving them, use 

    find_path_saved in either event page or set move route. The arguments mirror find_path.

    To execute saved move path, use

    execute_saved_path(event, source_event)in event page, or

    execute_saved_path(event)in move route page.

    Edit: Fixed some errors.
     
    Last edited by a moderator: Mar 6, 2014
    #4
  5. CodeEmpress

    CodeEmpress Villager Member

    Messages:
    21
    Likes Received:
    0
    First Language:
    English
    Thank you gonna try it later when I got home :o
     
    #5
  6. ShadowLurk

    ShadowLurk Tanoshii~ Veteran

    Messages:
    226
    Likes Received:
    53
    Wait. It seems that the script formatting in my last post just... exploded.

    Here should be the snippet with the proper formatting:

    class Game_Character attr_accessor :saved_found_path def save_path(x, y, dist = 0) path = $game_map.find_path(x, y, self.x, self.y, dist).reverse @saved_found_path = path.dup end def execute_saved_path(ev = 0) if ev == 0 src_char = self elsif ev < 0 src_char = $game_player else src_char = $game_map.events[ev] end return unless src_char.saved_found_path path = src_char.saved_found_path if !@move_route.repeat @move_route.list.delete_at(@move_route_index) @move_route.list.insert(@move_route_index, *path) @move_route_index -= 1 elsif path.length > 0 process_move_command(path[0]) @move_route_index -= 1 end end def find_path_saved(x, y, dist = 0) save_path(x, y, dist) execute_saved_path end endclass Game_Interpreter def save_path(x, y, ev = 0, dist = 0) char = get_character(ev) #modified line below (added distance parameter) path = $game_map.find_path(x, y, char.x, char.y, dist) path.reverse! path.push(RPG::MoveCommand.new(0)) char.saved_found_path = path.dup end def execute_saved_path(ev = 0, src_ev = ev, wait = false) char = get_character(ev) src_char = get_character(src_ev) return unless src_char.saved_found_path path = src_char.saved_found_path route = RPG::MoveRoute.new route.list = path route.wait = wait route.skippable = true route.repeat = false char.force_move_route(route) end def find_path_saved(x, y, ev = 0, wait = false, dist = 0) save_path(x, y, ev, dist) execute_saved_path(ev, ev, wait) end end
    Hopefully this one won't explode....
     
    #6

Share This Page