Advertisement
roninator2

Panic Window

Dec 11th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.12 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Panic Window                           ║  Version: 1.07     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║ Draw A Panic Number on Map                    ║    29 Dec 2021     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: nil                                                      ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description:                                                 ║
  15. # ║       Show a Window for Panic Meter                                ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   A script to display a number to indicate danager                 ║
  20. # ║   Designed for a horror/ thriller type game                        ║
  21. # ║   The number is whatever the value of the variable is              ║
  22. # ║   Set the values below to your preference                          ║
  23. # ╚════════════════════════════════════════════════════════════════════╝
  24. # ╔════════════════════════════════════════════════════════════════════╗
  25. # ║ Updates:                                                           ║
  26. # ║ 1.00 - 29 Dec 2021 - Script finished                               ║
  27. # ║                                                                    ║
  28. # ╚════════════════════════════════════════════════════════════════════╝
  29. # ╔════════════════════════════════════════════════════════════════════╗
  30. # ║ Credits and Thanks:                                                ║
  31. # ║   Roninator2                                                       ║
  32. # ║                                                                    ║
  33. # ╚════════════════════════════════════════════════════════════════════╝
  34. # ╔════════════════════════════════════════════════════════════════════╗
  35. # ║ Terms of use:                                                      ║
  36. # ║  Follow the original Authors terms of use where applicable         ║
  37. # ║    - When not made by me (Roninator2)                              ║
  38. # ║  Free for all uses in RPG Maker except nudity                      ║
  39. # ║  Anyone using this script in their project before these terms      ║
  40. # ║  were changed are allowed to use this script even if it conflicts  ║
  41. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  42. # ║  No part of this code can be used with AI programs or tools        ║
  43. # ║  Credit must be given                                              ║
  44. # ╚════════════════════════════════════════════════════════════════════╝
  45.  
  46. module R2_Panic_Number_Colour
  47.  
  48.   Panic_Var = 23              # variable used to adjust the panic
  49.   Colours = [11, 17, 20, 18]  # Windowskin colours
  50.   # Green, Yellow, Orange, Red
  51.   Number_Hud_X = 480          # X location
  52.   Number_Hud_Y = 10           # Y location
  53.   Number_Hud_Width = 60       # Number width
  54.   Number_Hud_Height = 50      # Number height
  55.   Window_Graphic = "Window"   # Set the window graphics
  56.   Window_Opacity = 255        # Set the window opacity
  57.   Window_Back_Opacity = 255   # Set the back opacity
  58.   Warning_Sound = "Buzzer1"   # Sound to play at warning point
  59.   Warning_Mark = 95           # Point of when sound will play
  60.   Image = "Red-Overlay"            # image to display when number is high
  61.   Image_OI = [0, 80, 160, 240]  # Opacity Increment
  62.   Font = "Arial"              # Set the font
  63.   Font_Size = 24              # Set the font size
  64.   Switch = 5                  # Switch to turn number off
  65.   Seconds = 3                 # time to wait between sounds
  66.  
  67. end
  68.  
  69. class Panic_Window < Window_Base
  70.  
  71.   def initialize
  72.     x = R2_Panic_Number_Colour::Number_Hud_X
  73.     y = R2_Panic_Number_Colour::Number_Hud_Y
  74.     w = R2_Panic_Number_Colour::Number_Hud_Width
  75.     h = R2_Panic_Number_Colour::Number_Hud_Height
  76.     super(x,y,w,h)
  77.     self.windowskin = Cache.system(R2_Panic_Number_Colour::Window_Graphic)
  78.     self.opacity = R2_Panic_Number_Colour::Window_Opacity
  79.     self.back_opacity = R2_Panic_Number_Colour::Window_Back_Opacity
  80.     self.contents_opacity = 255
  81.     @current_number = $game_variables[R2_Panic_Number_Colour::Panic_Var]
  82.     @panic_image = nil
  83.     self.windowskin = Cache.system(R2_Panic_Number_Colour::Window_Graphic)
  84.     @sndplayed = true
  85.     @time = 0
  86.     @last_time = 0
  87.     @image_shown = false
  88.     refresh
  89.   end
  90.  
  91.   def panic_data
  92.     @current_number = $game_variables[R2_Panic_Number_Colour::Panic_Var]
  93.     @current_number = 100 if $game_variables[R2_Panic_Number_Colour::Panic_Var] >= 100
  94.     @current_number = 0 if $game_variables[R2_Panic_Number_Colour::Panic_Var] <= 0
  95.     draw_panic_hud(0, 0)
  96.     if @last_time < @time
  97.       @sndplayed = false
  98.     end
  99.     if @current_number >= R2_Panic_Number_Colour::Warning_Mark && @sndplayed == false
  100.       snd = RPG::SE.new(R2_Panic_Number_Colour::Warning_Sound, 100, 100)
  101.       snd.play if @sndplayed == false
  102.       @last_time = @time if @sndplayed == false
  103.       @sndplayed = true
  104.     end
  105.   end
  106.  
  107.   def show_panic(ind)
  108.     @panic_image.dispose if !@panic_image.nil?
  109.     return if @image_shown == false
  110.     @panic_image = Sprite.new
  111.     @panic_image.bitmap = Cache.picture(R2_Panic_Number_Colour::Image)
  112.     @panic_image.opacity = R2_Panic_Number_Colour::Image_OI[ind]
  113.   end
  114.  
  115.   def draw_panic_hud(x, y)
  116.     draw_text_ex(0, 0, @current_number)
  117.   end
  118.  
  119.   def refresh
  120.     self.contents.clear
  121.     panic_data
  122.   end
  123.  
  124.   def panic_data_changed
  125.     return true if @current_number != $game_variables[R2_Panic_Number_Colour::Panic_Var]
  126.     return true if @time % R2_Panic_Number_Colour::Seconds == 0
  127.     return false
  128.   end
  129.  
  130.   alias r2_panic_update    update
  131.   def update
  132.     refresh if panic_data_changed
  133.     @time = $game_system.playtime
  134.     r2_panic_update
  135.   end
  136.  
  137.   def image_open(value = false)
  138.     @image_shown = value
  139.   end
  140.  
  141.   def see_image
  142.     return @image_shown
  143.   end
  144.  
  145.   def image_erase
  146.     @panic_image.bitmap.dispose if @panic_image
  147.     @panic_image.dispose if @panic_image
  148.   end
  149.  
  150.   alias r2_font_reset_colour  reset_font_settings
  151.   def reset_font_settings
  152.     r2_font_reset_colour
  153.     font = R2_Panic_Number_Colour::Font
  154.     font_size = R2_Panic_Number_Colour::Font_Size
  155.     self.contents.font = Font.new(font, font_size)
  156.     $game_variables[R2_Panic_Number_Colour::Panic_Var] = 100 if
  157.       $game_variables[R2_Panic_Number_Colour::Panic_Var] >= 100
  158.     $game_variables[R2_Panic_Number_Colour::Panic_Var] = 0 if
  159.       $game_variables[R2_Panic_Number_Colour::Panic_Var] <= 0
  160.     cnt = R2_Panic_Number_Colour::Colours.size
  161.     chk = 100 / cnt
  162.     if $game_variables[R2_Panic_Number_Colour::Panic_Var] == 100
  163.       col = R2_Panic_Number_Colour::Colours.size - 1
  164.     else
  165.       col = ($game_variables[R2_Panic_Number_Colour::Panic_Var] / chk).to_i
  166.     end
  167.     color = text_color(R2_Panic_Number_Colour::Colours[col])
  168.     contents.font.color.set(color)
  169.     show_panic(col)
  170.   end
  171. end
  172.  
  173. class Scene_Map < Scene_Base
  174.   alias r2_map_panic_start  start
  175.   def start
  176.     r2_map_panic_start
  177.     fadeout(0)
  178.     @map_panic = Panic_Window.new
  179.     @map_panic.close
  180.     fadein(30)
  181.   end
  182.   alias r2_map_panic_update    update
  183.   def update
  184.     if $game_switches[R2_Panic_Number_Colour::Switch] == false
  185.       @map_panic.image_open(false) if @map_panic.open?
  186.       @map_panic_shown = false
  187.     else
  188.       @map_panic.image_open(true) if @map_panic.close?
  189.       @map_panic_shown = true
  190.     end
  191.     if @map_panic_shown == false
  192.       @map_panic.close if @map_panic.open?
  193.     else
  194.       @map_panic.open if @map_panic.close?
  195.       @map_panic.update
  196.     end
  197.     r2_map_panic_update
  198.   end
  199.   def call_menu
  200.     @map_panic.image_erase if @menu_calling && !$game_player.moving?
  201.     Sound.play_ok
  202.     SceneManager.call(Scene_Menu)
  203.     Window_MenuCommand::init_command_position
  204.   end
  205.   def perform_transfer
  206.     pre_transfer
  207.     @map_panic.image_erase if $game_player.transfer?
  208.     $game_player.perform_transfer
  209.     post_transfer
  210.   end
  211.   def update_encounter
  212.     if $game_player.encounter
  213.       @map_panic.image_erase
  214.       SceneManager.call(Scene_Battle)
  215.     end
  216.   end
  217.   def image_battle
  218.     @map_panic_shown = false
  219.     @map_panic.image_erase
  220.   end
  221. end
  222.  
  223. class Game_Interpreter
  224.   alias r2_image_panic_command_301  command_301
  225.   def command_301
  226.     SceneManager.scene.image_battle
  227.     r2_image_panic_command_301
  228.   end
  229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement