Map Safety Level - kyonides - 12-30-2022
Map Safety Level
XP + VX + ACE + MV
by Kyonides Arkanthes
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 safe that map actually is. This window will be shown on the menu screen only.
Screenshots
XP Script
Code: # * Map Safety Level XP * #
# Scripter : Kyonides Arkanthes
# 2022-12-30
# This scriptlet lets you set some texts as Safety Level Labels, and then you
# can call a method to set a new level at any given time.
# Valid Levels: 0 up to your safety maximum level.
# * Get or Set Current Map's Safety Level * #
# $game_map.safety_level
# $game_map.safety_level = NewLevel
# * Preset a given Map's Safety Level * #
# SAFETY_LEVELS = { MapIDa => Level, MapIDb => Level, etc. }
# * Define a given Map's Safety Level Color * #
# - Alpha is optional. Valid Values: 0 through 255
# SAFETY_LEVELS[0] = [Red, Green, Blue, Alpha]
module MapData
DEFAULT_SAFETY_LEVEL = 0
SAFETY_LEVELS = { 1 => 3 }
SAFETY_LABELS = [] # Just leave it alone.
SAFETY_COLORS = [] # Just leave it alone.
SAFETY_LABELS[0] = "A Nightmare"
SAFETY_LABELS[1] = "Dangerous"
SAFETY_LABELS[2] = "Unsafe"
SAFETY_LABELS[3] = "Normal Place"
SAFETY_LABELS[4] = "Great Place"
SAFETY_LABELS[5] = "The Utopia"
SAFETY_COLORS[0] = [255, 0, 0]
SAFETY_COLORS[1] = [255, 165, 0]
SAFETY_COLORS[2] = [255, 255, 0]
SAFETY_COLORS[3] = [255, 255, 255]
SAFETY_COLORS[4] = [90, 205, 90]
SAFETY_COLORS[5] = [0, 255, 0]
end
class Game_Map
alias :kyon_map_safety_lvl_gm_map_init :initialize
alias :kyon_map_safety_lvl_gm_map_setup :setup
def initialize
kyon_map_safety_lvl_gm_map_init
@safety_levels = MapData::SAFETY_LEVELS.dup
@safety_levels.default = MapData::DEFAULT_SAFETY_LEVEL
end
def get_mapinfos_name
load_data("Data/MapInfos.rxdata")[@map_id].name
end
def display_name
@display_name ||= get_mapinfos_name
end
def safety_level
@safety_levels[@map_id]
end
def safety_level=(new_level)
@safety_levels[@map_id] = new_level
end
def safety_level_text
MapData::SAFETY_LABELS[@safety_levels[@map_id]]
end
attr_reader :safety_levels
attr_writer :display_name
end
class MapNameSafeWindow < Window_Base
def initialize(wx, wy, w)
super(wx, wy, w, 96)
self.contents = Bitmap.new(w - 32, 64)
map = $game_map
contents.draw_text(0, 0, 128, 28, map.display_name, 1)
safety_color = MapData::SAFETY_COLORS[map.safety_level]
contents.font.color.set(*safety_color)
contents.draw_text(0, 32, 128, 28, map.safety_level_text, 1)
end
end
class Scene_Menu
alias :kyon_map_safety_lvl_scn_menu_main :main
alias :kyon_map_safety_lvl_scn_menu_up :update
def main
@show_map_name = true
@map_name_safe = MapNameSafeWindow.new(0, 320, 160)
@map_name_safe.z += 100
kyon_map_safety_lvl_scn_menu_main
@map_name_safe.dispose
end
def update
if Input.trigger?(Input::L) or Input.trigger?(Input::R)
if @command_window.active
@show_map_name = !@show_map_name
@map_name_safe.z = @show_map_name ? 100 : 0
@steps_window.z = @show_map_name ? 0 : 100
end
return
end
kyon_map_safety_lvl_scn_menu_up
end
end
VX Script
Code: # * Map Safety Level VX * #
# Scripter : Kyonides Arkanthes
# 2022-12-30
# This scriptlet lets you set some texts as Safety Level Labels, and then you
# can call a method to set a new level at any given time.
# Valid Levels: 0 up to your safety maximum level.
# * Get or Set Current Map's Safety Level * #
# $game_map.safety_level
# $game_map.safety_level = NewLevel
# * Preset a given Map's Safety Level * #
# SAFETY_LEVELS = { MapIDa => Level, MapIDb => Level, etc. }
# * Define a given Map's Safety Level Color * #
# - Alpha is optional. Valid Values: 0 through 255
# SAFETY_LEVELS[0] = [Red, Green, Blue, Alpha]
module MapData
DEFAULT_SAFETY_LEVEL = 0
SAFETY_LEVELS = { 1 => 3 }
SAFETY_LABELS = [] # Just leave it alone.
SAFETY_COLORS = [] # Just leave it alone.
SAFETY_LABELS[0] = "A Nightmare"
SAFETY_LABELS[1] = "Dangerous"
SAFETY_LABELS[2] = "Unsafe"
SAFETY_LABELS[3] = "Normal Place"
SAFETY_LABELS[4] = "Great Place"
SAFETY_LABELS[5] = "The Utopia"
SAFETY_COLORS[0] = [255, 0, 0]
SAFETY_COLORS[1] = [255, 165, 0]
SAFETY_COLORS[2] = [255, 255, 0]
SAFETY_COLORS[3] = [255, 255, 255]
SAFETY_COLORS[4] = [90, 205, 90]
SAFETY_COLORS[5] = [0, 255, 0]
end
class Game_Map
alias :kyon_map_safety_lvl_gm_map_init :initialize
alias :kyon_map_safety_lvl_gm_map_setup :setup
def initialize
kyon_map_safety_lvl_gm_map_init
@safety_levels = MapData::SAFETY_LEVELS.dup
@safety_levels.default = MapData::DEFAULT_SAFETY_LEVEL
end
def get_mapinfos_name
load_data("Data/MapInfos.rvdata")[@map_id].name
end
def display_name
@display_name ||= get_mapinfos_name
end
def safety_level
@safety_levels[@map_id]
end
def safety_level=(new_level)
@safety_levels[@map_id] = new_level
end
def safety_level_text
MapData::SAFETY_LABELS[@safety_levels[@map_id]]
end
attr_reader :safety_levels
attr_writer :display_name
end
class MapNameSafeWindow < Window_Base
def initialize(wx, wy, w)
super(wx, wy, w, WLH * 2 + 32)
self.contents = Bitmap.new(w - 32, WLH * 2)
map = $game_map
contents.draw_text(0, 0, 128, 24, map.display_name, 1)
safety_color = MapData::SAFETY_COLORS[map.safety_level]
contents.font.color.set(*safety_color)
contents.draw_text(0, 24, 128, 24, map.safety_level_text, 1)
end
end
class Scene_Menu
alias :kyon_map_safety_lvl_scn_menu_start :start
alias :kyon_map_safety_lvl_scn_menu_term :terminate
def start
kyon_map_safety_lvl_scn_menu_start
create_map_safety_window
end
def create_map_safety_window
@map_name_safe = MapNameSafeWindow.new(0, Graphics.height - 80 - 56, 160)
end
def terminate
kyon_map_safety_lvl_scn_menu_term
@map_name_safe.dispose
end
end
ACE Script
Code: # * Map Safety Level ACE * #
# Scripter : Kyonides Arkanthes
# 2022-12-30
# This scriptlet lets you set some texts as Safety Level Labels, and then you
# can leave a map note to set its initial safety level.
# <map safety 1>
# Valid Levels: 0 up to your safety maximum level.
# * Get or Set Current Map's Safety Level * #
# $game_map.safety_level
# $game_map.safety_level = NewLevel
# * Define a given Map's Safety Level Color * #
# - Alpha is optional. Valid Values: 0 through 255
# SAFETY_LEVELS[0] = [Red, Green, Blue, Alpha]
module MapData
SAFETY_REGEX = /map safety (\d+)/i
SAFETY_LABELS = [] # Just leave it alone.
SAFETY_COLORS = [] # Just leave it alone.
SAFETY_LABELS[0] = "A Nightmare"
SAFETY_LABELS[1] = "Dangerous"
SAFETY_LABELS[2] = "Unsafe"
SAFETY_LABELS[3] = "Normal Place"
SAFETY_LABELS[4] = "Great Place"
SAFETY_LABELS[5] = "The Utopia"
SAFETY_COLORS[0] = [255, 0, 0]
SAFETY_COLORS[1] = [255, 165, 0]
SAFETY_COLORS[2] = [255, 255, 0]
SAFETY_COLORS[3] = [255, 255, 255]
SAFETY_COLORS[4] = [90, 205, 90]
SAFETY_COLORS[5] = [0, 255, 0]
end
class Game_Map
alias :kyon_map_safety_lvl_gm_map_init :initialize
alias :kyon_map_safety_lvl_gm_map_setup :setup
def initialize
kyon_map_safety_lvl_gm_map_init
@safety_levels ||= {}
end
def setup(map_id)
kyon_map_safety_lvl_gm_map_setup(map_id)
reset_safety_level unless @safety_levels[@map_id]
end
def reset_safety_level
@map.note[MapData::SAFETY_REGEX]
@safety_levels[@map_id] = $1.to_i
end
def safety_level
@safety_levels[@map_id]
end
def safety_level=(new_level)
@safety_levels[@map_id] = new_level
end
def safety_level_text
MapData::SAFETY_LABELS[@safety_levels[@map_id]]
end
attr_reader :safety_levels
end
class MapNameSafeWindow < Window_Base
def initialize(wx, wy, w)
super(wx, wy, w, 72)
self.contents = Bitmap.new(w - 32, 48)
map = $game_map
contents.draw_text(0, 0, 128, 24, map.display_name, 1)
safety_color = MapData::SAFETY_COLORS[map.safety_level]
contents.font.color.set(*safety_color)
contents.draw_text(0, 24, 128, 24, map.safety_level_text, 1)
end
end
class Scene_Menu
alias :kyon_map_safety_lvl_scn_menu_start :start
def start
kyon_map_safety_lvl_scn_menu_start
create_map_safety_window
end
def create_map_safety_window
@map_name_safe = MapNameSafeWindow.new(0, Graphics.height - 120, 160)
end
end
MV 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.
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.
RE: Map Safety Level - Kain Nobel - 12-30-2022
Reminds me of the Homeland Security Advisory System from the George W Bush days after 9/11.
RE: Map Safety Level - kyonides - 12-31-2022
Well, now that you mention it, I gotta admit I felt in need of improving the script to change the color of the second label according to the current safety level. This is valid for all versions available here!
RE: Map Safety Level - kyonides - 01-01-2023
MV Got Included As Well!
From now on, MV users can also display the current map's safety level.
Please pay attention to this comments:
Code: * Map Note: <safety N>
* where N is a number. Valid Options: 0 through Maximum.
RE: Map Safety Level - Kain Nobel - 01-01-2023
The color system is a nice addition, great job!
RE: Map Safety Level - kyonides - 01-02-2023
Even Kiwi Menu XP Has Its Own Safety Level Now!
Code: # * Map Safety Level XP - Kiwi Menu Version * #
# Scripter : Kyonides Arkanthes
# 2023-01-01
# This scriptlet lets you set some texts as Safety Level Labels, and then you
# can call a method to set a new level at any given time.
# Valid Levels: 0 up to your safety maximum level.
# * Get or Set Current Map's Safety Level * #
# $game_map.safety_level
# $game_map.safety_level = NewLevel
# * Preset a given Map's Safety Level * #
# SAFETY_LEVELS = { MapIDa => Level, MapIDb => Level, etc. }
# * Define a given Map's Safety Level Color * #
# - Alpha is optional. Valid Values: 0 through 255
# SAFETY_LEVELS[0] = [Red, Green, Blue, Alpha]
module MapData
DEFAULT_SAFETY_LEVEL = 0
SAFETY_LEVELS = { 1 => 3 }
SAFETY_LABELS = [] # Just leave it alone.
SAFETY_COLORS = [] # Just leave it alone.
SAFETY_LABELS[0] = "A Nightmare"
SAFETY_LABELS[1] = "Dangerous"
SAFETY_LABELS[2] = "Unsafe"
SAFETY_LABELS[3] = "Normal Place"
SAFETY_LABELS[4] = "Great Place"
SAFETY_LABELS[5] = "The Utopia"
SAFETY_COLORS[0] = [255, 0, 0]
SAFETY_COLORS[1] = [255, 165, 0]
SAFETY_COLORS[2] = [255, 255, 0]
SAFETY_COLORS[3] = [255, 255, 255]
SAFETY_COLORS[4] = [90, 205, 90]
SAFETY_COLORS[5] = [0, 255, 0]
end
module KiwiMenu
MAP_SAFETY_TAB_X = 320
MAP_SAFETY_TAB_Y = 448
end
class Game_Map
alias :kyon_map_safety_lvl_gm_map_init :initialize
alias :kyon_map_safety_lvl_gm_map_setup :setup
def initialize
kyon_map_safety_lvl_gm_map_init
@safety_levels = MapData::SAFETY_LEVELS.dup
@safety_levels.default = MapData::DEFAULT_SAFETY_LEVEL
end
def get_mapinfos_name
load_data("Data/MapInfos.rxdata")[@map_id].name
end
def display_name
@display_name ||= get_mapinfos_name
end
def safety_level
@safety_levels[@map_id]
end
def safety_level=(new_level)
@safety_levels[@map_id] = new_level
end
def safety_level_text
MapData::SAFETY_LABELS[@safety_levels[@map_id]]
end
attr_reader :safety_levels
attr_writer :display_name
end
class KiwiMenuSpriteset
alias :kyon_map_safety_kwmn_set_init :initialize
alias :kyon_map_safety_kwmn_set_disp :dispose
def initialize(pos, options_max)
kyon_map_safety_kwmn_set_init(pos, options_max)
create_map_safety_sprites
end
def create_map_safety_sprites
@map_safety = [Sprite.new, Sprite.new]
@map_safety[0].x = MAP_SAFETY_TAB_X
@map_safety[0].y = MAP_SAFETY_TAB_Y
@map_safety[1].x = MAP_SAFETY_TAB_X
@map_safety[1].y = MAP_SAFETY_TAB_Y
@map_safety[0].bitmap = b = RPG::Cache.picture(GOLD_TAB)
@map_safety[1].bitmap = bm = Bitmap.new(b.width, b.height)
safety_color = MapData::SAFETY_COLORS[$game_map.safety_level]
bm.font.color.set(*safety_color)
text = $game_map.safety_level_text
bm.draw_text(4, 4, b.width - 8, 24, text, 1)
end
def dispose
@map_safety.each{|sprite| sprite.dispose }
@map_safety.clear
kyon_map_safety_kwmn_set_disp
end
end
So you can now include it in any of your game projects that are already using my Kiwi Menu script, guys.
RE: Map Safety Level - kyonides - 01-06-2023
Minor Update for MV
In the latest version of MapSafetyLevelMV.js file, I've fixed a bug that prevented the game from updating the MapID properly even if you could still be transferred to another map. What a mystery!
It also allows you know to keep track of the different map safety levels.
So people, should the Map Safety Levels get their own Menu Scripts?
|