Main Menu
  • Welcome to The RPG Maker Resource Kit.

Conditional NPC Event Move Route

Started by GreenBanana, January 27, 2010, 11:24:37 PM

0 Members and 1 Guest are viewing this topic.

GreenBanana

How would you go about creating an NPC whose move route would change depending upon a condition such as proximity to the player?  And how would you do this with only one event?  

Let's make an example where you have an NPC that will try to avoid the player if the player approaches too closely.  Let's say that if the player is in a range of five tiles, the NPC will attempt to move away from the player, but if the player is farther away than this then the NPC will just move randomly.  The NPC is a person who will show a message when the player interacts with it, triggered by the Action button.  

Is it possible to achieve this via the Script... command in the Custom Move Route properties of the NPC event?  If so,how is it done?  My initial attempt was to try and compare the Player's map coordinates to the Event's map coordinates, but I am unsure how to reference this as self.x and self.y or self.map_x and self.map_y and so forth, but I always receive an error.  I've been trying search engines and searching on RMXP websites (well, they're just forums, really) for the past few days now with no success.  

Also, while I suspect this would require scripting, I wasn't sure that it would require an entire Script per se, as I figured it would only require minimal basic-level programming, such as an if-then-else statement and some variable referencing. 

Thanks for your time.  

modern algebra

Well, my suggestion would be to have the event have two pages, one that is set to moe randomly and the second set to move away from player. Have the second be conditional on a switch.

Then in a parallel process event, compare player x & y to event x & y by using the Control Variable command to get those values and then comparing them in a conditional branch. If they are within 5 squares (a simple calculation), then turn on the switch that the second page has as its condition. If it's > 5, then turn that switch off.