Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Maliki's Random Encounter Step Options
- // MalEncounterRateOptions.js
- // version 1.5
- //=============================================================================
- /*:
- * @plugindesc ver1.5 - Allows players to set a general random encounter rate in the Options Menu.
- * @author Maliki79
- *
- * @param RateUpperLimit
- * @desc The highest percentage the Encounter Rate can reach. This number MUST be at or above 100.
- * Default: 100
- * @default 100
- *
- * @param RateLowerLimit
- * @desc The lowest percentage the Encounter Rate can reach. This number MUST be at or below 100.
- * Default: 0
- * @default 0
- *
- * @param EncounterOffset
- * @desc The value that the Encounter Rate will change when a direction or ok is pressed.
- * Default: 50
- * @default 50
- *
- * @param EncounterRateShow
- * @desc Forces Encounter rate to be shown in Options even when locked. 0 = true 1 = false
- * Default: 0
- * @default 0
- *
- * @param EncounterSpeed
- * @desc Enter an Interger higher than 0 to allow encounters to occur event when standing still.
- * Default: 0
- * @default 0
- *
- * @help Allows players to set a general random encounter rate in the Options Menu.
- * This rate can be reduced to 0 to eliminate ALL random encounters.
- * Also allows developers to lock/unlock the encounter rate directly and set
- * values to whatever they want.
- *
- * Once installed, run your game and go to Options to find the
- * Encounter Rate setting. (If EncounterRateShow is NOT set to 0, the encounter rate will NOT appear
- * on the Title Screen's Option Menu as the rate is considered locked when on the Title Screen.)
- *
- * Optional: You can set the Upper limit of the Encounter rate to any number over 100.
- * If set below, or to a non-number, it will default to 100.
- *
- * Optional: You can set the amount the Encounter Rate rises or falls via the Encounter Offset Param.
- *
- * You can set a timer to allow encounters while standing still.
- * If the param EncounterSpeed is set to a number higher than 0, encounters will be able to occur
- * even while players are not moving!
- * Increasing the number will speed up the enocounter rate.
- * Leaving it at 0 will disable this option.
- * (Other encounter rate option will still be in effect)
- *
- * SCRIPT CALLS
- *
- * $gameSystem.lockEncounterRate();
- * This call will LOCK the Encounter Rate setting at whatever number it was when called.
- * You can add a number in the () to set the rate while locking it.
- * Note: Unless EncounterRateShow is set to 0, the Encounter Rate will not show on the Option
- * Menu while locked.
- *
- * $gameSystem.unlockEncounterRate();
- * This call will allow players to change the Encounter Rate again after it hs been locked.
- * You can add a number in the () to set the rate while unlocking it.
- *
- * $gameSystem.setEncounterRate(x);
- * This call will change the Encounter Rate to any positive integer.
- * Note that the player can change the number if the Encounter Rate is not locked.
- *
- * $gameSystem.getEncounterRate();
- * This call will return the current Encounter Rate.
- */
- ConfigManager.commandEncounter = 100;
- var MalEncounterTitle = Scene_Title.prototype.create;
- Scene_Title.prototype.create = function() {
- MalEncounterTitle.call(this);
- $gameSystem._encountersLocked = true;
- }
- var MalEncounterInitialize = Game_System.prototype.initialize;
- Game_System.prototype.initialize = function() {
- MalEncounterInitialize.call(this);
- this._encountersLocked = false;
- }
- Game_System.prototype.lockEncounterRate = function(setting) {
- $gameSystem._encountersLocked = true;
- if (setting) this.setEncounterRate(setting);
- }
- Game_System.prototype.unlockEncounterRate = function(setting) {
- $gameSystem._encountersLocked = false;
- if (setting) this.setEncounterRate(setting);
- }
- Game_System.prototype.getEncounterRate = function() {
- return $gameSystem._encounterRate;
- }
- Game_System.prototype.setEncounterRate = function(setting) {
- var numb = Number(eval(setting)) || 100;
- if (numb < 0) numb = 0;
- ConfigManager['commandEncounterVolume'] = numb;
- $gameSystem._encounterRate = numb;
- }
- Object.defineProperty(ConfigManager, 'encounterRate', {
- get: function() {
- return ConfigManager.commandEncounterVolume;
- },
- set: function(value) {
- ConfigManager.commandEncounterVolume = value;
- },
- configurable: true
- });
- var Mal_Config_MakeData = ConfigManager.makeData;
- ConfigManager.makeData = function() {
- var config = Mal_Config_MakeData.call(this);
- config.encounterRate = this.encounterRate;
- return config;
- };
- var Mal_Config_applyData = ConfigManager.applyData;
- ConfigManager.applyData = function(config) {
- Mal_Config_applyData.call(this, config);
- this.encounterRate = this.readEncounter(config, 'encounterRate');
- };
- ConfigManager.readEncounter = function(config, name) {
- var value = config[name];
- if (value !== undefined) {
- return Number(value);
- } else {
- return 100;
- }
- };
- Window_Options.prototype.encounterOffset = function() {
- var num = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterOffset']) || 50;
- if (num !== undefined) {
- return Math.floor(num);
- } else {
- return 50;
- }
- };
- var Mal_Window_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
- Window_Options.prototype.addGeneralOptions = function() {
- Mal_Window_addGeneralOptions.call(this);
- if (PluginManager.parameters('MalEncounterRateOptions')['EncounterRateShow'] == 0 || $gameSystem._encountersLocked == false ) this.addCommand("Encounter Rate", 'commandEncounterVolume');
- };
- Game_Player.prototype.encounterProgressValue = function() {
- var value = $gameMap.isBush(this.x, this.y) ? 2 : 1;
- var val2 = ConfigManager.encounterRate;
- if ($gameParty.hasEncounterHalf()) {
- value *= 0.5;
- }
- if (this.isInShip()) {
- value *= 0.5;
- }
- return value * (val2 / 100.0);
- };
- ConfigManager.readEncounter = function(config, name) {
- var value = config[name];
- var limit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit']);
- var lowLimit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit']);
- if (limit < 100) limit = 100;
- if (lowLimit < 0) lowLimit = 0;
- if (value !== undefined) {
- return Number(value).clamp(lowLimit, limit);
- } else {
- return 100;
- }
- };
- Window_Options.prototype.isEncounterSymbol = function(symbol) {
- return symbol.contains('Encounter');
- };
- var Mal_Win_Options_processOk = Window_Options.prototype.processOk
- Window_Options.prototype.processOk = function() {
- var index = this.index();
- var symbol = this.commandSymbol(index);
- if (this.isEncounterSymbol(symbol) ) {
- var value = this.getConfigValue(symbol);
- var offset = this.encounterOffset();
- var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
- var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
- if (limit < 100) limit = 100;
- if ($gameSystem._encountersLocked == false){
- if (value + offset > limit && value != limit) {
- value = limit;
- } else {
- value += offset;
- }
- if (value > limit) value = lowLimit;
- this.changeValue(symbol, value);
- $gameSystem._encounterRate = value;
- } else {
- SoundManager.playBuzzer();
- }
- } else {
- Mal_Win_Options_processOk.call(this);
- }
- };
- var Mal_Win_Options_cursorRight = Window_Options.prototype.cursorRight
- Window_Options.prototype.cursorRight = function(wrap) {
- var index = this.index();
- var symbol = this.commandSymbol(index);
- if (this.isEncounterSymbol(symbol)) {
- var value = this.getConfigValue(symbol);
- var offset = this.encounterOffset();
- var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
- var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
- if (limit < 100) limit = 100;
- if ($gameSystem._encountersLocked == false){
- if (value + offset > limit && value != limit) {
- value = limit;
- } else {
- value += offset;
- }
- if (value > limit) value = lowLimit;
- this.changeValue(symbol, value);
- $gameSystem._encounterRate = value;
- } else {
- SoundManager.playBuzzer();
- }
- } else {
- Mal_Win_Options_cursorRight.call(this, wrap);
- }
- };
- var Mal_Win_Options_cursorLeft = Window_Options.prototype.cursorLeft
- Window_Options.prototype.cursorLeft = function(wrap) {
- var index = this.index();
- var symbol = this.commandSymbol(index);
- if (this.isEncounterSymbol(symbol)) {
- var value = this.getConfigValue(symbol);
- var offset = this.encounterOffset();
- var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
- var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
- if (limit < 100) limit = 100;
- if ($gameSystem._encountersLocked == false){
- if (value - offset < lowLimit && value != lowLimit) {
- value = lowLimit;
- } else {
- value -= offset;
- }
- if (value < lowLimit) value = limit;
- this.changeValue(symbol, value);
- $gameSystem._encounterRate = value;
- } else {
- SoundManager.playBuzzer();
- }
- } else {
- Mal_Win_Options_cursorLeft.call(this, wrap);
- }
- };
- var MalEncounter_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
- Scene_Load.prototype.onLoadSuccess = function() {
- MalEncounter_onLoadSuccess.call(this);
- ConfigManager['commandEncounterVolume'] = $gameSystem._encounterRate || 100;
- //$gamePlayer.encounterTick = 0;
- }
- //var MalEncounter_updateNonmoving = Game_Player.prototype.updateNonmoving;
- Game_Player.prototype.updateNonmoving = function(wasMoving) {
- if (!$gamePlayer.encounterTick) $gamePlayer.encounterTick = 0;
- if (!$gameMap.isEventRunning()) {
- if (wasMoving) {
- $gameParty.onPlayerWalk();
- this._firstStep = false;
- this.checkEventTriggerHere([1,2]);
- if ($gameMap.setupStartingEvent()) {
- return;
- }
- }
- if (this.triggerAction()) {
- return;
- }
- if ($gamePlayer.encounterTick >= 1000) {
- this.updateEncounterCount();
- $gamePlayer.encounterTick = 0;
- } else {
- if(!this._firstStep) $gamePlayer.encounterTick += 1 * Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed']));
- //console.log($gamePlayer.encounterTick);
- }
- if (wasMoving) {
- this.updateEncounterCount();
- } else {
- $gameTemp.clearDestination();
- }
- }
- };
- var MalEncounterCount = Game_Player.prototype.makeEncounterCount;
- Game_Player.prototype.makeEncounterCount = function() {
- MalEncounterCount.call(this);
- if(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed'] != 0) this._encounterCount += 3;
- this._firstStep = true;
- };
Add Comment
Please, Sign In to add comment