Main Menu
  • Welcome to The RPG Maker Resource Kit.

[MV] Vehicle Passability for Events 1.0.0

Started by modern algebra, October 28, 2015, 02:58:24 AM

0 Members and 1 Guest are viewing this topic.

modern algebra

Vehicle Passability for Events
Version: 1.0.0
Author: modern algebra
Date: 27 October 2015

Version History




  • <Version 1.0.0> 2015-10-27 - Original Release

Description



Set up events that are bound by the passability rules of boats, ships, or airships.

Features


  • Can make events that move randomly but restrict themselves to the water
  • Easy to set up through first-line comments
  • Can change vehicle passability for each page of an event

Instructions

Save the script in your plugins folder and import it through the Plugin Manager.

To set vehicle passability for an event, you must set the first command for an event page to be a comment which includes one of the following codes:

        \vehicle[boat]
        \vehicle[ship]
        \vehicle[airship]

The vehicle type is determined on a page-by-page basis. If a vehicle event should update to a new page, it will need to have a new vehicle code or else it will revert to normal passability.

Plugin



You can download the .js file from Pastebin: http://pastebin.com/RCVr2D4f


//=============================================================================
//  Vehicle Passability for Events
//  Version: 1.0.0
//  Date: 27 October 2015
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*:
* @plugindesc Set up events that are bound by the passability rules of boats, ships, or airships
* @author Modern Algebra (rmrk.net)
* @help This plugin does not have any plugin parameters. It is setup through
* comments in an event.
*
* To set vehicle passability for an event, you must set the first command for
* an event page to be a comment which includes one of the following codes:
*
*      \vehicle[boat]
*      \vehicle[ship]
*      \vehicle[airship]
*
* The vehicle type is determined on a page-by-page basis. If a vehicle event
* should update to a new page, it will need to have a new vehicle code or
* else it will revert to normal passability.
*/
//=============================================================================

(function() {
   
    var _Game_Event_initMembers =
            Game_Event.prototype.initMembers;
    Game_Event.prototype.initMembers = function() {
        _Game_Event_initMembers.call(this);
        this._maVehicleType = ''; // Initialize _maVehicleType
    };

    var _Game_Event_setupPageSettings =
            Game_Event.prototype.setupPageSettings;
    Game_Event.prototype.setupPageSettings = function() {
        _Game_Event_setupPageSettings.call(this)
        var comments = this.maepoCollectCommentsAt(0);
        // Match an integer in \vehicle[x]
        var rpatt = /\\vehicle\s*\[\s*(boat|ship|airship)\s*\]/i;
        var match = rpatt.exec(comments);
        if (match) { // If there is a match (match is not null)
            vtype = match[1].toLowerCase();
            this._maVehicleType = vtype;
        } else {
            this._maVehicleType = '';   
        }
    };
   
    // Selects all comment lines at index i in the list
    Game_Event.prototype.maepoCollectCommentsAt = function(i) {
        var comments = '';
        var list = this.list(); // List of event commands for current page
        // Select only comment lines
        while (i < list.length && (list[i].code === 108 || list[i].code === 408)) {
            comments = comments + list[i].parameters[0];
            i++;
        }
        return comments
    };

    // For consistency, code below uses same structure as in Game_Player
    var _Game_Event_isMapPassable =
            Game_Event.prototype.isMapPassable;   
    Game_Event.prototype.isMapPassable = function(x, y, d) {
        var vehicle = this.vehicle();
        if (vehicle) {
            return vehicle.isMapPassable(x, y, d);
        } else {
            return _Game_Event_isMapPassable.call(this, x, y, d);
        }
    };
   
    Game_Event.prototype.vehicle = function() {
        return $gameMap.vehicle(this._maVehicleType);
    };
   
})();


Credit




  • modern algebra

Support



Post in this thread if you have any comments or questions. It is perfectly fine to post here even if this topic has not been posted in for a very long time.

Please do not message me privately, as any concerns you have are likely shared by others and they will benefit from our correspondence being public. Additionally, I am often absent, and posting publicly will allow other members to assist you when I am unable to do so quickly.

Author's Notes



So, it turns out that I know nothing about javascript. This plugin is so simple that it is barely even useful, and I still feel like I coded it poorly.

Terms of Use



You are welcome to use this script in any project of yours, whether it is commercial or non-commercial. There is no need to credit me, and please feel free to modify the plugin in whatever ways suit your project.

Basically, my plugin is your plugin, but please do not re-post this plugin or any modified version of it on another forum or website.

&&&&&&&&&&&&&

&&&&&&&&&&&&&&&&

bluntsword

Was hoping MA would get to know Java.

Was not disappointed.

Looking forward to more!

Kyuukon


やれやれだぜ。

yuyu!

Yay! It's nice to see you on the Javascript side, too! :D

[Spoiler=My Games and Art]
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]

[/Spoiler]

LoganF

Quote from: modern algebra on October 28, 2015, 02:58:24 AM

So, it turns out that I know nothing about javascript. This plugin is so simple that it is barely even useful, and I still feel like I coded it poorly.


I know exactly how you feel. I don't remember RGSS/Ruby being quite as, er, fun as this.

Still, any progress is progress and as time goes on you can only get better and feel more confident. That's what I keep telling myself at least.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

yuyu!

Quote from: modern algebra on October 28, 2015, 02:58:24 AM
So, it turns out that I know nothing about javascript. This plugin is so simple that it is barely even useful, and I still feel like I coded it poorly.

It definitely looks pretty, though (all of your scripts do)! :D It'll be that much easier to go back later and simplify stuff.

Half of the other students in my c++ class produce some pretty messy code. T-T

[Spoiler=My Games and Art]
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]

[/Spoiler]

Acolyte

As someone who only knows visual basic, I envy all of you. ;9

yuyu!

I wouldn't envy anyone that has to take c++. ;9

It's  e v i l  . . .

[Spoiler=My Games and Art]
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]

[/Spoiler]

&&&&&&&&&&&&&

Please stay on topic.
[spoiler]:^V[/spoiler]
&&&&&&&&&&&&&&&&

modern algebra

#10
haha, thanks guys. Your enthusiasm is misplaced but inspiring.