RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Conditional NPC Event Move Route

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 83
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.  

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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.