The RPG Maker Resource Kit

RMRK RPG Maker Creation => MV => MV Scripts Database => Topic started by: modern algebra on October 28, 2015, 02:58:24 AM

Title: [MV] Vehicle Passability for Events 1.0.0
Post by: modern algebra on October 28, 2015, 02:58:24 AM
Vehicle Passability for Events
Version: 1.0.0
Author: modern algebra
Date: 27 October 2015

Version History



Description


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

Features


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

Code: [Select]
//=============================================================================
//  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



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.
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: &&&&&&&&&&&&& on October 28, 2015, 03:06:56 AM
Jolly good show.
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: bluntsword on October 28, 2015, 04:12:11 AM
Was hoping MA would get to know Java.

Was not disappointed.

Looking forward to more!
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: Kyuukon on October 28, 2015, 03:40:36 PM
OMG! MA is back for MV! :D :D Thanks!
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: yuyu! on October 28, 2015, 03:55:34 PM
Yay! It's nice to see you on the Javascript side, too! :D
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: LoganF on October 29, 2015, 04:44:22 PM

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.
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: yuyu! on October 29, 2015, 09:10:30 PM
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
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: Acolyte on October 29, 2015, 09:44:55 PM
As someone who only knows visual basic, I envy all of you. ;9
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: yuyu! on October 29, 2015, 09:52:58 PM
I wouldn't envy anyone that has to take c++. ;9

It's  e v i l  . . .
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: &&&&&&&&&&&&& on October 29, 2015, 10:59:54 PM
Please stay on topic.
Spoiler for:
:^V
Title: Re: [MV] Vehicle Passability for Events 1.0.0
Post by: modern algebra on October 30, 2015, 12:25:12 AM
haha, thanks guys. Your enthusiasm is misplaced but inspiring.