Creating NPCs similar to trainers in Pokemon

Hi everyone.

I tried to make an NPC similar to Pokemon trainers as we know them from every Pokemon game.
Basically, the NPC is supposed to patrol an area and the moment you make eye contact with him, he should notice you, move
towards you and start the battle.

Here I was... thinking it will be pretty easy to do... I made an event that should probably work (even though it's really badly optimized), but it doesn't for some reason.

The NPC never notices me, that's the problem I'm trying to fix. I tried to set NPC on static, so it wouldn't move but the event still didn't work.

I would be happy if you could look at the event below and point a mistake.

This is the part of the map in use. The event is marked by the weird red arrow 😀
MapForum.jpg


This is the event page 1
EventPage1.jpg


This is all the content in the event page 1 (yes, the ID of the event really is 013, you can briefly see it at the top of event pages)
EventForum.jpg


And this is the event page 2
EventPage2.jpg


Thanks in advance to anyone who spends their free time thinking about this problem.
If you have any ideas for a better optimized event that would do the thing I would want it to do, I'll be happy if you shared them. Thanks a lot 😀
This plugin will should do the trick
I belive with this plugin your npc will look and behave more natural
http://yanfly.moe/2015/10/21/yep-20-event-chase-player/
. . . .
First, I would like to appoint a lot of things on your event....
  1. [FLAW] Your event is too long, inconvenient, and inefficient cause you're repeating same process.
  2. [FLAW] You might want to change the event ID number to this._eventId. That will directly read the current event ID.
  3. [FLAW] Never put the actual content of your event in a parallel process. That will cause a clash if similar parallel process event is exist on the same map.
  4. [MISTAKE] When writing a condition, you use == (double equals) as comparison. Otherwise, the condition will be ignored. Guess this is what make your event not running.
    ex : $gamePlayer.x == $gameMap.events(this._eventId).x
  5. [MISTAKE] Your condition : $gamePlayer.x > $gameMap.events(this._eventId).x
    Will be triggered when the player is in a straight line of the event vision without any limit, including when you are behind a wall. Ineffective.

SOLUTION
  1. You can simply use the plugin mentioned above. It automatically chase player when the player is around the event proximity. Although that way doesn't feel like Pokemon-esque, since the player may try to run away from the event. The content of the event won't be triggered until it touch the player. I believe you don't want that...?

  2. Let me fix your event in the most effective way possible :

    [FIRST PAGE] is the parallel process event. Its function is only to detect the player when it's one tile in front of the event. Feel free tampering with the range condition if you understand how it works. When the condition are fulfilled, proceed to the second page.
    eventing1.JPG

    [SECOND PAGE] is the actual content of your event. The move route, show dialog, and battle process will run in an autorun. This is to avoid clashing with other similar parallel process event if you plan to put more than one guard roaming around the same map.
    eventing2.JPG

  3. When you mention "similar to trainers in pokemon", I believe most of them are static. Standing silently in place. In this case where the event doesn't move and a narrow path, it's better to just use an invisible event on the player's path with touch trigger.
Hope this help.
Thanks a lot, I tried both the plugin and the script you proposed, they work very well.
I'm still not sure which method I will use, but probably the plugin since it's easier to implement.
However, if it poses some problems I will use the script.
@Reigan
how about trying out the default method which works without plugin and without scripts?
It has some limitations, but it would be easiest to install.

First page with custom movement in autonomous movement, content for checking if the "hunt" is triggered on a parallel process with a wait(10) or so to prevent lag. If the hunt for the player is triggered, then just do a self-switch to activate a second page.

Second page has autonomous movement set to approach, trigger as "event touch" (which triggers as soon as the moving event touches the player) and the content only what should happen when the event catches the player (the battle processing part).

you don't have to compare the event and actor positions to trigger the battle, just let that be handled by the event touch trigger.
Seems like an interesting idea as well. Thanks a lot, everyone!

Original thread: https://forums.rpgmakerweb.com/threads/creating-npcs-similar-to-trainers-in-pokemon.94827/