Pokemon type event trouble

I made an event that is supposed to act like a trainer in pokemon, but i am having some issues.
1617041629729.png

When the event detects the player, even when the player is not in direct line of sight, the event does the moving animation and the battle part, but it is still doing the custom movement that I have on it, instead of staying still. Plus, I wish for it to only move when it sees the player in its direct line of sight a few blocks away and move to them like the pokemon npcs do. Thanks for the help.
You used "Conditional Branch" with Javascript right?
So you are using a Script RGSS, could you post the link here?
You used "Conditional Branch" with Javascript right?
So you are using a Script RGSS, could you post the link here?
You could do a self switch on, and on the next page you do the battle processing, without any autonomous movement, and use an "if win: Erase Event, if lose: Turn off self switch. That should make the event dissapear, and re-appear when you re-enter the map.

I hope you understand what I mean.
You could do a self switch on, and on the next page you do the battle processing, without any autonomous movement, and use an "if win: Erase Event, if lose: Turn off self switch. That should make the event dissapear, and re-appear when you re-enter the map.

I hope you understand what I mean.
That is helpful, but not the info I am looking for.
I hope you find what you are looking for 👍 😀
I am not quite sure exactly what you mean. I think you want it to only detect the player if the player is in a direct line in front of the event and when it detects the player then the player should stop and let the event move to the player, say some text, and start a battle like in pokemon? If so then you need to rewrite the saw_player function in the detection script as it returns true if the event is facing the general direction of the player. I have rewritten it to be the direct direction here:
Spoiler: Code
Ruby:
def saw_player?(e)
  event = get_event(e)
  eventXDist = distance_x_from(e, $game_player.x)
  eventYDist = distance_y_from(e, $game_player.y)

  if event.direction == 2 #South
    return (eventYDist < 0) && (event.x == $game_player.x)
  elsif event.direction == 4 #West
    return (eventXDist > 0) && (event.y == $game_player.y)
  elsif event.direction == 6 #East
    return (eventXDist < 0) && (event.y == $game_player.y)
  elsif event.direction == 8 #North
    return (eventYDist > 0) && (event.x == $game_player.x)
  end
end
You can then set an event up using two pages. One page for detecting the player and one page for the movement and battle processing. The reason for having the second page is to have that page be autorun so the player cannot move. Here is an example:
Spoiler: Images
1617066632370.png

1617066651596.png
I am not quite sure exactly what you mean. I think you want it to only detect the player if the player is in a direct line in front of the event and when it detects the player then the player should stop and let the event move to the player, say some text, and start a battle like in pokemon? If so then you need to rewrite the saw_player function in the detection script as it returns true if the event is facing the general direction of the player. I have rewritten it to be the direct direction here:
Spoiler: Code
Ruby:
def saw_player?(e)
  event = get_event(e)
  eventXDist = distance_x_from(e, $game_player.x)
  eventYDist = distance_y_from(e, $game_player.y)

  if event.direction == 2 #South
    return (eventYDist < 0) && (event.x == $game_player.x)
  elsif event.direction == 4 #West
    return (eventXDist > 0) && (event.y == $game_player.y)
  elsif event.direction == 6 #East
    return (eventXDist < 0) && (event.y == $game_player.y)
  elsif event.direction == 8 #North
    return (eventYDist > 0) && (event.x == $game_player.x)
  end
end
You can then set an event up using two pages. One page for detecting the player and one page for the movement and battle processing. The reason for having the second page is to have that page be autorun so the player cannot move. Here is an example:
Ok so here is how I have the move and battle part set up.
1617075463759.png

BTW is the code supposed to be put under the detector script or is it a changed part of the script and if so what line?
The code was a changed part of the script around line 112. But if you prefer having it be a script after the detector script this should work:
Ruby:
class Game_Interpreter
  def saw_player?(e)
    event = get_event(e)
    eventXDist = distance_x_from(e, $game_player.x)
    eventYDist = distance_y_from(e, $game_player.y)

    if event.direction == 2 #South
      return (eventYDist < 0) && (event.x == $game_player.x)
    elsif event.direction == 4 #West
      return (eventXDist > 0) && (event.y == $game_player.y)
    elsif event.direction == 6 #East
      return (eventXDist < 0) && (event.y == $game_player.y)
    elsif event.direction == 8 #North
      return (eventYDist > 0) && (event.x == $game_player.x)
    end
  end
end
The code was a changed part of the script around line 112. But if you prefer having it be a script after the detector script this should work:
Ruby:
class Game_Interpreter
  def saw_player?(e)
    event = get_event(e)
    eventXDist = distance_x_from(e, $game_player.x)
    eventYDist = distance_y_from(e, $game_player.y)

    if event.direction == 2 #South
      return (eventYDist < 0) && (event.x == $game_player.x)
    elsif event.direction == 4 #West
      return (eventXDist > 0) && (event.y == $game_player.y)
    elsif event.direction == 6 #East
      return (eventXDist < 0) && (event.y == $game_player.y)
    elsif event.direction == 8 #North
      return (eventYDist > 0) && (event.x == $game_player.x)
    end
  end
end
You are amazing! Thank you so much for the help. I really appreciate it.
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/pokemon-type-event-trouble.134895/