RMMV Turning Common Event Script into a Plugin

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
216
Reaction score
168
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
543
Reaction score
220
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,064
Reaction score
1,484
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
216
Reaction score
168
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,064
Reaction score
1,484
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
216
Reaction score
168
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

Evil7 added!


I did a bit of a remake on one of the maps, also I made a particle for jumping into the portal, and one for traveling through the portal. I'll probably add more sparkles later to embellish it. :LZSwink:
Polished the animation and added details :kaojoy:
Ami
What do you think about the Wood Bridge inside of Volcano?
Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.

Forum statistics

Threads
105,686
Messages
1,015,538
Members
137,362
Latest member
sdramose
Top