@caethyril Thanks! I tried it out and it works really well. Although when it comes to changing the movement speed with the code, I am a little confused as to which number symbolizes frequency and which number symbolizes speed.
Frequency determines how often an event moves. Frequency 5 (Highest) means there is no delay between movements, lower frequencies put a delay between each step: the lower the frequency, the longer the delay. For this I'd recommend a frequency of 5, at least when they're chasing you. =)
If you'd also like the frequency to change when chasing/not chasing, putting this in another Script command seems to do it:
Code:
this.setMoveFrequency($gameMap.distance(this.x, this.y, $gamePlayer.x, $gamePlayer.y) < 8 ? 5 : 4);
It works much the same as the move speed one: if the event is less than 8 tiles away from the player, move frequency gets set to 5, else it gets set to 4.
There is one other thing I am needing with your code. When using your movement, the animal (fox) is a little too clever and makes it impossible (I think) to get far enough away from him so that he stops chasing the player. Is it possible to make it that he walks five spaces towards the player, then one random space, then five spaces towards the player, and so on? In my previous animal (fox), I made him do that. Thanks a lot.
Oops, yes, good point! Poor doomed bunny.
Before I go on, I'll just note that I've realised I'm basically reinventing Yanfly's
Event Chase Player plugin with script calls here...you may want to give that a look instead at this point, but I'll carry on regardless.
I'm not sure about how to make it happen every 5 steps, but giving the event a random chance to not chase every move is possible. Here's an example where the event will chase correctly 80% of the time and move randomly otherwise:
Code:
if (Math.randomInt(100) < 80 && $gameMap.distance(this.x, this.y, $gamePlayer.x, $gamePlayer.y) < 8) { this.moveStraight(this.findDirectionTo($gamePlayer.x, $gamePlayer.y)); } else { this.moveRandom(); }
The only difference here is the
Math.randomInt(100) < 80 bit, which means "pick a random integer from 0~99 and check if it's less than 80", i.e. return true 80% of the time.
I noticed there's a 1-frame delay if using multiple Script commands in one move route, so I decided to try putting them all in one command (in script, semi-colons act as line breaks) and it seemed to work well!

Here's my test example, works if pasted into a single Script command in an event's auto move route:
Code:
var chaseDist = 8, baseSpeed = 3, chaseSpeed = 5, baseFreq = 4, chaseFreq = 5, wanderChance = 20; var inRange = $gameMap.distance(this.x, this.y, $gamePlayer.x, $gamePlayer.y) < chaseDist; if (inRange) { this.setMoveSpeed(chaseSpeed); this.setMoveFrequency(chaseFreq); } else { this.setMoveSpeed(baseSpeed); this.setMoveFrequency(baseFreq); }; if (inRange && Math.randomInt(100) < (100 - wanderChance)) { this.moveStraight(this.findDirectionTo($gamePlayer.x, $gamePlayer.y)); } else { this.moveRandom(); }
Yep, that's a lot of code!

However, notice there's a collection of values defined at the start...that's so you don't have to dig through the actual code hunting them down, you can just change the starting values and everything should adjust correctly.

Here's what each one should do:
- chaseDist: limits how many tiles away the event should start chasing from;
- baseSpeed: movement speed when not chasing the player (player walk speed = 4, dash speed = 5);
- chaseSpeed: movement speed while chasing;
- baseFreq: movement frequency when not chasing the player;
- chaseFreq: movement frequency when chasing;
- wanderChance: % chance of random movement while in range for chasing;
Feel free to make any edits you like to the script!
(...incidentally, I think I'm going to use this, or something similar, in the game I'm making; it looks neat! ^_^)