Save-Point
Panik Value ACE - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker VX/VXAce (RGSS2/3) Engines (https://www.save-point.org/forum-117.html)
+---- Thread: Panik Value ACE (/thread-8434.html)



Panik Value ACE - kyonides - 12-29-2021

Panik Value ACE
by Kyonides


Introduction

This scriptlet allows you to display a so called panic level on screen. You can change its current location by adjusting the values of the corresponding CONSTANTS found in the Panik module.

Version 1.0.2

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


Terms & Conditions

You can find them embedded in my scriptlet. Winking


RE: Panik Value ACE - kyonides - 12-30-2021

Panik Update

I have revisited my script in order to implement new minor features like letting you customize the Panik Value font color and also setting up a new flash with its corresponding color that will be displayed once for every time the Panik Value hits or exceeds the specified total panic threshold.

Don't ever let panic overcome you! Laughing



RE: Panik Value ACE - kyonides - 01-02-2022

A Minor Bug Fix

I have found a miniscule bug in the class PanicSpriteset#refresh_value method so I have fixed it in version 1.0.2 of my script.
Later on I have also made a few minor code changes in order to make it easy to update the backdrop automatically.