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,044
Reaction score
1,474
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,044
Reaction score
1,474
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 Profile Posts

Tomorrow is Thanksgiving, and I'm so excited! I've been exploring MZ a little, and I just downloaded Effekseer to make new animations. I have experience in 3D animation software, so I'll be pretty good at the whole "particle" thing. My first game on MZ will be Fantasy Force--starring a griffin, a dragon, and a pegasus fighting against the Dragon of Darkness.
currently listening to Driftwood Gaming streaming some MZ dev time and it's delightful! had no idea they were this entertaining, love it
In quarantine, will be tested soon. This year is really something... special.
I was at another orientation yesterday and I realized I'll be working with an old friend! We met at the local water park a few years back and it was so nice to see her again! We had a chat, and next week when I officially start, I'll see if maybe we can trade our Zoom IDs so we can talk!
I made some sideview closets for MV!
You can find them in my MV resource thread.

Forum statistics

Threads
105,512
Messages
1,014,339
Members
137,198
Latest member
mmc1980
Top