RMMV Turning Common Event Script into a Plugin

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
210
Reaction score
165
First Language
English
Primarily Uses
RMMV
I wrote a small script to change the player's movement speed based on whether or not the current map type is Overworld:
JavaScript:
xDRAGOONx.setMoveSpeed = function(){
    if ($gameMap.isOverworld(this)) {
        $gamePlayer.setMoveSpeed(3);
        $gamePlayer.hideFollowers();
        $gamePlayer.refresh();
         } else {
        $gamePlayer.setMoveSpeed(4);
        $gamePlayer.showFollowers();
        $gamePlayer.refresh();
         }
}
xDRAGOONx.setMoveSpeed.call(this);
and after testing it as a common event called in a transfer event, I am wondering how I could add this in some way as a plugin so I don't have to add it to every single Overworld to Town transfer event.

I tried modifying:
JavaScript:
Game_CharacterBase.prototype.setMoveSpeed = function(moveSpeed) {
    this._moveSpeed = moveSpeed;
};
but I only managed to mess up the followers' movement, as I an not sure exactly what I am doing there.
 

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
540
Reaction score
219
First Language
english
Primarily Uses
RMMV
i usually have 1 autorun event on every map anyways so wouldnt be any issue adding it into those.
these autoruns could range from setting/enable/disable a teleport and warp location,
playing different music because day/night or war/festival is going on,
to changing the entire party's actor images based on state(dead/undead) or class changes from the menu. edit: that 1 more of common event then map event.
but teleporting NPC based on time and daily schedule was also autorun>erase map event.
just 2 more lines for speed and followers is nothing
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,050
Reaction score
1,479
First Language
EN
Primarily Uses
RMMZ
If you want to automatically invoke your method whenever the player changes map, you could try patching it in after the default setup method of Game_Map, e.g.
JavaScript:
(function() {
  var _Game_Map_setup = Game_Map.prototype.setup;
  Game_Map.prototype.setup = function() {
    _Game_Map_setup.apply(this, arguments);
    xDRAGOONx.setMoveSpeed();
  };
})();
You could put both that and your xDRAGOONx.setMoveSpeed method into a .js file (paste into text editor, Save As > File Type: All Files, Filename: whatever.js) and import as a plugin, I think that'll work. :)

(I'm not sure why you've passed isOverworld an argument...I don't see one in MV's code?)
 

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
210
Reaction score
165
First Language
English
Primarily Uses
RMMV
i usually have 1 autorun event on every map anyways so wouldnt be any issue adding it into those.
these autoruns could range from setting/enable/disable a teleport and warp location,
playing different music because day/night or war/festival is going on,
to changing the entire party's actor images based on state(dead/undead) or class changes from the menu. edit: that 1 more of common event then map event.
but teleporting NPC based on time and daily schedule was also autorun>erase map event.
just 2 more lines for speed and followers is nothing
I don't disagree with your method, but I am starting to get to the point where I want to go one step further learning the code behind the system and this looks like a great place to start.


If you want to automatically invoke your method whenever the player changes map, you could try patching it in after the default setup method of Game_Map, e.g.
JavaScript:
(function() {
  var _Game_Map_setup = Game_Map.prototype.setup;
  Game_Map.prototype.setup = function() {
    _Game_Map_setup.apply(this, arguments);
    xDRAGOONx.setMoveSpeed();
  };
})();
You could put both that and your xDRAGOONx.setMoveSpeed method into a .js file (paste into text editor, Save As > File Type: All Files, Filename: whatever.js) and import as a plugin, I think that'll work. :)

(I'm not sure why you've passed isOverworld an argument...I don't see one in MV's code?)
@caethyril Thank you! I've already added my code as a plugin so I can just add this to it. Thanks again for pointing me to the specific code I was looking for.

Also,
JavaScript:
Game_Map.prototype.isOverworld = function() {
    return this.tileset() && this.tileset().mode === 0;
};
is in rpg_objects.js

-EDIT-
It worked! Thanks again, this gives me a foothold going forward.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,050
Reaction score
1,479
First Language
EN
Primarily Uses
RMMZ
@xDRAGOONx great! :kaojoy:

And yes, but by default isOverworld doesn't expect any arguments, i.e. it's function(), not function(stuff). It just means the following two lines are equivalent:
JavaScript:
$gameMap.isOverworld(this)
$gameMap.isOverworld()
 

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
210
Reaction score
165
First Language
English
Primarily Uses
RMMV
Okay, I understand what your saying
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Oh no. That moment when you try to fix something you modified in your game, like, a year ago but didn't want to fix then, and you now have no idea what you even did. Me right now, trying to figure out why my gold window is over stretched?
LittlePIGGY wrote on atreyoray's profile.
Where are you TT^TT
We need ARP_InGameManual for MZ
Oh my gosh. Thank you, Macy's! Thank you so much! You have made me very happy!
Happy Thanksgiving everyone! What are you thankful for? I'm thankful that I no longer have PTSD, and that I get to enjoy a good meal with my mom and stepdad! It might not be the same as before COVID, but at least I still get to enjoy the holiday!

Forum statistics

Threads
105,550
Messages
1,014,568
Members
137,225
Latest member
Eryndor
Top