Pheryus

Villager
Member
Joined
Aug 18, 2015
Messages
19
Reaction score
2
First Language
Portugues
Primarily Uses
Hi. I'm trying to control the "enemies" events to follow the player under specifics circunstances using js.
This function is called in the updateScene function from the Scene_Map and the events have their autonomous movement "Fixed".

I use the _chasePlayer to set the events to follow the player, and the results end up working.
But when I set the events to stop following the player (in the updateScene too), the events returns to the place where they had started, and I dont want that.
I tried different strategies to stop that, but doesnt work. Even setting the _moveSpeed to 0 doesnt prevent that from happening.

If anyone knows wth is happening, please, help :D
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,567
Reaction score
8,159
First Language
German
Primarily Uses
RMMV
Please post the code that you're using, and screenshots of any event code as well.
Your vague descriptions are not enough to understand what is happening or to help you.
 

Pheryus

Villager
Member
Joined
Aug 18, 2015
Messages
19
Reaction score
2
First Language
Portugues
Primarily Uses
Ok. I tried to replicate the results that were occuring in my real project, but didnt work (for some unknown reason). But I'll assume this error is the raw one and the cause of my problems.

Suppose I have a event (or events) like this one, with a notetag like "follow_player".

a6a0f458-425f-434e-8edb-075253ed7ccf
YX6LDdF.png


I created a simple script here to illustrate what I wanted, so you can understand the expected results I was hoping to happening.

RtmibIE.png


I want the event with the follow_player tag to follow the player if the switch 1 is active. In my previous attempts, the event was following the player correctly, but when the gameSwitch 1 turn off, it stop following the player and starts to move back to the original position it was placed in the map.

On the other hand, this simple piece of the code isnt even working at all. The event is still idle, even with the switch on. What can I do to modify the movement and the type of movement of events via script?

If you can solve or help with one of these two situations (probably this second one that I examplify with some code), I will be grateful :D

[EDIT]
Oh, it seems I forgot to put some more code in the script.

Test_Game_Event_updateSelfMovement = Game_Event.prototype.updateSelfMovement;

Game_Event.prototype.updateSelfMovement = function (){

if (this._stopCount > 0 && this._chasePlayer){
var direction = this.findDirectionTo($gamePlayer.x, $gamePlayer.y);
if (direction > 0) this.moveStraight(direction);
}
else
Test_Game_Event_updateSelfMovement.call(this);
}

This piece of code fixed my problems! In fact, the other weird situation that was hapenning was due to the findDirectionTo arguments that I was using. I was not passing the gamePlayer position as the arguments, but a variable referencing the previous position of player. When the switch turned off, the reference variable was resetting, making the event follow to the (0,0) position.
Sorry by the confusion here :aswt: The problem is solved.
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,063
Reaction score
2,323
First Language
English
Primarily Uses
RMMV
Can we see the code you wrote for handling the _chasePlayer flag?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,567
Reaction score
8,159
First Language
German
Primarily Uses
RMMV
I think you misunderstand several things.

By default, the engine does not remember any event position, so all events revert back to original position on map reloading. That is the only possible reason for the event to go back to its original position like you described, and that had nothing to do with your code for following.
The only way to prevent that is to use a plugin that updates event positions through map reloads - there are several of them already existing, for example Shaz' "remember event position" (might be named a bit different)

That said, why use javascript at all? That (minus the remember position) is one of the most basic functions supported by the default engine.

Simply make a two-page event, page one without condition and autonomous movement = fixed, page two with condition switch X = on, autonomous moment = approach player.
Finished - that event will try to follow the player if the switch is On and stop when it is off

If you want to include a remember position command, you need the plugin installed and use autonomous movement = custom on the second page, with the custom being one approach player command followed by the script command to update position.
 

Pheryus

Villager
Member
Joined
Aug 18, 2015
Messages
19
Reaction score
2
First Language
Portugues
Primarily Uses
Sorry for the confusion. I edited my last reply. But thanks anyway for the attention.

And thanks for the exemplification too, Andar. I'm not using the followPlayer via events cause I want the conditions to the followPlayer be more specific, like when pressing some key instead of some switch is turned on.

And about the Shaz script, I will take a look. It will probably help me too :D
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,063
Reaction score
2,323
First Language
English
Primarily Uses
RMMV
Glad you got it sorted, but you do realise Game_Event can already call a function called moveTowardPlayer that negates the need to use findDirectionTo, right?
 

Pheryus

Villager
Member
Joined
Aug 18, 2015
Messages
19
Reaction score
2
First Language
Portugues
Primarily Uses
Oh, yes. I didnt used because I wanted the events to go to the position the player was in the moment the switch turned on. Just to facilitate I omitted this information.
 

Latest Threads

Latest Profile Posts

just beat ff7 original for the first time since 2010. having played remake last year, I have a much better appreciation for the original oddly enough. I still like some of the character presentation in remake more, but the original's got a lot going for it.
Ever reach that moment in your life when your juggling a dozen or more projects that you know will never be made but don't have the heart to delete them? Ugh, I hate those moments...
:kaosigh: Why must you hurt me so?
my main character isn't the warrior of light or the chosen one, he's a self righteous, invasive try hard who gets ahead of himself and makes a critical error, resulting in a downward moral spiral that, eventually, leads him to truths that make him a better man, and im DAMN proud of that.
Generate Actors, Dark Fantasy Monsters, & I Heard There Was a Chosen One, | RPG Maker News #42

Work on Cat Quest: The Last Catmancer continues slowly but surely. :kaopride: Today I received the Game Over screen from @Finnuval!
GameOver.png

Forum statistics

Threads
111,448
Messages
1,061,171
Members
144,812
Latest member
Kitaaku
Top