查看: 5510|回复: 2

[交流讨论] 計時器 怎麼做時間到了會觸發事件?

[复制链接]
梦石
0
星屑
497
在线时间
266 小时
注册时间
2015-12-8
回帖
729
发表于 2015-12-30 14:01:27 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
做一個 逃離火災的事件 只是如果把計時器判斷丟在地圖上 設定自動運行 (判斷時間小於1秒) 人物就會卡住整個不動
梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
回帖
403
发表于 2015-12-30 14:10:28 | 显示全部楼层
事件第一页:
设为自动运行
开始定时器
独立开关A=on
事件第二页:
设为并行
独立开关A打钩
操作变量:#0001计时器的值=定时器
条件分歧:0001 计时器的值<1
设置玩家移动路线:玩家(等待) 等待999帧
分歧结束
  点我进入    
       ↓      
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2015-12-30 15:52:10 | 显示全部楼层
Multi Timers

Plugin commands are:
AddTimer key seconds command
DeleteTimer key
HasTimer key switchId
TimeLeft key variableId

key is any text/number string without spaces, that uniquely identifies the timer, and can be used later to cancel/delete it, see if it is running, and how much time is left. Using the same key in subsequent AddTimer plugin commands replaces the existing timer with the newest one.
seconds is the number of seconds for the timer to count down.
command is the command to run after countdown completes. This can be any command to run, but would normally be turning a switch on or off, setting a self switch, or changing a variable.
switchId is the switch id to be turned on if there is a timer with the specified key.
variableId is the variable id to be set to the number of seconds remaining on the timer. If there is no timer with the specified key, the variable will be set to 0.

Keywords that can be used anywhere in the plugin command are:
<thismap> - current map's id
<thisevent> - current event's id
\setSS - set a self switch - format is \setss([map, event, 'A'], true)
\ss - the value of a self switch - format is \ss([map, event, 'A'])
\setS - set a switch - format is \sets(switchId, true)
\s - the value of a switch - format is \s(switchId)
\setV - set a variable - format is \setv(variableId, value)
\v - the value of a variable - format is \v(variableId)

See plugin documentation for examples



Multi Timers//=============================================================================
// Multi Timers
// by Shaz
// Last Updated: 2015.11.14
//=============================================================================

/*:
* @plugindesc Allows more than one timer running at once, with custom commands
* @author Shaz
*
* @help
* This plugin allows you to set multiple timers at once, along with a command
* to be executed after the timer expires.  There is no timer display.
*
* Plugin Commands:
*
* AddTimer key seconds command - sets a timer with key
* DeleteTimer key - deletes timer with key
* HasTimer key switchId - turns switch on if a timer with that key is active
* TimeLeft key varId - sets a variable to the number of seconds remaining
*
* key = any numbers/text (no spaces) to identify unique timers
* seconds = seconds to run
* command = command to run on expiry (may be any command, and include spaces)
* switchId = id of switch to set on in HasTimer call if timer exists
* varId = id of variable to set to seconds remaining on timer
*
* The following codes can be used and substituted as follows:
* <thismap> - id of current map
* <thisevent> - id of current event
* \setSS - set self switch
* \setS - set switch
* \setV - set variable
* \ss - self switch value
* \s - switch value
* \v - variable value
*
* Examples:
* addTimer opendoor 300 \sets(10, true)
*    sets a timer for 5 minutes (300 seconds) to turn on switch 10, which
*    controls the opening of a door
* addTimer eggsHatched 600 \setv(8, \v(8) + 1)
*    sets a timer for 10 minutes (600 seconds) to increment variable 8 by 1,
*    which controls how many eggs have hatched
* addTimer <thismap>.<thisevent>.A 180 \setss([<thismap>, <thisevent>, 'A'], true)
*    sets a timer for 3 minutes to turn the current event's self switch A on
*    the name/key of the timer, if the event is EV008 on map 3, will be 3.8.A
* deleteTimer opendoor
*    cancels the timer previously called opendoor (case insensitive)
* hasTimer <thismap>.<thisevent>.A 15
*    if run on EV008 on map 3, turns switch 15 on if there is a timer for 3.8.A
* timeLeft eggsHatched 5
*    sets variable 5 to the number of seconds remaining before an egg hatches
*
*/

(function() {
  var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function(command, args) {
    switch(command.toUpperCase()) {
      case 'ADDTIMER':
        args = this.subst(args);
        key = args.shift();
        seconds = parseInt(args.shift());
        command = args.join(' ');
        $gameTimer.addTimer(key, seconds, command);
        break;
      case 'DELETETIMER':
        key = this.subst(args);
        $gameTimer.deleteTimer(key);
        break;
      case 'HASTIMER':
        args = this.subst(args);
        key = args.shift();
        switchId = parseInt(args.shift());
        $gameSwitches.setValue(switchId, $gameTimer.hasTimer(key));
        break;
      case 'TIMELEFT':
        args = this.subst(args);
        key = args.shift();
        varId = parseInt(args.shift());
        timeLeft = $gameTimer.hasTimer(key);
        $gameVariables.setValue(varId, timeLeft ? timeLeft : 0);
        break;
      default:
        _Game_Interpreter_pluginCommand.call(this, command, args);
    }
  };

  Game_Interpreter.prototype.subst = function(args) {
    args = args.join(' ');
    args = args.replace(/<thismap>/gi, this._mapId.toString());
    args = args.replace(/<thisevent>/gi, this._eventId.toString());
    args = args.replace(/\\setSS/gi, '$gameSelfSwitches.setValue');
    args = args.replace(/\\setV/gi, '$gameVariables.setValue');
    args = args.replace(/\\setS/gi, '$gameSwitches.setValue');
    args = args.replace(/\\SS/gi, '$gameSelfSwitches.value');
    args = args.replace(/\\V/gi, '$gameVariables.value');
    args = args.replace(/\\S/gi, '$gameSwitches.value');
    return args.split(' ');
  };

  var _Game_Timer_initialize = Game_Timer.prototype.initialize;
  Game_Timer.prototype.initialize = function() {
    _Game_Timer_initialize.call(this);
    this.initTimer();
  };

  Game_Timer.prototype.initTimer = function() {
    if (!this._timers) {
      this._timers = {};
    }
  };

  var _Game_Timer_update = Game_Timer.prototype.update;
  Game_Timer.prototype.update = function(sceneActive) {
    _Game_Timer_update(this, sceneActive);
    if (sceneActive && this._timers) {
      keys = Object.keys(this._timers);
      keys.forEach(function(timer) {
        this._timers[timer][0]--;
        if (this._timers[timer][0] === 0) {
          eval(this._timers[timer][1]);
          this.deleteTimer(timer);
        }
      }.bind(this));
    }
  };

  Game_Timer.prototype.addTimer = function(key, seconds, command) {
    this.initTimer();
    this._timers[key.toUpperCase()] = [seconds * 60, command];
  };

  Game_Timer.prototype.deleteTimer = function(key) {
    key = key.toUpperCase();
    if (this._timers && this._timers[key]) {
      delete this._timers[key.toUpperCase()];
    }
  };

  Game_Timer.prototype.hasTimer = function(key) {
    key = key.toUpperCase();
    if (this._timers && this._timers[key]) {
      return Math.floor(this._timers[key][0] / 60);
    } else {
      return null;
    }
  };
})();
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部