Block event interaction when X switch is on

● ARCHIVED · READ-ONLY
Started by Tigerstark 10 posts View original ↗
  1. EDIT 2: Take a look at posts #6, #7 and #8 for the answer.

    EDIT:
    Managed to get something to work (I think?) in a script call. However, whenever I try to include it in the plugin, I keep getting Cannot read property 'name' of undefined because of the $dataMap.events[this._eventId].name.match(/s{2}/) I added. Otherwise, it works fine, but it still doesn't do what I want it to do.

    Here's the script call:
    Code:
    if ($dataMap.events[this._eventId].name.match(/s{2}/))
    $gameMessage.add("Hello World")
    else
    $gameMessage.add("Guess this doesn't work?")

    And here's how I included it in the plugin:
    Code:
    Game_Player.prototype.startMapEvent = function(x, y, triggers, normal) {
        if (!$gameMap.isEventRunning()) {
            $gameMap.eventsXy(x, y).forEach(function(event) {
                if (event.isTriggerIn(triggers) && event.isNormalPriority() === normal && $gameSwitches.value(1) == false) {
                    event.start();
                }
                else if ($gameSwitches.value(1) == true && $dataMap.events[this._eventId].name.match(/s{2}/)) {
                    event.start();
                }
            });
            }
        };
    ——————————————————————————————————————
    I have looked around for such a plugin for about two days. I might have simply not entered the correct key words for the search engine to come up with what I'm looking for, or that one plugin simply doesn't exist.

    Basic idea: Similar to what Shaz provided in this thread here for VX Ace: https://forums.rpgmakerweb.com/inde...orarily-disable-all-event-interactions.86663/ but made for MV and allows usage of several switches for different situations instead of only one switch.

    How I think it would work: Switch IDs would be defined in the plugin manager, and event interaction would be completely blocked if said events do not have a specific string of characters written in a comment, the name, or the note. Also defined in the plugin manager.

    I'm aware this could be done with conditional branches, however it adds clutter that could easily pile up when you already have a bunch of other conditional branches in various events.
    Already in-dev projects would benefit immensely from this as the need to add a conditional branch to every event evaporates immediately.

    Things I would use this for include a freecam ability that lets you transfer between maps as the transfer events have a defined string of characters in them, but block any other even interaction such as talking to people since they don't have that one important string of characters.
    Another ability lets you enter a dream sort of world. It blocks transfer events, but lets you "talk" to people to intercept their thoughts, etc.
  2. And what about using an additional page and give it the correct condition to override the event instead of conditional branches?
  3. Sure, that could work. Same problem as conditional branches though. That, and I really don't want unnecessary pages everywhere, especially in simple events like transfer events.
    I'm just looking for a way to make my life easier by not achieving my goal through DIY means in which the stuff I use would most likely be required elsewhere, and then I'd have to bother around some more. I'm just a lazy person. Really.

    If Javascript is anything like Ruby then making a similar plugin like the script in the older thread would almost require no effort from people who know how to make them.

    Anyway, trying to figure it out myself meanwhile with a conditional branch script first
  4. K, figured out how to make the game prevent any sort of encounter or event while a switch is active. That was the easy part. Now, I have to figure out how to make it check the name of the event as well as make it possible for other switches to also work and affect other strings of characters.

    I've discovered a wild '$dataMap.events[].name', but I have absolutely no idea what to do with it.
  5. bump
  6. Should be able to alias Game_Event.prototype.start for this. Try out the attached plugin! Full code in spoiler below.
    Spoiler
    Code:
    //=========================================================
    // Cae_DisableEventStart.js
    //=========================================================
    
    /*:
     * @plugindesc v1.0 - Lets you prevent events from starting while a switch is on unless their name contains a particular string.
     * @author Caethyril
     *
     * @help Plugin Commands:
     *   None.
     *
     * Compatibility:
     *   Aliases start method of Game_Event.
     *
     * Terms of use:
     *   Free to use and modify.
     *
     * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     * Update log:
     *   1.0: Initial release.
     * 
     * @param Disable Switch
     * @text Disable Switch
     * @type switch
     * @desc When this switch is on, normal event interactions are disabled.
     * @default 0
     *
     * @param Exception String
     * @text Exception String
     * @type text
     * @desc If an event contains this text in its name, it will always be able to be activated.
     * @default &&
     */
    
    var Imported = Imported || {};				// Import namespace, var can redefine
    Imported.Cae_DisableEventStart = 1.0;			// Import declaration
    
    var CAE = CAE || {};					// Author namespace, var can redefine
    CAE.DisableEventStart = CAE.DisableEventStart || {};	// Plugin namespace
    
    (function(_) {
    
    'use strict';
    
    	_.params = PluginManager.parameters('Cae_DisableEventStart');		// Process user parameters
    
    	_.swID = Number(_.params['Disable Switch']);
    	_.excl = String(_.params['Exception String']);
    
    	_.Game_Event_start = Game_Event.prototype.start;
    	Game_Event.prototype.start = function() {
    		if ((_.swID > 0 && !$gameSwitches.value(_.swID)) || this.event().name.contains(_.excl)) {
    			_.Game_Event_start.call(this);
    		}
    	};
    
    })(CAE.DisableEventStart)
  7. Thank you, caethyril. Your plugin is almost everything I requested, however it only has one switch and string that I could utilize. So, I decided to modify it somewhat, and so far it has been working without any problems.
    Spoiler
    _.swID1 = Number(_.params['Disable Switch 1']);
    _.excl1 = String(_.params['Exception String 1']);

    _.swID2 = Number(_.params['Disable Switch 2']);
    _.excl2 = String(_.params['Exception String 2']);

    _.Game_Event_start = Game_Event.prototype.start;
    Game_Event.prototype.start = function() {
    .........if ($gameSwitches.value(_.swID1) == true || $gameSwitches.value(_.swID2) == true) {
    ...............if ($gameSwitches.value(_.swID1) == true && this.event().name.contains(_.excl1)) {
    ...................._.Game_Event_start.call(this);
    ...............}
    ...............else if ($gameSwitches.value(_.swID2) == true && this.event().name.contains(_.excl2)) {
    ...................._.Game_Event_start.call(this);
    ...............}
    .........}
    .........else {
    .............. _.Game_Event_start.call(this);
    .........}
    };
    Only one of these two switches is supposed to be on at any time, so hypothetically this should work perfectly.
    If there's anything wrong with my edit that might break some things, please tell me.

    A question I have: why did you utilize this "_.swID > 0 && !$gameSwitches.value(_.swID)" in your if condition. Isn't just typing "$gameSwitches.value(_.swID) == true", as seen in my edit, far simpler? Or is it trying to accomplish an entirely different objective?
  8. You're welcome, and your edit looks fine! ^_^

    My check for _.swID > 0 was quite arbitrary actually...mostly just to make sure a switch has been set in the parameters, but you wouldn't be using the plugin if you hadn't set a switch. Force of habit, I guess. xP

    As far as I know $gameSwitches.value(_.swID) and $gameSwitches.value(_.swID) == true are equivalent if the switches are always Boolean (true or false), which they should be in this case:
    Code:
    Game_Switches.prototype.value = function(switchId) {
        return !!this._data[switchId];
    };
    So other than my arbitrary _.swID > 0 check, I'd expect our methods to achieve the same thing. =) For reference, the not operator ! coerces the argument to boolean as well (!! for no inversion, as seen in the excerpt above). The == operator works slightly differently when comparing different variable types; here's MDN's table on the topic:
    https://developer.mozilla.org/en-US...comparisons_and_sameness#Loose_equality_using
  9. I see. Thank you.
  10. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.