Save-Point
Map Safety Level MV - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Plugins and Mods (https://www.save-point.org/forum-74.html)
+---- Forum: RPGMaker MV/MZ Engines (https://www.save-point.org/forum-120.html)
+---- Thread: Map Safety Level MV (/thread-9007.html)



Map Safety Level MV - kyonides - 09-01-2024

Map Safety Level MV

by Kyonides


Introduction

I have come up with a very simple scriptlet that will allow the game developers to show a simple map name window plus a brand new label telling the player how Police Killer safe that map actually is. This window will be shown on the menu screen only. Happy with a sweat

Screenshots
[Image: mapsafetylevelace01.jpg]
The Plugin

Code:
//========================================================================================
// Map Safety Level MV.js
//========================================================================================
/*:
* @plugindesc This script allows you to display the current map's name and safety level.
* @version 2023-01-06
* @author Kyonides Arkanthes
*
* @param None
*
* @help
* Aliased Functions:
*   Game_Map#setup
* Overwritten Functions:
*   Scene_Menu#create
*
* Map Note: <safety N>
* where N is a number. Valid Options: 0 through Maximum.
*
* Plugin Calls:
*
*   $gameMap.getSafetyLevel();
*   $gameMap.setSafetyLevel(Number);
*   $gameMap.getSafetyLevelByMapId(Number);
*   $gameMap.safetyLevels();
*/

function MapSafetyWindow() {
  this.initialize.apply(this, arguments);
}

MapSafetyWindow.prototype = Object.create(Window_Base.prototype);
MapSafetyWindow.prototype.constructor = MapSafetyWindow;

MapSafetyWindow.prototype.initialize = function(x, y, width, height) {
  Window_Base.prototype.initialize.call(this, x, y, width, height);
  let w = this.contentsWidth();
  this.drawText($gameMap.displayName(), 0, 0, w, "center");
  this.changeTextColor(this.currentColor());
  this.drawText(this.currentLevel(), 0, 36, w, "center");
};

MapSafetyWindow.prototype.currentColor = function() {
  let level = $gameMap.getSafetyLevel();
  if (level == 0) {
    return "rgb(255, 0, 0)";
  } else if (level == 1) {
    return "rgb(255, 165, 0)";
  } else if (level == 2) {
    return "rgb(255, 255, 0)";
  } else if (level == 3) {
    return "rgb(255, 255, 255)";
  } else if (level == 4) {
    return "rgb(90, 205, 90)";
  } else if (level == 5) {
    return "rgb(0, 255, 0)";
  }
  return "rgb(255, 255, 255)";
}

MapSafetyWindow.prototype.currentLevel = function() {
  let level = $gameMap.getSafetyLevel();
  if (level == 0) {
    return "A Nightmare";
  } else if (level == 1) {
    return "Dangerous";
  } else if (level == 2) {
    return "Unsafe";
  } else if (level == 3) {
    return "Normal Place";
  } else if (level == 4) {
    return "Great Place";
  } else if (level == 5) {
    return "The Utopia";
  }
  return "Error!";
}

const Game_Map_safety_init = Game_Map.prototype.initialize;
const Game_Map_safety_setup = Game_Map.prototype.setup;

Game_Map.prototype.initialize = function() {
  Game_Map_safety_init.call(this);
  this._safetyLevels = [];
}

Game_Map.prototype.setup = function(mapId) {
  Game_Map_safety_setup.call(this, mapId);
  if (this._safetyLevels[mapId] == null) {
    let slvl = $dataMap.meta.safety || 0;
    this.setSafetyLevel(slvl);
  }
}

Game_Map.prototype.getSafetyLevel = function() {
  return this._safetyLevels[this._mapId];
}

Game_Map.prototype.setSafetyLevel = function(level) {
  return this._safetyLevels[this._mapId] = level;
}

Game_Map.prototype.getSafetyLevelByMapId = function(mapId) {
  return this._safetyLevels[mapId];
}

Game_Map.prototype.safetyLevels = function() {
  return this._safetyLevels;
}

Scene_Menu.prototype.create = function() {
  Scene_MenuBase.prototype.create.call(this);
  this.createCommandWindow();
  this.createMapSafetyWindow();
  this.createGoldWindow();
  this.createStatusWindow();
};

Scene_Menu.prototype.createMapSafetyWindow = function() {
  let w = this._commandWindow.width;
  let h = this._commandWindow.height;
  this._mapSafetyWindow = new MapSafetyWindow(0, h, w, 108);
  this.addWindow(this._mapSafetyWindow);
}

Terms & Conditions

Free for use in commercial and non commercial games unless you have pissed me off. Angry
Please include my nickname in your game credits.
I seriously hope this will not be the only script of mine that you will include in your games. Winking