Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=========================================================
- // Sensor SelfSwitch
- // Sensor SelfSwitch.js
- // Version: 1.2
- //=========================================================
- var Imported = Imported || {};
- Imported.LSensor = true;
- var Lyson = Lyson || {};
- Lyson.Sensor = Lyson.Sensor || {};
- /*:
- * @author Lyson
- * @plugindesc Allows events to flip a self switch when a
- * player is in range.
- *
- * @param Self Switch
- * @desc The self switch to flip when the player is in range.
- * A, B, C, or D
- * @default D
- *
- * @help
- * =============================================================================
- * What does it do?
- * =============================================================================
- *
- * This plugin activates a self switch when a player is in a certain proximity
- * of an event. It uses a notetag in the note of the event to set the proximity.
- *
- * =============================================================================
- * Usage
- * =============================================================================
- *
- * In the plugin parameters, set the self switch to be triggered on the event
- * when a player enters the range. Options are A, B, C, and D. Default is D.
- *
- * Event tags provide 2 way functionality, they will turn off the switch when
- * the player leaves the event's range.
- *
- * Comment tags only provide 1 way switching, they will NOT turn off the Self
- * Switch when the player leaves the event's range.
- *
- * -----------------------------------------------------------------------------
- * Notetags
- * -----------------------------------------------------------------------------
- *
- * These notetags go in the note box for the event or in a comment on an event
- * page.
- *
- * <Sensor: x>
- *
- * Where x is the number of tiles away that the selfswitch will be triggered.
- *
- * ----------------------------------------------------------------------------
- * =============================================================================
- */
- Lyson.Parameters = $plugins.filter(function (plugin) { return plugin.description.indexOf('<Sensor SelfSwitch>') != -1; })[0].parameters;
- Lyson.Param = Lyson.Param || {};
- Lyson.Param.SelfSwitch = String(Lyson.Parameters['Self Switch']);
- Lyson.Sensor.playerMoved = false;
- Lyson.Sensor.Game_Event_setupPage = Game_Event.prototype.setupPage;
- Game_Event.prototype.setupPage = function () {
- Lyson.Sensor.Game_Event_setupPage.call(this);
- this.setupSensor();
- };
- Game_Event.prototype.setupSensor = function () {
- this._sensorRange = 0;
- };
- Lyson.Sensor.Game_Event_update = Game_Event.prototype.update;
- Game_Event.prototype.update = function () {
- Lyson.Sensor.Game_Event_update.call(this);
- this.updateSensor();
- };
- Game_Event.prototype.updateSensor = function () {
- if (this._erased) return;
- if (!this._sensorRange) { this._sensorRange = 0 };
- if (this._sensorRange < 0) return;
- Lyson.Sensor.playerMoved = $gamePlayer.isMoving();
- if (!Lyson.Sensor.playerMoved) { return; }
- Lyson.Sensor.processEventNotetags.call(this);
- };
- Lyson.Sensor.processEventNotetags = function () {
- if (!$dataMap) {
- return;
- }
- var event = this.event();
- if (event.note) {
- var note1 = /<(?:SENSOR):[ ](\d+)>/i;
- var notedata = event.note.split(/(?:>)[ ]/);
- for (var i = 0; i < notedata.length; i++) {
- var tag = notedata[i];
- if (tag.match(note1)) {
- this._sensorRange = parseInt(RegExp.$1);
- Lyson.Sensor.basicSensor.call(this);
- }
- }
- }
- };
- Lyson.Sensor.basicSensor = function (c) {
- var selfs = Lyson.Sensor.selfSwitch;
- var inRange = Math.abs(this.deltaXFrom($gamePlayer.x));
- inRange += Math.abs(this.deltaYFrom($gamePlayer.y));
- if (inRange <= this._sensorRange) {
- selfs.call(this, true);
- } else {
- selfs.call(this, false);
- };
- };
- Lyson.Sensor.selfSwitch = function (selfs) {
- $gameSelfSwitches.setValue([this._mapId, this._eventId, Lyson.Param.SelfSwitch], selfs)
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement