Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // RPG Maker MZ - Maliki's Encounter Conditions v1.0
- //=============================================================================
- /*:
- * @target MZ
- * @plugindesc Provides deeper control on what enemy troops are encountered by the player
- * @author Maliki79
- *
- * @help MalMZ_EncounterConditions.js
- *
- * This plugin enables devs to set conditional evals for random encounter troop battles.
- *
- * To start, set up encounters normally.
- * Next, in the Map Notes, use Notetag <encounterEvals: x, code >>>
- * noting the specific spaces and the end of the tag MUST have 3 > signs as shown and the space after the :
- * Let x be the id number of the troop.
- * code is the specific javascript code you are using.
- * Be sure you use code that can eval to true or false.
- *
- * You can use multiple lines to check for a troop.
- * You can also use s[x] or v[x] for game switches and variables respectively.
- *
- * Once set up, when the player starts a random battle, the plugin will check for any evels that are set for the specific Troop Id.
- * If ALL evals for that troop are true, it is then added to the list of POSSIBLE encounters based on your setup in Map Properties.
- * You can have different conditions for the same troop on different maps.
- *
- * Example: <encounterEvals: 7, $gameParty.gold() > 200 >>>
- * Troop Id 7 will only appear if the party has more than 200.
- *
- * Example 2: (Separate lines on the same map property notes)
- * <encounterEvals: 10, s[27] >>>
- * <encounterEvals: 10, $gameParty.highestLevel() < 5 >>>
- * Troop 10 will only appear if game switch 27 is on AND the party's highest level is lower than 5.
- *
- */
- Game_Player.prototype.makeEncounterTroopId = function() {
- const encounterList = [];
- let weightSum = 0;
- for (const encounter of $gameMap.encounterList()) {
- if (this.malEncounterCond(encounter)) {
- if (this.meetsEncounterConditions(encounter)) {
- encounterList.push(encounter);
- weightSum += encounter.weight;
- }
- }
- }
- if (weightSum > 0) {
- let value = Math.randomInt(weightSum);
- for (const encounter of encounterList) {
- value -= encounter.weight;
- if (value < 0) {
- return encounter.troopId;
- }
- }
- }
- return 0;
- };
- Game_Player.prototype.malEncounterCond = function(encounter) {
- var troopId = encounter.troopId;
- var cond = this.encounterCond;
- var s = $gameSwitches._data;
- var v = $gameVariables._data;
- for (var i = 0; i < cond.length; i++) {
- var cond2 = cond[i];
- if (cond2[0] == troopId) {
- var ecEval = cond2[1];
- if(eval(ecEval) == false) return false;
- }
- }
- return true;
- };
- var malSMStart = Scene_Map.prototype.start
- Scene_Map.prototype.start = function() {
- malSMStart.call(this);
- $gamePlayer.setEncountercond();
- };
- Game_Player.prototype.setEncountercond = function() {
- this.encounterCond = [];
- var noteread = $dataMap.note;
- while(noteread.indexOf("encounterEvals") > -1)
- {
- var notereg = noteread.split("<encounterEvals: ");
- var match = notereg[1].split(">>>");
- var match2 = match[0].split(",");
- match2[0] = Number(match2[0]);
- this.encounterCond.push(match2);
- noteread = noteread.replace("<encounterEvals: ", " ");
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement