Save-Point
ToggleTimer XP - 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 XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: ToggleTimer XP (/thread-11015.html)



ToggleTimer XP - kyonides - 11-29-2024

ToggleTimer XP

by Kyonides

Introduction


Do you want to be able to show or hide the default game timer?
Then don't wait anymore and start using my script right away! Grinning

It also includes a feature to let you set its horizontal alignment with ease.

Please read the embedded comments before using it.

The Script

Code:
# * ToggleTimer XP * #
#   Scripter : Kyonides
#   2024-11-28

# This scriptlet allows you to show or hide the default timer.
# It lets you set its horizontal alignment as well.
# There are just 2 CONSTANTS that you need to configure here.

# Warning! 3 Methods Have Been Modified #
# Sprite_Timer: initialize & update
# Interpreter:  command_124 (Control Timer)

# * Script Calls * #
# - Show Timer - #
# $game_system.show_timer = true

# - Hide Timer - #
# $game_system.show_timer = false

# - Align Timer - #
# Alignment Options: 0 or :left, 1 or :center & 2 or :right
# Example:
# $game_system.align_timer = :left

# OPTIONAL: Set Hidden Timer #
# hidden_timer(minutes, seconds)

module KTimer
  DEFAULT_VISIBLE = true
  # Alignment Options: 0 or :left, 1 or :center & 2 or :right
  ALIGN_X = :right
end

class Game_System
  alias :kyon_toggle_timer_gm_sys_init :initialize
  def initialize
    kyon_toggle_timer_gm_sys_init
    @show_timer = KTimer::DEFAULT_VISIBLE
    @align_timer = KTimer::ALIGN_X
  end
  attr_accessor :show_timer, :align_timer
end

class Sprite_Timer
  def initialize
    super
    @width = 88
    self.bitmap = Bitmap.new(@width, 48)
    self.bitmap.font.name = "Arial"
    self.bitmap.font.size = 32
    refresh_align_x
    self.y = 0
    self.z = 500
    update
  end

  def refresh_align_x
    case @align_x = $game_system.align_timer
    when 0, :left
      self.x = 0
    when 1, :center
      self.x = 320 - @width / 2
    when 2, :right
      self.x = 640 - @width
    end
  end

  def update
    super
    return unless $game_system.timer_working
    self.visible = $game_system.show_timer
    if $game_system.align_timer != @align_x
      refresh_align_x
    end
    if $game_system.timer / Graphics.frame_rate != @total_sec
      self.bitmap.clear
      @total_sec = $game_system.timer / Graphics.frame_rate
      min = @total_sec / 60
      sec = @total_sec % 60
      text = sprintf("%02d:%02d", min, sec)
      self.bitmap.font.color.set(255, 255, 255)
      self.bitmap.draw_text(self.bitmap.rect, text, 1)
    end
  end
end

class Interpreter
  def command_124
    if @parameters[0] == 0
      $game_system.timer = @parameters[1] * Graphics.frame_rate
      $game_system.timer_working = true
    end
    if @parameters[0] == 1
      $game_system.timer_working = false
      $game_system.show_timer = false
    end
    true
  end

  def hidden_timer(min, sec)
    time = min * 60 + sec
    $game_system.timer = time * Graphics.frame_rate
    $game_system.timer_working = true
    $game_system.show_timer = false
    true
  end
end

Terms & Conditions

Free for use in ANY game. Gamer
Due credit is acceptable.
Mention this forum as well.
That's it! Tongue sticking out