Script panic meter

Hello everyone, 👋
I'm looking for a script to create a panic/sanity meter in the right corner of the screen.
The idea is to use variable 23 to change how the meter/counter behaves. When the variable is 0, the meter is also 0.
As the meter goes up to 100, the color gradually changes from green to yellow/orange to bright red. At the same time, starting from 50, a picture will become visible, and an alarm will sound at 95. When the meter reaches 100, a common event gets triggered. The character will also move slower if the meter is really high. The higher, the slower. Both in running and walking.

Is there anyone who can help me with this?

0.png

50.png

100.png

Backdrop panic meter.png
Red-Overlay.png


Screen resolution: 640X416
Moved to: RGSS3 Script Requests
Try this

Updated* Forgot to add the windowskin and I never set up interval checking.
*Update - added sound timer
*Updated v1.02
*Updated v1.03
*Updated v1.04
*Updated v1.07
Here's my version of the script just in case you're interested in testing it at any given time.

Post no longer needed.
my version of the script
Did you test this?
Or is there something that you have done to your project to make it work.
Asking because if I replace mine with this, I get this
1640748112688.png
I had to edit the script anyway so I've updated its main thread accordingly. Now you can find it by clicking on the link below.

Thank you for reacting to this post. Your script was almost exactly what I had in mind. 🙏

I did find some bugs while testing. If you decrease the panic levels it's possible to go into a minus number. It can go down to -100 before you get an error message. Another thing I noticed was the warning sound. If the variable passes 95 without actually stopping on 95, the sound doesn't play. (For example: If the number is 93 and the number increases by 3, making 96, the sound doesn't play.) And it only played once instead of a continuous alarm. (Like a low health alarm to let the player know: YOU'RE PANICKING!!!! Find something to calm yourself down or you die.)
Try this
Spoiler: Panic Hud
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Panic HUD                    ║  Version: 1.00     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║                                     ╠════════════════════╣
# ║ Draw A Panic Number on Map          ║    28 Dec 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ A script to display a number to indicate danager         ║
# ║  Designed for a horror/ thriller type game               ║
# ║                                                          ║
# ║ Set the values below to your preference                  ║
# ╚══════════════════════════════════════════════════════════╝
# ╔═════════════════════════════════════╗
# ║ Terms of use:                       ║
# ║ Free for all uses in RPG Maker      ║
# ╚═════════════════════════════════════╝

module R2_Panic_Number_Colour
 
  Panic_Var = 23              # variable used to adjust the panic
  Colours = [11, 17, 20, 18]  # Windowskin colours
  # Green, Yellow, Orange, Red
  Number_Hud_X = 480          # X location
  Number_Hud_Y = 10           # Y location
  Number_Hud_Width = 60       # Number width
  Number_Hud_Height = 50      # Number height
  Window_Graphic = "Window"   # Set the window graphics
  Window_Opacity = 255        # Set the window opacity
  Window_Back_Opacity = 255   # Set the back opacity
  Warning_Sound = "Buzzer1"   # Sound to play at warning point
  Warning_Mark = 95           # Point of when sound will play
  Image = "Border"            # image to display when number is high
  Image_OI = [0, 80, 160, 240]  # Opacity Increment
  Font = "Arial"              # Set the font
  Font_Size = 24              # Set the font size
  Switch = 5                  # Switch to turn number off
 
end

class Panic_Window < Window_Base
 
  def initialize
    x = R2_Panic_Number_Colour::Number_Hud_X
    y = R2_Panic_Number_Colour::Number_Hud_Y
    w = R2_Panic_Number_Colour::Number_Hud_Width
    h = R2_Panic_Number_Colour::Number_Hud_Height
    super(x,y,w,h)
    self.windowskin = Cache.system(R2_Panic_Number_Colour::Window_Graphic)
    self.opacity = R2_Panic_Number_Colour::Window_Opacity
    self.back_opacity = R2_Panic_Number_Colour::Window_Back_Opacity
    self.contents_opacity = 255
    @current_number = $game_variables[R2_Panic_Number_Colour::Panic_Var]
    @panic_image = nil
    self.windowskin = Cache.system(R2_Panic_Number_Colour::Window_Graphic)
    refresh
  end
 
  def panic_data
    @current_number = $game_variables[R2_Panic_Number_Colour::Panic_Var]
    @current_number = 100 if $game_variables[R2_Panic_Number_Colour::Panic_Var] >= 100
    draw_panic_hud(0, 0)
    if @current_number == R2_Panic_Number_Colour::Warning_Mark
      snd = RPG::SE.new(R2_Panic_Number_Colour::Warning_Sound, 100, 100)
      snd.play
    end
  end
 
  def show_panic(ind)
    @panic_image.dispose if !@panic_image.nil?
    @panic_image = Sprite.new
    @panic_image.bitmap = Cache.picture(R2_Panic_Number_Colour::Image)
    @panic_image.opacity = R2_Panic_Number_Colour::Image_OI[ind]
  end
 
  def draw_panic_hud(x, y)
    draw_text_ex(0, 0, @current_number)
  end

  def refresh
    self.contents.clear
    panic_data
  end

  def panic_data_changed
    return true if @current_number != $game_variables[R2_Panic_Number_Colour::Panic_Var]
    return false
  end

  alias r2_panic_update    update
  def update
    refresh if panic_data_changed
    r2_panic_update
  end
 
  def image_erase
    @panic_image.bitmap.dispose
    @panic_image.dispose
  end
 
  alias r2_font_reset_colour  reset_font_settings
  def reset_font_settings
    r2_font_reset_colour
    font = R2_Panic_Number_Colour::Font
    font_size = R2_Panic_Number_Colour::Font_Size
    self.contents.font = Font.new(font, font_size)
    $game_variables[R2_Panic_Number_Colour::Panic_Var] = 100 if
      $game_variables[R2_Panic_Number_Colour::Panic_Var] >= 100
    cnt = R2_Panic_Number_Colour::Colours.size
    chk = 100 / cnt
    if $game_variables[R2_Panic_Number_Colour::Panic_Var] == 100
      col = 3
    else
      col = ($game_variables[R2_Panic_Number_Colour::Panic_Var] / chk).to_i
    end
    color = text_color(R2_Panic_Number_Colour::Colours[col])
    contents.font.color.set(color)
    show_panic(col)
  end
end
 
class Scene_Map < Scene_Base
  alias r2_map_panic_start  start
  def start
    r2_map_panic_start
    @map_panic_shown = true if @map_panic_shown.nil?
    start_panic
  end
  def start_panic
    @map_panic = Panic_Window.new
  end
  alias r2_map_panic_update    update
  def update
    r2_map_panic_update
    if $game_switches[R2_Panic_Number_Colour::Switch] == false
      @map_panic_shown = false
    else
      @map_panic_shown = true
    end
    if @map_panic_shown == false
      @map_panic.close if @map_panic.open?
    else
      @map_panic.open if @map_panic.close?
      panic_update
    end
  end
  def panic_update
    @map_panic.update if @map_panic_shown == true
    if @map_panic_shown == true
      @map_panic.image_erase if $game_player.transfer?
      @map_panic.image_erase if $game_player.encounter
      @map_panic.image_erase if @menu_calling && !$game_player.moving?
      @map_panic.image_erase if $TEST && Input.press?(:F9)
    end
  end
end
Updated* Forgot to add the windowskin and I never set up interval checking.
it's possible to go into a minus number.
Fixed
without actually stopping on 95, the sound doesn't play
Changed it to check greater than or equal
only played once
Added seconds for time interval
Fixed

Changed it to check greater than or equal

Added seconds for time interval
Yes. Thank you very much. The fixed bugs work perfectly. The only other small bug that I managed to find was that the Off switch has some problems. When the game starts, it's always a few frames visible. Even if I have the switch off. (It's only visible when the switch is on, except for those few first frames.)
it's always a few frames visible
I don't know how to make that perfect with the way it is code now.
I've updated the code. It is slightly visible when the game starts and then disappears.
Didn't realize you wanted it hidden at the start

I updated it again. Still can't make it 100% hidden at the start, but fixed an issue where the image would not disappear if the switch was off.
I don't know how to make that perfect with the way it is code now.
I've updated the code. It is slightly visible when the game starts and then disappears.
Didn't realize you wanted it hidden at the start
It actually works pretty well at the beginning. 😂I still see it a little, but I'll try to find a way to fix this later. Maybe with a wait before the fade-in or something like that. The reason why I didn't want it visible at the beginning was because the game starts with an intro where it asks your name. So that's why.

Again, thank you for writing this script. I'll make sure to credit you in my game. 🙏
@Daphne04 I updated it again. Fixed an issue where teh image would not disappear with the switch off.
Now I understand why you need it to not show. As for your suggestion I'll look at that.
@Daphne04 fixed. try it now
@Daphne04 I updated it again. Fixed an issue where teh image would not disappear with the switch off.
Now I understand why you need it to not show. As for your suggestion I'll look at that.
@Daphne04 fixed. try it now
The panic meter is no longer visible in the beginning when my intro starts. But my game does, strangely enough, become a bit laggy when the switch is turned off.
@Daphne04 I think I finally got it.
Script updated
@Daphne04
I've completed the parts I was trying to figure out. Hiding the image in all circumstances (in battle, menu call, player transfer)
V1.07 now available.
@Daphne04
I've completed the parts I was trying to figure out. Hiding the image in all circumstances (in battle, menu call, player transfer)
V1.07 now available.
I tested it out by starting a new game, but I got a line 120 error. I found out it happens when you transfer the player while the switch is turned off.
line 120 error.PNG
Did you load a saved game? I don't get that error at all. I can transfer the player with the switch on or off, image shown or not.
Did you load a saved game? I don't get that error at all. I can transfer the player with the switch on or off, image shown or not.
Nop, It was a new game. just to be sure I tested it in another file to see if any of my other scripts interfered, but I got the same result. If you have a parallel process and transfer the player to another/or the same map with the switch turned off, it will give this error.
Sorry, it was an error on my part. I didn't have part of the code in the script I posted, but I had it in my test project. It's fixed now.
Sorry, it was an error on my part. I didn't have part of the code in the script I posted, but I had it in my test project. It's fixed now.
Mistakes can happen. Thank you for uploading the working version. I no longer get the error. 😂

Original thread: https://forums.rpgmakerweb.com/threads/script-panic-meter.143386/