Creating a patrolling guard that will chase on sight

bashenkman

Warper
Member
Joined
Jan 23, 2020
Messages
1
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hi All,

New user here. I wanted to post because I found a unique solution to a problem that, after searching for a bit, didn't have many answers.

I wanted to create a patrolling guard that would chase the player on sight. Naturally Yanfly's Event Chase Player was the beginning of the answer.

The problem I kept having was, I wanted the guard to patrol a route, chase on player sight, and return to his patrol once the player ran away.

Yanfly's Event Chase has a return function, and it worked very well, returning the guard to the beginning of his patrol after losing sight of the player.

The problem was, Yanfly's script is being called in the custom route movement section of the guard event, which is also where I need the patrol movements to run. This is because I need 'event touch' on for the player to enter combat with the guard.

What was happening is the guard would return to his patrol start, but would pick up the actual route sequence where he left off after chasing the player, i.e. if the whole pattern was (Turn Up, Move Up, Move Up, Turn Down, Move Down, Move Down) and the guard got through (Turn Up, Move Up, Move Up, CHASE PLAYER) he would return to the x,y, of the very beginning of his route, but then enact (Turn Down, Move Down, Move Down, Turn Up, Move Up, Move Up). Correct route in the wrong sequence, ending up with him patrolling the wrong place.

I finally came upon the answer by using custom movement script, and saving the x and y location of the guard after each movement. So essentially instead of returning to the patrol start x,y, he returns to the point in the patrol he started chasing from, and resumes it there. Because of the way the return function in Yanfly's works, you don't have to worry about the x,y, being overwritten again until the guard has reached its start x,y, even if you re-aggro it and drag it somewhere else as it is returning.

The code is, for (Turn Up, Move Up, Move Up, Turn Down, Move Down, Move Down) (using Yanfly's Event Chase Plugin), written in the autonomous movement custom route:

this._chaseRange = 5; //(movement script)
Turn Up //(normal call)
$gameMap.event(5).moveStraight(8);this._startLocationX = this.x;this._startLocationY = this.y; //(ALL in ONE movement script)
$gameMap.event(5).moveStraight(8);this._startLocationX = this.x;this._startLocationY = this.y; //(Another separate movement script)
Turn Down //(normal call)
$gameMap.event(5).moveStraight(2);this._startLocationX = this.x;this._startLocationY = this.y; //(ditto)
$gameMap.event(5).moveStraight(2);this._startLocationX = this.x;this._startLocationY = this.y; //(ditto)


Basically the stock movements are replaced with script movements, and each appended by overwriting the start x,y. It doesn't need to be done for turns, as they are the same x,y. Hope this helps someone in the same situation.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Fekken kill me. I unknowingly swapped out two important events's codes and saved the game to test it. I'm just doing this for fun and the fun has now been replaced with excruciating torture.
Is this how game developers feel all the time?

EDIT:
WAIT HOLY S***
MY LAST POST ASKING FOR HELP ON AN EVENT ACTUALLY SAVED IT
OH MY GOD
Coffee + Silk Coconut Milk + Splenda Zero = Not ..... awful :/ .
I was making a cutscene where Hero's dad got killed by the dragon but when he lose its say game over and send you to the tittle screen. How can remove game over for that cutscene
My new RPG Maker music pack, Emotional: Redemption, is now in progress and will be coming to RPG Maker soon. It is an album that focuses on emotional themes including the darker forms of sorrow and despair. Below is a demo of a composition from the album.

Please watch out for your hands when handling chests! XD Did this a few days ago, it was fun to animate

Forum statistics

Threads
94,446
Messages
920,985
Members
124,258
Latest member
Aotaru
Top