Code:
# * Panik Value ACE
#   Scripter : Kyonides Arkanthes
#   v1.0.2 - 2022-01-02
# * This script is free as beer and speech! * #
# Display the current Panic Level on screen!
# It changes its backdrop depending on how dangerous the situation actually is.
# You can toggle it by turning a specific game switch on and off at will.
# A flash will be displayed if the Panic Level hits a certain value.
# Please adjust the values of all the CONSTANTS found below in the Panik module.
module Panik
  BACKDROP_X = 460
  BACKDROP_Y = 0
  # Pictures for Good, So so and Bad Panic Levels
  BACKDROPS = ["", "", ""]
  VAR_ID = 100
  SWITCH_ID = 1
  FONT_NAME = "Verdana"
  FONT_SIZE = 20
  # [ Red, Green, Blue ] for each Panic Level
  FONT_COLOR = [[255,255,255], [220,80,20], [255,0,0]]
  FLASH_MIN_VALUE = 90
  FLASH_COLOR = [255,0,0,128] # [ Red, Green, Blue, Opacity ]
  FLASH_DURATION = 8
end
class PanicSpriteset
  include Panik
  def initialize
    @box = Sprite.new
    @box.x = BACKDROP_X
    @box.y = BACKDROP_Y
    @board = Sprite.new
    @board.x = BACKDROP_X + 4
    @board.y = BACKDROP_Y + 4
    @sprites = [@box, @board]
    refresh_panic
    check_panic_index
    refresh_backdrop
    @board.bitmap = Bitmap.new(@box.width - 8, @box.height - 8)
    refresh_value
    self.visible = $game_switches[SWITCH_ID]
  end
  def check_panic_index
    @panic_index = case @panic_value
    when 0..49   then 2
    when 50..75  then 1
    when 75..100 then 0
    end
  end
  def refresh_panic
    @panic_value = [0, $game_variables[VAR_ID]].max
    @panic_value = [@panic_value, 100].min
  end
  def refresh_backdrop
    @last_index = @panic_index
    backdrop = BACKDROPS[@last_index]
    @box.bitmap.dispose if @box.bitmap != nil
    @box.bitmap = Cache.picture(backdrop)
  end
  def refresh_value
    @last_value = @panic_value
    bit = @board.bitmap
    bit.clear
    bit.font.name = FONT_NAME
    bit.font.size = FONT_SIZE
    r, g, b = FONT_COLOR[@panic_index]
    bit.font.color = Color.new(r, g, b, 255)
    bit.draw_text(0, 0, @board.width, @board.height, @panic_value.to_s, 1)
    return if FLASH_MIN_VALUE > @panic_value
    r, g, b, a = FLASH_COLOR
    $game_screen.start_flash(Color.new(r, g, b, a), FLASH_DURATION)
  end
  def update
    refresh_panic
    check_panic_index
    refresh_backdrop if @last_index != @panic_index
    refresh_value if @last_value != @panic_value
    self.visible = $game_switches[SWITCH_ID]
  end
  def visible=(bool)
    if @last_state != bool
      @sprites.each{|sprite| sprite.visible = bool }
    end
    @last_state = bool
  end
  def dispose
    @sprites.each do |sprite|
      sprite.bitmap.dispose
      sprite.dispose
    end
    @sprites.clear
  end
end
class Scene_Map
  alias :kyon_panik_val_scn_map_crt_spr :create_spriteset
  alias :kyon_panik_val_scn_map_dsp_spr :dispose_spriteset
  alias :kyon_panik_val_scn_map_up :update
  def create_spriteset
    kyon_panik_val_scn_map_crt_spr
    @panic_box = PanicSpriteset.new
  end
  
  def dispose_spriteset
    kyon_panik_val_scn_map_dsp_spr
    @panic_box.dispose
  end
  def update
    kyon_panik_val_scn_map_up
    @panic_box.update
  end
end