Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // SilvEventChance.js
- // Version: 1.00
- //=============================================================================
- /*:
- * @plugindesc v1.00 Randomizes events through disabling specific marked events. <SilvEventChance>
- * @author Silver
- *
- * @param -- General --
- *
- * @param Default Regular Section Chance
- * @desc The chance for NOT disabling events for regular sections when no chance-notetag was found. Value must be between 0.0 and 1.0 (inclusive).
- * @default 0.5
- *
- * @help
- * Note that the exclusive-section is never disabled for the map if there is only 1 exclusive section for that map.
- *
- * Events disabled through self-switches and exclusive-events are saved between maps and saving&loading the game.
- * Regular sections are randomized each time the player visits the map again or loads a savegame.
- *
- *--------------------------------------
- * Event Notetags
- *--------------------------------------
- * <evc_chance:value> // value 0-100 or 0.0 - 1.0. both are valid and the same
- * <evc_section:value>
- * <evc_excl_section:value>
- * <evc_disable_mode:value1, value2, value3> // value1: switch/erase, value2: A, B, C or D, value3: ON/OFF
- *
- * Examples:
- * <evc_chance:50> // 50% chance to be disabled. If evc_section is included then this is the chance for the section instead. Does not apply to exclusive sections.
- * <evc_section:towns> // Only disable when the town-section is disabled
- * <evc_excl_section:towns> // only 1 exclusive section can be enabled at any time, all other events tagged with a different section will be disabled
- * <evc_disable_mode:switch A> // switch can be either "switch A/B/C/D" or "erase" (default: erase)
- * <evc_disable_mode:switch A ON> // The last value can be ON or OFF. If the 3rd value is omitted, it will default to "ON".
- *
- * Examples for an exclusive-section:
- * <evc_excl_section:towns><evc_disable_mode:switch A>
- * <evc_excl_section:towns><evc_disable_mode:switch B OFF>
- *
- * Examples for a regular section:
- * <evc_section:towns1><evc_chance:90>
- * <evc_section:towns3>
- * <evc_section:towns4><evc_disable_mode:switch A ON>
- *
- * Example for chancing a single event:
- * <evc_chance:75>
- *--------------------------------------
- * Version History:
- *--------------------------------------
- * v.1.00 (22 December 2015)
- * - First Release
- *
- */
- // Imported
- var Imported = Imported || {};
- Imported.SILV_EventChance = 1.00;
- // #Parameters
- var Silv = Silv || {};
- Silv.EvChance = Silv.EvChance || {};
- Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvEventChance>'); })[0].parameters;
- // General
- Silv.EvChance.DefaultRegularSectionChance = parseFloat(Silv.Parameters['Default Regular Section Chance']);
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Utilities
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // chance parameter: between 0.0 and 1.0
- Silv.EvChance.Chance = function(chance)
- {
- return (Math.random() < chance);
- };
- Silv.EvChance.DisableEv = function(mapId, event, storedEvent)
- {
- if (storedEvent.disableMode === 'erase')
- {
- event.erase();
- }
- else
- {
- $gameSelfSwitches.setValue([mapId, storedEvent.id, storedEvent.disableModeLetter], storedEvent.disableModeValue);
- }
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Your Code
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Game_Map.prototype.initEVCSections = function()
- {
- this.sections = {};
- this.sections.regular = {};
- this.sections.regularArray = [];
- this.sections.exclusive = {};
- this.sections.exclusiveArray = [];
- };
- var alias_silv_evChance_Game_Map_setup = Game_Map.prototype.setup;
- Game_Map.prototype.setup = function(mapId)
- {
- // Call alias
- alias_silv_evChance_Game_Map_setup.apply(this, arguments);
- // Init custom-map-variables
- this.initEVCSections();
- // Loop through all map-events
- var events = this.events();
- for (var evIdx=0; evIdx<events.length; evIdx++)
- {
- var event = events[evIdx];
- var storedEvent = { id:event._eventId, disableMode:'erase' };
- //------------------------------------------------------------------------------------------------------------------------------------
- // Disable mode
- //------------------------------------------------------------------------------------------------------------------------------------
- if ('evc_disable_mode' in $dataMap.events[storedEvent.id].meta)
- {
- var disableModeData = $dataMap.events[storedEvent.id].meta.evc_disable_mode.split(' ');
- // Sanity Check
- if (disableModeData.length < 2) { throw new Error('Disablemode expects 2 values, the "switch" and the variable to switch (A, B, C or D). Exmaple: "switch A". Received value: ' + $dataMap.events[storedEvent.id].meta.evc_disable_mode); }
- // Check for switch-disable-mode
- if (disableModeData[0].toLowerCase() === 'switch')
- {
- storedEvent.disableMode = 'switch';
- storedEvent.disableModeLetter = disableModeData[1].toUpperCase();
- if (disableModeData.length >= 3)
- {
- storedEvent.disableModeValue = (disableModeData[2].toUpperCase() === 'ON');
- }
- else
- {
- storedEvent.disableModeValue = true;
- }
- }
- }
- //------------------------------------------------------------------------------------------------------------------------------------
- // Process Notetags
- //------------------------------------------------------------------------------------------------------------------------------------
- if ('evc_excl_section' in $dataMap.events[storedEvent.id].meta) // Exclusive section
- {
- var sectionName = $dataMap.events[storedEvent.id].meta.evc_excl_section;
- if (typeof this.sections.exclusive[sectionName] === 'undefined')
- {
- this.sections.exclusive[sectionName] = { enabled:false, events:[storedEvent] };
- this.sections.exclusiveArray.push(this.sections.exclusive[sectionName]);
- }
- else
- {
- this.sections.exclusive[sectionName].events.push(storedEvent);
- }
- }
- else if ('evc_section' in $dataMap.events[storedEvent.id].meta) // Regular section
- {
- var sectionName = $dataMap.events[storedEvent.id].meta.evc_section;
- if (typeof this.sections.regular[sectionName] === 'undefined')
- {
- this.sections.regular[sectionName] = { enabled:false, chance:Silv.EvChance.DefaultRegularSectionChance, events:[storedEvent] };
- this.sections.regularArray.push(this.sections.regular[sectionName]);
- }
- else
- {
- this.sections.regular[sectionName].events.push(storedEvent);
- }
- // Section Chance
- if ('evc_chance' in $dataMap.events[storedEvent.id].meta)
- {
- var chance = parseFloat( $dataMap.events[storedEvent.id].meta.evc_chance);
- this.sections.regular[sectionName].chance = ((chance <= 1) ? chance : chance / 100.0); // Only add a chance between 0.0 and 1.0. So convert values 1.01 - 100.0 to fit this range.
- }
- }
- else if ('evc_chance' in $dataMap.events[storedEvent.id].meta) // Chance (no section)
- {
- var chance = parseFloat( $dataMap.events[storedEvent.id].meta.evc_chance);
- var chance = ((chance <= 1) ? chance : chance / 100.0); // Only add a chance between 0.0 and 1.0. So convert values 1.01 - 100.0 to fit this range.
- if (Silv.EvChance.Chance(chance)) { Silv.EvChance.DisableEv(mapId, event, storedEvent); }
- }
- };
- //------------------------------------------------------------------------------------------------------------------------------------
- // Enable a random exclusive section
- //------------------------------------------------------------------------------------------------------------------------------------
- if (this.sections.exclusiveArray.length > 0)
- {
- var randomExclusiveIdx = Math.floor(Math.random() * this.sections.exclusiveArray.length);
- this.sections.exclusiveArray[randomExclusiveIdx].enabled = true;
- // Now process the exclusive sections
- for (var sectionIdx=0; sectionIdx<this.sections.exclusiveArray.length; sectionIdx++)
- {
- var section = this.sections.exclusiveArray[sectionIdx];
- if (!section.enabled)
- {
- for (var sectionEventIdx=0; sectionEventIdx<section.events.length; sectionEventIdx++)
- {
- var storedEvent = section.events[sectionEventIdx];
- Silv.EvChance.DisableEv(mapId, this.event(storedEvent.id), storedEvent);
- }
- }
- }
- }
- //------------------------------------------------------------------------------------------------------------------------------------
- // Now process the regular sections
- //------------------------------------------------------------------------------------------------------------------------------------
- for (var sectionIdx=0; sectionIdx<this.sections.regularArray.length; sectionIdx++)
- {
- var section = this.sections.regularArray[sectionIdx];
- section.enabled = Silv.EvChance.Chance(section.chance);
- if (!section.enabled)
- {
- for (var sectionEventIdx=0; sectionEventIdx<section.events.length; sectionEventIdx++)
- {
- var storedEvent = section.events[sectionEventIdx];
- Silv.EvChance.DisableEv(mapId, this.event(storedEvent.id), storedEvent);
- }
- }
- }
- //------------------------------------------------------------------------------------------------------------------------------------
- this.refreshTileEvents();
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // This is the end of this awesome script!
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement