QTE Script for VX

As a small mini-event for a game I'm working I was thinking of adding QTE mini-game to determine if an action is successful or not. I was surprised when I couldn't find a script for this online. I could do this through events but I think a script would be much-much better solution if anyone wants to help.

hitbox.png
pointer.png
background.png


Background is 416x56
Hitbox is 48x48
Pointer is 8x48

The pointer should move from one end to another waiting for the player to press the confirmation button. If the button is pressed at the time the pointer is inside the hitbox, player wins, if it's outside the box or time runs out (615 is turned off). Time/duration(in seconds) will be sent when the script is called inside an event script call.

if player wins (x switch is turned on, good sound plays, script closes)
if player loses (x switch is turned off, bad sound plays, script closes)

The position of the hitbox should be randomized(should fit within the background picture dimensions)
The size of the hitbox should also vary based on difficulty which should be set manually (maybe also as a variable through event script call). Difficulties: 1 through 3. One being 1/3 of the full hitbox picture size, 2 being 2/3, and 3 being full size.

The speed of the pointer should also vary to make it more difficult to hit. (Maybe also set it through an event script call)

The position of the whole script should be around the middle of the screen both H and V.

Pictures are located inside Graphics/system

Thanks in advance for any suggestions/help.

I went ahead and attempted to make my script for it (it's half ai, half me 🙁). The script as it is works now but I'm not sure I'm doing this correctly. I don't want to have the black background. Is it possilbe for the background to be transparent? I tried adding a transparent 544x416 picture in the background but it's not working.

1730453311716.png


Ruby:
class Scene_QTE
  def initialize
    # Set up the images
    @background = Sprite.new
    @background.bitmap = Cache.system("background")
    @background.x = (544 - 416) / 2  # Center the background horizontally
    @background.y = (416 - 64) / 2   # Center the background vertically

    @hitbox = Sprite.new
    @hitbox.bitmap = Cache.system("hitbox")
    @hitbox.x = @background.x + (416 - 48) / 2  # Center hitbox inside background
    @hitbox.y = @background.y + 4

    @pointer = Sprite.new
    @pointer.bitmap = Cache.system("pointer")
    @pointer.y = @background.y + 4

    # Initialize pointer movement variables
    @pointer_speed = 6
    @pointer_direction = 1
    @pointer_start_x = @background.x + 8  # Pointer starts moving from left edge
    @pointer_end_x = @background.x + 416 - 8
    @pointer.x = @pointer_start_x
    
    @running = true
    end
 
  def main
    # Main loop
    Graphics.transition(0)
    while @running
      Graphics.update   # Update the screen
      Input.update
      update_pointer
      check_player_input
    end
    Graphics.freeze
  end
 
  def update_pointer
    @pointer.x += @pointer_speed * @pointer_direction
    
    if @pointer.x <= @pointer_start_x || @pointer.x >= @pointer_end_x
      @pointer_direction *= -1  # Reverse direction when hitting edges
    end
  end
 
  # Check if the player has pressed the confirm button (Z key by default)
  def check_player_input
    if Input.trigger?(Input::C)  # C corresponds to the "confirm" button (Z key)
      if @pointer.x >= @hitbox.x && @pointer.x <= @hitbox.x + 48 - 8
         Audio.se_play("Audio/SE/Decision", 80, 100)  # Play success sound
      else
         Audio.se_play("Audio/SE/Buzzer", 80, 100)  # Play failure sound
      end
      
      @running = false           # Stop the loop if the button is pressed
      $scene = Scene_Map.new     # Return to scene before
    end
  end

  def terminate
    # Dispose of all sprites when finished
    @background.bitmap.dispose
    @background.dispose
    @hitbox.bitmap.dispose
    @hitbox.dispose
    @pointer.bitmap.dispose
    @pointer.dispose
  end
end
I have this script in one of my folders, I can't find the demo for it but from memory it does exactly what you need.

MiniGameBullseye.png

You'll need this picture sheet for the script

Ruby:
#===============================================================================
#
# Shanghai Simple Script - Minigame Bull's Eye
# Last Date Updated: 2010.05.18
# Level: Normal
#
# This is a minigame script. It's easy to play. Press Z when the cursor is right
# above the bull's eye or within the red region.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials but above ▼ Main. Remember to save.
#
# Do a script call for
#   $game_variables[1] = bulls_eye_game(x, y)
#
# x is the percentage range allowed for error and y is the cursor speed.
# Works with Battle Engine Melody.
#===============================================================================

$imported = {} if $imported == nil
$imported["MinigameBullsEye"] = true

module SSS
  # This is the filename for the bull's eye mini game spritesheet. Place it
  # inside of Graphics\System to work.
  BULLS_EYE_SHEET = "MiniGameBullseye"
  # These are the sound effects used for the bull's eye mini game.
  BULLS_EYE_SHOOT = RPG::SE.new("Bow1", 80, 100)
  BULLS_EYE_CLICK = RPG::SE.new("Cursor", 40, 150)
  BULLS_EYE_PERFECT = RPG::SE.new("Chime2", 80, 120)
  BULLS_EYE_ALMOST  = RPG::SE.new("Decision2", 80, 100)
  BULLS_EYE_MISSED  = RPG::SE.new("Buzzer2", 80, 100)
 
module SPRITESET
  #--------------------------------------------------------------------------
  # * Bulls Eye Game
  #--------------------------------------------------------------------------
  def bulls_eye_game(percent = 15, speed = 10)
    @bulls_eye_percent = percent
    @bulls_eye_speed = speed
    create_bulls_eye_sprites
  end
  #--------------------------------------------------------------------------
  # * Create Bulls Eye Sprites
  #--------------------------------------------------------------------------
  def create_bulls_eye_sprites
    @bulls_eye_sprite = Sprite_Base.new(@viewport3)
    bitmap1 = Bitmap.new(512, 72)
    bitmap2 = Cache.system(SSS::BULLS_EYE_SHEET)
    # Make the Main Body
    rect = Rect.new(0, 0, 512, 24)
    bitmap1.blt(0, 24, bitmap2, rect)
    # Make the Target Safe Zone
    rect = Rect.new(0, 24, 0, 24)
    rect.width = @bulls_eye_percent * 512 / 100
    rect.x = (512 - rect.width) / 2
    bitmap1.blt(rect.x, 24, bitmap2, rect)
    # Make the Target Center
    rect = Rect.new(488, 48, 24, 24)
    bitmap1.blt(244, 24, bitmap2, rect)
    # Make the Instructions
    rect = Rect.new(312, 48, 176, 24)
    bitmap1.blt(168, 48, bitmap2, rect)
    # Apply Sprite
    @bulls_eye_sprite.bitmap = bitmap1
    @bulls_eye_sprite.x = (Graphics.width - 512) / 2
    @bulls_eye_sprite.y = Graphics.height - 200
    # Arrow Sprite
    @arrow_shoot_sprite = Sprite_Base.new(@viewport3)
    @arrow_shoot_sprite.bitmap = Bitmap.new(24, 24)
    rect = Rect.new(0, 48, 24, 24)
    @arrow_shoot_sprite.bitmap.blt(0, 0, bitmap2, rect)
    @arrow_shoot_sprite.ox = 12
    @arrow_shoot_sprite.oy = 24
    @arrow_shoot_sprite.x = @bulls_eye_sprite.x
    @arrow_shoot_sprite.y = @bulls_eye_sprite.y + 24
    # Make Sounds
    @shoot_sound = SSS::BULLS_EYE_SHOOT
    @click_sound = SSS::BULLS_EYE_CLICK
    @bulls_eye_direction = 0
  end
  #--------------------------------------------------------------------------
  # * Dispose Bulls Eye Sprites
  #--------------------------------------------------------------------------
  def dispose_bulls_eye_sprites
    unless @bulls_eye_sprite.nil?
      @bulls_eye_sprite.dispose
      @bulls_eye_sprite = nil
    end
    unless @arrow_shoot_sprite.nil?
      @arrow_shoot_sprite.dispose
      @arrow_shoot_sprite = nil
    end
    unless @results_sprite.nil?
      @results_sprite.dispose
      @results_sprite = nil
    end
  end
  #--------------------------------------------------------------------------
  # * Update Bulls Eye Sprites
  #--------------------------------------------------------------------------
  def update_bulls_eye_sprites
    @bulls_eye_sprite.update
    if @bulls_eye_direction == 0
      m = Graphics.width - @bulls_eye_sprite.x
      @arrow_shoot_sprite.x = [@arrow_shoot_sprite.x + @bulls_eye_speed, m].min
      @bulls_eye_direction = 1 if @arrow_shoot_sprite.x >= m
    else
      m = @bulls_eye_sprite.x
      @arrow_shoot_sprite.x = [@arrow_shoot_sprite.x - @bulls_eye_speed, m].max
      @bulls_eye_direction = 0 if @arrow_shoot_sprite.x <= m
    end
    @click_sound.play if @bulls_eye_speed >= 0
    @arrow_shoot_sprite.update
  end
  #--------------------------------------------------------------------------
  # * Create Bulls Eye Results
  #--------------------------------------------------------------------------
  def create_bulls_eye_results
    @results_sprite = Sprite_Base.new(@viewport3)
    @results_sprite.bitmap = Bitmap.new(96, 24)
    bitmap = Cache.system(SSS::BULLS_EYE_SHEET)
    mx = @bulls_eye_sprite.x
    perfect_location = (mx+244)..(mx+268)
    almost_percent = (@bulls_eye_percent * 512 / 100) / 2
    almost_location1 = 512/2 - almost_percent
    almost_location2 = 512/2 + almost_percent
    if (mx+244..mx+268) === @arrow_shoot_sprite.x
      SSS::BULLS_EYE_PERFECT.play
      @result = 2
      rect = Rect.new(24, 48, 96, 24)
    elsif (mx+almost_location1..mx+almost_location2) === @arrow_shoot_sprite.x
      SSS::BULLS_EYE_ALMOST.play
      @result = 1
      rect = Rect.new(120, 48, 96, 24)
    else
      SSS::BULLS_EYE_MISSED.play
      @result = 0
      rect = Rect.new(216, 48, 96, 24)
    end
    @results_sprite.bitmap.blt(0, 0, bitmap, rect)
    @results_sprite.ox = 48
    @results_sprite.x = Graphics.width / 2
    @results_sprite.y = @bulls_eye_sprite.y - 24
  end
  #--------------------------------------------------------------------------
  # * Stop Bulls Eye Sprites
  #--------------------------------------------------------------------------
  def stop_bulls_eye_sprites
    @bulls_eye_speed = 0
    @shoot_sound.play
    wait = 60
    loop do
      wait -= 1
      $scene.update_basic
      @results_sprite.update unless @results_sprite.nil?
      case wait
      when 40
        create_bulls_eye_results
      when 0
        break
      end
    end
    dispose_bulls_eye_sprites
    return @result
  end
end
end

#==============================================================================
# ** Game_Interpreter
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Bulls Eye Game
  #--------------------------------------------------------------------------
  def bulls_eye(percent = 15, speed = 10)
    return false unless $scene.is_a?(Scene_Map) or $scene.is_a?(Scene_Battle)
    return $scene.bulls_eye(percent, speed)
  end
end

#==============================================================================
# ** Spriteset_Map
#==============================================================================

class Spriteset_Map
  include SSS::SPRITESET
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  alias dispose_sss_spriteset_map_bulls_eye dispose unless $@
  def dispose
    dispose_sss_spriteset_map_bulls_eye
    dispose_bulls_eye_sprites
  end
end

#==============================================================================
# ** Spriteset_Battle
#==============================================================================

class Spriteset_Battle
  include SSS::SPRITESET
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  alias dispose_sss_spriteset_battle_bulls_eye dispose unless $@
  def dispose
    dispose_sss_spriteset_battle_bulls_eye
    dispose_bulls_eye_sprites
  end
end

#==============================================================================
# ** Scene_Map
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :spriteset
  #--------------------------------------------------------------------------
  # * Bulls Eye Game
  #--------------------------------------------------------------------------
  def bulls_eye(percent = 15, speed = 10)
    @spriteset.bulls_eye_game(percent, speed)
    loop do
      update_basic
      @spriteset.update_bulls_eye_sprites
      break if Input.trigger?(Input::C)
    end
    return @spriteset.stop_bulls_eye_sprites
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :spriteset
  #--------------------------------------------------------------------------
  # * Bulls Eye Game
  #--------------------------------------------------------------------------
  def bulls_eye(percent = 15, speed = 10)
    @spriteset.bulls_eye_game(percent, speed)
    loop do
      update_basic
      @spriteset.update_bulls_eye_sprites
      break if Input.trigger?(Input::C)
    end
    return @spriteset.stop_bulls_eye_sprites
  end
end

#===============================================================================
#
# END OF FILE
#
#===============================================================================
I'll try it out. Tx

Original thread: https://forums.rpgmakerweb.com/threads/qte-script-for-vx.172922/