RMMV Turning Common Event Script into a Plugin

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
240
Reaction score
196
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
624
Reaction score
269
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,227
Reaction score
1,635
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
240
Reaction score
196
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,227
Reaction score
1,635
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
240
Reaction score
196
First Language
English
Primarily Uses
RMMV
Okay, I understand what your saying
 

Latest Threads

Latest Posts

Latest Profile Posts

Looking back at some sketches, and game design documents on my PC dated summer of 2015. I started development with the release of MZ, but in 2015, I felt a strong desire to make a game out of the blue. I remember feeling sad for no apparent reason, and all these ideas rushed into my head. Now that I think about it, since that day, everything has become easier to do on my PC . . . it’s very creepy.
Everything's going to be alright! We're all in this together. <3
Aaaaannd published my game's tech demo. :D

Feel free to download and play it. And give feedback!
Hey everyone, we know that the edit bar is missing. We're working on it. You can talk about it in the announcement here: https://forums.rpgmakerweb.com/index.php?threads/forum-errors-missing-edit-bar-etc.132715/
So, explain why we can no longer use BBC code or smilies in our posts? This sparks much sadness...

Forum statistics

Threads
107,794
Messages
1,032,254
Members
139,941
Latest member
Finley
Top