• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Question] (Essentials) How to make an event move to a specific point on the map

2
Posts
2
Years
    • Seen Oct 15, 2023
    Hi, so right now I'm struggling making the rival character leave a room because the player affects where they stand. I was wondering if there was a way to make them move to a specific spot (without basically teleporting there) in the middle of the room, that way they can get there and just walk straight out. thanks :)
     

    Swdfm

    Game Developer
    245
    Posts
    5
    Years
    • he/him
    • UK
    • Seen Dec 8, 2023
    Hi @BiggSlorp
    So, there's a few ways to address your problem
    1) Move the rival based on where the player is.
    2) Move the rival based on where they start.
    Both solutions work, but one can be easier than the other depending on what the layout of the room is like.

    When I write the solution, I do not know the layout of the room, and I am assuming:
    1) The player has just talked to the rival, and is therefore next to them when this starts in any of the four directions.
    2) There are no objects between the destination tile and the current rival position, other than the player. This includes furniture, or other events, even empty ones.

    Write a script similar to:
    Code:
    def pbMoveRivalInPlace
      dest_x = 69 # Change this!
      dest_y = 420 # Change this!
      rival_event_id = 0 # Change this! 0 if the event calling this script IS the rival event
      #====================================
      # No need to change below here!
      #====================================
      rival = get_character(rival_event_id)
      is_west  = rival.x > dest_x
      is_north = rival.y > dest_y
      dirs = []
      # Establishes which directions the rival should go in
      if is_north
        if is_west # Rival has to move NW
          # If player faces down, go W, N. Otherwise, go W, N
          dirs = $game_player.direction == 2 ? [:W, :N] : [:N, :W] works
        else # Rival may have to move NE
          # If player faces down, go E, N. Otherwise, go N, E
          dirs = $game_player.direction == 2 ? [:E, :N] : [:N, :E] works
        end
      else
        if is_west # Rival has to move NW
          # If player faces up, go W, S. Otherwise, go W, S
          dirs = $game_player.direction == 8 ? [:W, :S] : [:S, :W] works
        else # Rival may have to move SE
          # If player faces up, go E, S. Otherwise, go S, E
          dirs = $game_player.direction == 8 ? [:E, :S] : [:S, :E] works
        end
      end
      move_route = []
      # Works out steps to do
      for dir in dirs
        case dir
    	when :N
    	  (rival.y - dest_y).times do
    	    move_route.push(PBMoveRoute::Up)
    	  end
    	when :S
    	  (dest_y - rival.y).times do
    	    move_route.push(PBMoveRoute::Down)
    	  end
    	when :W
    	  (rival.x - dest_x).times do
    	    move_route.push(PBMoveRoute::Left)
    	  end
    	when :E
    	  (dest_x - rival.x).times do
    	    move_route.push(PBMoveRoute::Right)
    	  end
    	end
      end
      # Actual Movement
      return if move_route.empty?
      pbMoveRoute(mover, move_route)
      # Below line allows movement to take place!
      to_wait = 0.5 * move_route.length
      pbWait(to_wait) if to_wait > 0
    end
    And then place in "pbMoveRivalInPlace" onto any event in a script section, to run when you need it to

    I haven't tested this code, so let me know if any errors show up!

    Hope this helps,
    Swdfm
     
    Back
    Top