设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 63|回复: 0

[转载发布] JK Preserve Map Event States

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8259

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30525
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39678

    灌水之王

    发表于 6 天前 | 显示全部楼层 |阅读模式

    JK Preserve Map Event States v1.1



    Author: Pirobi



    Introduction


            Normally in RPG Maker, if you have an event with multiple pages, the event will automatically switch to the highest page # that has its conditions fulfilled. For example, if you have an event that disappears after a switch turns on, it will disappear as soon as that switch turns on.


            Sometimes, this behavior is not desired. What if you have an npc that will disappear when it becomes night (he leaves to go to bed)? It would become jarring to see that event suddenly disappear. This plugin aims to resolve this issue.


    Features


            The plugin keeps track of switch and/or variable IDs that you want to control to prevent the above behavior. The event pages using these variables/switches as their conditions will only become active when the player changes maps. Going back to the above example: If you have a switch that sets to true when it is nighttime, and this plugin is tracking that switch, the npc will not disappear off the map immediately when the switch is set to true, instead disappearing after you leave the map and come back to it, or use a command(see Plugin Commands).


    How to Use


            Add the plugin to your plugins list. Then, add the variable and/or switch IDs that you wish to track. (i.e. 1    or    1,2,3,4,. . .)


            Now, when you go through the game, if a switch changes value that is in the tracking list, the game will flag it as having changed. Events that use that switch in their event pages will not update as long as you are on the same map.


    NEW in 1.1! 


            You can now have events on the map that ignore this plugin, essentially behaving as if you don't have this plugin.


            To do this, add the following notetag at the END of the object's note box:


            <AllowStateChange>


    Plugin Commands


            If you want a switch or variable to resume normal behavior while the player is still on that map, use one of the following commands:


    ResetVars - This will Clear the list of flagged variables


    ResetSwitches - Same as above, except for switches


    ResetVars id1 id2 . . . - This will remove the specified variables(by ID) from the list of flagged variables.


    ResetSwitches id1 id2 . . . - Same as above, except for switches


            Using these plugin commands will cause events to update normally(see Things to Consider), so even if an event page would not change because of the tracked switch, using the command will then allow the page to change.


    Demo


    Download the Demo Here


    Things to Consider


    • This doesn't prevent the value of the switch or variable changing. The values will still change, but the event pages won't update if their conditions become true/false with them.
    • This doesn't consider Self Switches, Items, or Actors in the condition pages for events. They will function the same.
    • This doesn't consider switches or variables that are changed by script call. Only switches/variables changed using the event commands (Control Switches/Variables).
    • Currently, this does not force events to immediately refresh after using the plugin commands.

                                      If you reset switch 1, and then, for example, Self Switch A is activated, then the events using switch 1 will process normally. I might fix this in a future update to auto-refresh.




    Script

    Spoiler//:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
    // JK_PreserveMapEventStates.js v1.1
    //:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
    /*:
      * @plugindesc Have certain event pages only update on map load. <JKMap>
      * @author Pirobi

      * @param SwitchesToCheck
      * @desc The switch(es) to keep track of. (i.e. 1 or 1,2,3,...)
      * @default

      * @param VarsToCheck
      * @desc The variable(s) to keep track of. (i.e. 1 or 1,2,3,...)
      * @default

      * @help Normally, if you change the value of a switch, any event
        pages on the map that use that switch will immediately switch to
        that page if the condition is true.
        It can be jarring to have people appear on the map
        suddenly if using a time-based system, for example.
        This plugin aims to make it so if an event's page would change
        due to a switch/variable making the page active,
        the event page won't be updated until you leave and re-enter the map.

        NOTE: If you are checking if a switch is activated, or checking if a
        variable is a specific value, it WILL STILL UPDATE even though the
        variable/switch is being tracked.

        This only prevents EVENT PAGES from activating due to the Switch/Variable!
        Switches/Variables WILL STILL CHANGE VALUE!!!!!!!!

        In addition, this also does not take into account variables or switches
        that were changed by script(i.e. not through the event commands)!

        This also does not take into account other page conditions
        (Self Switch, Item, Actor). These will still perform as normal.

        :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
        Instructions For Use:
        :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
        Just set the variables/switches that the plugin will keep track of,
        and you are good to go!

        NEW in 1.1: If you want an event to ignore this script, add
        the following to the note box of the event:

        <AllowStateChange>

        :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
        Plugin Commands:
        :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:

        ResetVars
        This will clear the List of Variables that changed while on the map.

        ResetVars id1 id2 . . .
        This will remove the specified Variable Ids from the list of changed
        variables.

        ResetSwitches
        This will clear the list of Switches that changed while on the map.

        ResetSwitches id1 id2 . . .
        This will remove the specified Switch Ids from the list of changed
        switches.

        You can use these to basically force the original event behavior.
        After the command is called, the events will all update again, so
        Any events that were flagged to not change will now change.

            :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
            Updates
            :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
            -v1.1: Added <AllowStateChange> notetag to have events that ignore this script.
            -v1.0: Initial Version

        :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
         Copyright Information
        :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
        Copyright 2016, JK Software

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

           http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
        */

        var Imported = Imported || {};
        var JKMap = JKMap || {};

        //:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
        //JKMap
        //:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
        (function($){
          "use strict";
          var parameters = $plugins.filter(function(plugin){return plugin.description.contains('<JKMap>')})
          if(parameters.length === 0){
            throw new Error("Couldn't find parameters.");
          }
          $.Parameters = parameters[0].parameters;
          $.Param = {};

          $.VariableList = $.Parameters.VarsToCheck.split(",") || [];
          $.SwitchList = $.Parameters.SwitchesToCheck.split(",") || [];

          $.MapVarsChanged = {};
          $.MapSwchsChanged = {};
          $.CurrentMap = null;
        })(JKMap);

      //When the switch value is changed through an event
      //And the switch is a part of the list of switches to watch,
      //Add the switch to the list of switches changed.
        var JKSwitchChanged = Game_Interpreter.prototype.command121;
        Game_Interpreter.prototype.command121 = function(){
          var rv = JKSwitchChanged.call(this);
          for(var i = this._params[0]; i <= this._params[1]; i++){
            if(JKMap.SwitchList.contains(String(i))){
              JKMap.MapSwchsChanged = true;
            }
          }
          //console.warn(JKMap.MapSwchsChanged);
          return rv;
        };


          //When the variable value is changed through an event
          //And the variable is a part of the list of variables to watch,
          //Add the variable to the list of variables changed.
        var JKVarChanged = Game_Interpreter.prototype.command122;
        Game_Interpreter.prototype.command122 = function(){
          var rv = JKVarChanged.call(this);
          for(var i = this._params[0]; i <= this._params[1]; i++){
            if(JKMap.VariableList.contains(String(i))){
              JKMap.MapVarsChanged = true;
            }
          }
          //console.warn(JKMap.MapVarsChanged);
          return rv;
        };

    //When the player enters a new map, clear the list of vars/switches
    //That were changed on the previous map.
        var JKLoadMap = DataManager.loadMapData;
        DataManager.loadMapData = function(mapId){
          JKLoadMap.call(this, mapId);
          if(JKMap.CurrentMap === null) JKMap.CurrentMap = mapId;
          else if(mapId !== JKMap.CurrentMap){
            JKMap.MapSwchsChanged = {};
            JKMap.MapVarsChanged = {};
            JKMap.CurrentMap = mapId;
          }
        };

    //When checking if an event page should be selected, add an
    //Additional condition to check if the variable/switches used
    //On the page did NOT change while the player was on the map
    //I.E. This should return true only if the switch/variables
    //On the page meet the conditions AND they did not meet
    //Conditions while the player was still on the map.
        var JKMeetsConditions = Game_Event.prototype.meetsConditions;
        Game_Event.prototype.meetsConditions = function(page){
            var meetsConditions = JKMeetsConditions.call(this, page);
            return meetsConditions && (this.event().meta.AllowStateChange ||
              this.pageCondChangedOnSameMap(page) === false);
        };

    //Custom function to check if the switches/variables on this event page
    //Were changed while on the map.
    //When the player enters a new map, MapSwchsChanged and MapVarsChanged
    //Will both reset.
        Game_Event.prototype.pageCondChangedOnSameMap = function(page){
          var c = page.conditions;
          var swchKeys = Object.keys(JKMap.MapSwchsChanged);
          var varKeys = Object.keys(JKMap.MapVarsChanged);
          var changedOnSameMap =
          (
            swchKeys !== null &&
            varKeys !== null &&
            (
              (c.switch1Valid && swchKeys.contains(String(c.switch1Id))) ||
              (c.switch2Valid && swchKeys.contains(String(c.switch2Id))) ||
              (c.variableValid && varKeys.contains(String(c.variableId)))
            )
          )
          return changedOnSameMap;
        };

    //When determining which page to use,
    //Either take the page that meets conditions and wasn't changed on the same map,
    //(An event appearing because the page is now true)
    //OR
    //The current page being displayed whose conditions changed on the same map.
    //The event disappearing because the page is now false).
        Game_Event.prototype.findProperPageIndex = function() {
            var pages = this.event().pages;
            for (var i = pages.length - 1; i >= 0; i--) {
                var page = pages;
                  if(this.event().meta.AllowStateChange){
                    if(this.meetsConditions(page)){
                      return i;
                    }
                  }
                  else if (this.meetsConditions(page) || (i === this._pageIndex && this.pageCondChangedOnSameMap(page))) {
                    return i;
                  }
            }
            return -1;
        };

        var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
        Game_Interpreter.prototype.pluginCommand = function(command, args){
          switch(command){
            case "ResetVars":
              if(args.length > 0){
                for(var i = 0; i < args.length; i++){
                  delete JKMap.MapVarsChanged[args];
                }
              }
              else{
                JKMap.MapVarsChanged = {};
              }
              break;
            case "ResetSwitches":
              if(args.length > 0){
                for(var i = 0; i < args.length; i++){
                  delete JKMap.MapSwchsChanged[args];
                }
              }
              else{
                JKMap.MapSwchsChanged = {};
              }
              break;
            default:
              _Game_Interpreter_pluginCommand.call(this, command, args);
              break;
          }
        };

    Imported["JKMap"] = 1.1;










    FAQQ: Can I use this plugin for my commercial game?A: Yes, you can! Please be sure to check the licensing information, either in the script or below. And be sure to let me know if you do use it (a copy of the game would be nice too!)


            Q: I'm running into [insert bug/error here], what do I do?


            A: Please report any problems, suggestions, or comments here in this thread, or send me a pm. I will do my best to keep working on the plugin to make it more beautiful, optimized, etc.


    Credit And Thanks


            - Pirobi(me)


            - Liquidize


            - JK Software



    本贴来自国际rpgmaker官方论坛作者:Pirobi处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/jk-preserve-map-event-states.72540/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 18:50 , Processed in 0.117871 second(s), 51 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表