Stay in range minigame

Hello. Im using Sixth's mini-games script for RPG Maker VX Ace. One of them is "Stay in Range" minigame. I want to reset the mini-game score but i dont seem to find any script call on the script that is capable of doing that. Can anyone help me?

Here's the script:
Code:
#===============================================================================
# * [ACE] "Stay-In-Range" Mini-Game
#===============================================================================
# * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
# * Version: 1.1
# * Updated: 08/12/2015
# * Requires: Sixth's Picture Number Drawing
#             Sixth's Mini-Game Base
#-------------------------------------------------------------------------------
# * < Change Log >
#-------------------------------------------------------------------------------
# * Version 1.0 (29/11/2015)
#   - Initial release.
# * Version 1.1 (08/12/2015)
#   - Re-worked the code. This script now requires my Mini-Game Base script too!
#   - Changed the script calls. All of them are explained in the Mini-Game Base
#     script (except the mini-game starting script call)!
#   - Added popups to show the player when the game starts/ends.
#-------------------------------------------------------------------------------
# * < Description >
#-------------------------------------------------------------------------------
# * This is a mini-game script, where the player needs to keep a cursor in the
#   range of a moving and shrinking bar.
# * The player can earn scores from winning in the game too. You can use these
#   scores in eventing.
# * Settings for making infinite difficulties.
# * Completely image based! The images used can be changed during the game too!
# * For scripters: Easily implement this mini-game into any scenes!
#   All you have to do is to create a mini game instance and loop it's update
#   method (along with the Input and Graphics update methods) until the game
#   is finished.
#-------------------------------------------------------------------------------
# * < Playing the Game >
#-------------------------------------------------------------------------------
# * When you use the script call to start a game, the images used for the game
#   will show up. The player must press the confirm button to start the game.
#   When the game is started, the bar will start to move, and the player must
#   follow it with the cursor. If the cursor gets out of range of the bar, the
#   player will gain failure points. If these points reach the maximum allowed
#   value (can be set up for each difficulty separately), the player will lose
#   the game. If the player manages to keep the cursor in range, he/she will
#   get score points. The longer the cursor stays in range, the more score can
#   be gained quickly. Also, if the cursor is in range, the bar will start to
#   shrink. If the bar shrinks enough (can be set for each difficuly separately)
#   the player wins the game.
#   Regardless if the game is won or lost, after it ends, the player must press
#   the confirm button to exit the game.
#   After the game, you can check if it was won or lost with the provided script
#   variables in conditional branch commands (with the script option), so you
#   can trigger different things depending on whether the player won or lost the
#   game.
#-------------------------------------------------------------------------------
# * < Script Calls >
#-------------------------------------------------------------------------------
# * To start a mini-game, use the following script call:
#
#     start_range_game(key,x,y)
#
#   Replace 'key' with a key you used in the 'Games' settings in the script!
#   Replace 'x' and 'y' with the X and Y co-ords you want to show the mini-game
#   images!
#   All image positions are centered! So, the X and Y positions do NOT mean the
#   top left corner of images, but the center of them!
#
#   Exammples: start_range_game(:easy,120,240)
#              start_range_game(:hard,230,146)
#-------------------------------------------------------------------------------
# * < Installation >
#-------------------------------------------------------------------------------
# * Place this script below Materials but above Main!
#-------------------------------------------------------------------------------
# * < Compatibility Info >
#-------------------------------------------------------------------------------
# * No known incompatibilities.
#-------------------------------------------------------------------------------
# * < Known Issues >
#-------------------------------------------------------------------------------
# * No known issues.
#-------------------------------------------------------------------------------
# * < Terms of Use >
#-------------------------------------------------------------------------------
# * Free to use for whatever purposes you want.
# * Credit me (Sixth) in your game, pretty please! :P
# * Posting modified versions of this script is allowed as long as you notice me
#   about it with a link to it!
#===============================================================================
$imported = {} if $imported.nil?
$imported["SixthRangeMiniGame"] = true
#===============================================================================
# Settings:
#===============================================================================
module RangeMiniGame
  #-----------------------------------------------------------------------------
  # Image Folder Settings:
  #-----------------------------------------------------------------------------
  # Set up the folder which contains the images used for the mini game.
  # All of the images used must be in this folder!
  #-----------------------------------------------------------------------------
  ImgFolder = "Graphics/RangeMiniGame/"
 
  #-----------------------------------------------------------------------------
  # Score Settings:
  #-----------------------------------------------------------------------------
  # You can show/hide the score display with this setting.
  # true = show, false = hide.
  # The scores will still be updated even if you set this to false, but the
  # score display during games will be hidden.
  #-----------------------------------------------------------------------------
  UseScore = false
 
  #-----------------------------------------------------------------------------
  # Image Settings:
  #-----------------------------------------------------------------------------
  # This mini-game is made with images. This is the place where you set up the
  # used images in the mini game.
  # You must follow some rules with your images:
  # - The shrinking bar must NOT have any empty pixels on the left and right
  #   sides of the image!
  # - The background for the shrinking bar decides where the bar can slide.
  #   That is the sliding area of the bar. For that reason, the background for
  #   the shrinking bar can NOT have any empty pixels on the sides of the image
  #   either!
  # - The filling "life" bar can NOT have any empty pixels on the sides either!
  # The rest of the images don't require any special properties.
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Details:
  #
  #   :img => "filename",
  # The image used for the specified data.
  # All images must be in the folder you have set up above!
  #
  #   :opa => value,
  # The opacity value of the images. Valid values: 0 - 255.
  #
  #   :z => value,
  # The Z value of the images.
  #
  #   :pos => [x,y],
  # X and Y offset values for the images.
  # The default position is the initial position of the shrinking bar/cursor.
  # Offset that position with these values!
  # Note that not all settings got this option!
  #
  #   :size => [width,height],
  # The width and height of the score display bitmaps.
  # In other words, the size reserved for drawing the score numbers.
  #   
  #   :tpos => [x,y],
  # The X and Y positions of the score numbers INSIDE the score bitmaps.
  # Note that if the score text gets outside of the score bitmap, the text
  # outside will be cut down!
  #
  #   :align => type,
  # The alignment type of the score number texts.
  # 0 = Left, 1 = Middle, 2 = Right.
  # Make sure to read about the connection of the alignment and position
  # settings in my Picture Number Drawing script!
  #
  #   :style => ["filename",row_index],
  # The picture number style used to draw the score numbers.
  # Make sure to read about this setting in my Picture Number Drawing script!
  # Note that the image files used here must be in the folder you have set up
  # in my Picture Number Drawing script!
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Popup specific setting details:
  #
  # There are 3 popups which can appear during the game.
  # These are the start, success and fail popup images.
  # These can be animated by setting movement, opacity and zoom level changes
  # for them.
  # The position, opacity, and zoom settings you enter are the initial values
  # for those properties. These will be changed with the :move_in, :fade_in and
  # :zoom_in settings.
  # When the popup is finished with the entering animation, the player can press
  # the confirm button to get rid of the popup. After the confirm button
  # pressing, the popup will start it's exiting animation.
  # The exiting animation is controlled by the :move_out, :fade_out and
  # :zoom_out settings. These settings will start to change the popup's
  # properties until the exiting animation finishes.
  #
  # Details:
  #
  #   :in_time => frames,
  # The frames of the entering animation. The less frames you set here, the
  # quicker the animation will be. Remember: 1 second = 60 frames!
  #
  #   :out_time => frames,
  # The frames of the exiting animation. The less frames you set here, the
  # quicker the animation will be. Remember: 1 second = 60 frames!
  #
  #   :move_in => [x,y],
  # The movement of the entering animation. This many pixels will the popup
  # move on the X and Y axis while the entering animation lasts.
  #
  #   :move_out => [x,y],
  # The movement of the exiting animation. This many pixels will the popup
  # move on the X and Y axis while the exiting animation lasts.
  # Note that this takes the popup's position after the entering animation, and
  # the values you set up here will be added to that position!
  #
  #   :fade_in => value,
  # The change in the popup's opacity during the entering animation.
  #
  #   :fade_out => value,
  # The change in the popup's opacity during the exiting animation.
  # Note that this takes the popup's opacity after the entering animation, and
  # the value you set up here will be added to that value!
  #
  #   :zoom_in => [x_zoom,y_zoom],
  # The change in the popup's zoom level on the X and Y axis during the entering
  # animation.
  #
  #   :zoom_out => [x_zoom,y_zoom],
  # The change in the popup's zoom level on the X and Y axis during the exiting
  # animation.
  # Note that this takes the popup's zoom level after the entering animation,
  # and the values you set up here will be added to that zoom value!
  #
  #   :wave = true/false,
  # With this, you can enable a wave effect for the popup when it is in the
  # waiting phase (waiting for the player to press the confirm button).
  # true = enable wave effect, false = disable wave effect.
  #-----------------------------------------------------------------------------
  Images = {
    :cursor => { # Cursor image settings.
      :img => "curs1a", :opa => 250, :z => 20,
    },
    :bar => { # Shrinking/moving bar image settings.
      :img => "bar1a", :opa => 250, :z => 15,
    },
    :back => { # Background image settings for the shrinking/moving bar.
      :img => "back2a", :opa => 200, :z => 10,
    },
    :life => { # Filling "life" bar image settings.
      :img => "fail1a", :pos => [0,40], :opa => 250, :z => 6,
    },
    :lback => { # Background image settings for the filling "life" bar.
      :img => "fback1a", :pos => [0,40], :opa => 200, :z => 5,
    },   
    :sback => { # Background image settings for the score display.
      :img => "score1a", :pos => [0,-60], :opa => 200, :z => 5,
    },
    :current => { # Current score info display settings.
      :opa => 250, :z => 8, :size => [130,26],
      :pos => [-65,18], :tpos => [65,0],
      :style => ["mpnums1va",0], :align => 1,
    },
    :total => { # Total accumulated score info display settings.
      :opa => 250, :z => 8, :size => [130,26],
      :pos => [65,18], :tpos => [65,0],
      :style => ["mpnums1va",1], :align => 1,
    },
    :start => { # Start popup image settings.
      :img => "startpop1a", :pos => [0,180], :z => 500,
      :opa => 0, :zoom => [0.0,0.0],
      :in_time => 30, :move_in => [0,-50], :fade_in => 255, :zoom_in => [1.0,1.0],
      :out_time => 30, :move_out => [0,50], :fade_out => -255, :zoom_out => [-1.0,-1.0],
      :wave => false,
    },
    :success => { # Success popup image settings.
      :img => "successpop1a", :pos => [0,180], :z => 500,
      :opa => 0, :zoom => [0.0,0.0],
      :in_time => 30, :move_in => [0,-50], :fade_in => 255, :zoom_in => [1.0,1.0],
      :out_time => 30, :move_out => [0,50], :fade_out => -255, :zoom_out => [-1.0,-1.0],
      :wave => false,
    },
    :fail => { # Fail popup image settings.
      :img => "failpop1a", :pos => [0,180], :z => 500,
      :opa => 0, :zoom => [0.0,0.0],
      :in_time => 30, :move_in => [0,-50], :fade_in => 255, :zoom_in => [1.0,1.0],
      :out_time => 30, :move_out => [0,50], :fade_out => -255, :zoom_out => [-1.0,-1.0],
      :wave => false,
    },
  }
 
  #-----------------------------------------------------------------------------
  # Sound Settings:
  #-----------------------------------------------------------------------------
  # Set up the BGM to be played during the game and the sound effects used upon
  # various actions during the game.
  #
  # Format: RPG::BGM.new("filename",volume,pitch), # For the BGM.
  #         RPG::SE.new("filename",volume,pitch),  # For the SEs.
  #
  # "filename" = The name of the audio file to be played.
  # volume = The volume of the audio.
  # pitch = The pitch of the audio.
  #
  # If you don't want to change the map BGM during the mini-game, set the
  # whole :bgm setting to 'nil' (without the apostrophes!), like this:
  #   :bgm => nil,
  #-----------------------------------------------------------------------------
  Sounds = {
    :bgm => nil,
    :start => RPG::SE.new("Bell3",80,100),
    :win => RPG::SE.new("Chime2",80,100),
    :lose => RPG::SE.new("Buzzer1",80,100),
    :exit => RPG::SE.new("Decision2",80,100),
  }
 
  #-----------------------------------------------------------------------------
  # Game Settings:
  #-----------------------------------------------------------------------------
  # This is where you can set up your game settings.
  # You can make different settings here, and you can load these settings for
  # the range mini-game with the script call.
  # In other words, you can use this section to make different difficulty
  # settings for your range mini-games.
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Format:
  #
  #  key => { # Key used for the setting. You will use this in the script calls.
  #    :cursor => { # Cursor settings.
  #      :acc => { # Cursor acceleration settings.
  #        :base => value,
  #        :extra => value,
  #        :acc_a => value,
  #        :acc_b => value
  #      },
  #      :score => { # Score acceleration settings.
  #        :base => value,
  #        :extra => value,
  #        :acc_a => value,
  #        :acc_b => value
  #      },
  #      :await => value,
  #      :dwait => value,
  #      :amax => value,
  #    },
  #    :bar => { # Shrinking and movement settings for the bar.
  #      :shrink => value,
  #      :goal => value,
  #      :fail => value,
  #      :speed => [min_value,max_value],
  #      :mwait => value,
  #      :wait => value,
  #      :chance => value,
  #    },
  #  },
  #
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Details: 
  #
  #   key => {
  # The 'key' here can be anything you want, from strings to integers across
  # symbols and arrays of data. There is only one rule: don't make duplicates!
  # You will use these keys in your script calls to load the correct settings
  # for your mini-games.
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Cursor Settings:
  #
  #   :await => value,
  # The waiting time between each increase in acceleration.
  # The higher this number is, the slower the acceleration will be.
  # You can only use integer numbers and only from 1 and above! No negatives!
  #
  #   :dwait => value,
  # The waiting time between each increase in deceleration speed.
  # The cursor will start to slow down on it's own if no direction buttons are
  # pressed. This setting determines how fast that slow down will be.
  # The higher number you enter, the slower the slow down will be.
  # This only affects the slow down speed when no direction buttons are being
  # pressed!
  # You can only use integer numbers and only from 1 and above! No negatives!
  #
  #   :amax => value,
  # The maximum acceleration cap.
  # This limits the acceleration and can prevent the cursor from getting
  # ligthning fast. The higher this number is, the quicker the acceleration can
  # be when the player presses one direction for a longer period.
  # You can only use integer numbers and only from 1 and above! No negatives!
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Cursor Acceleration Settings: 
  #
  # These settings are based on the XP curve settings from the Class database.
  # If you are unsure how these settings work even after reading their
  # description, you can open your database editor and check how the XP curve
  # settings work. That should give you enough visuality to understand these
  # acceleration settings.
  # The only difference is, that you can use float numbers here too, not just
  # integers like in the editor.
  #
  # The acceleration calculation uses levels too.
  # The more time the player presses the same direction, the higher the
  # acceleration level goes.
  # If the player changes directions, the acceleration level starts to decrease
  # until the direction of the cursor is changes as well. When that happens,
  # the acceleration level will start to raise again.
  # If the player stops pressing the direction keys, the cursor will start to
  # slow down gradually as well until it completely stops.
  #
  #   :base => value,
  # The base acceleration value. It's the starting value for the acceleration.
  # Affects the entire acceleration calculation.
  #
  #   :extra => value,
  # A direct value added to the final acceleration value for each acceleration
  # level. Equally affects the entire acceleration calculation.
  #
  #   :acc_a => value,
  # An acceleration multiplier which affects the entire acceleration
  # calculation. If you want quickly, but gradually accelerating cursors, edit
  # this setting until you found the value you want.
  # If you want to make a quickly accelerating cursor, but want to slow down the
  # acceleration if the player presses the same direction for a longer period,
  # keep the :acc_b setting low, and set this one to something higher.
  #
  #   :acc_b => value,
  # An acceleration multiplier which mainly affects the higher acceleration
  # levels. If you want slowly starting, but gradually accelerating cursors,
  # keep the :acc_a setting low, and set this one to something higher.
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Score Gain Acceleration Settings: 
  #
  # This uses the same format and settings as the cursor acceleration.
  #
  # You might find it weird that I have put this in the settings for the cursor.
  # I did it this way, so I don't need to make another method to calculate the
  # score acceleration. This way, I can use the same one the cursor acceleration
  # uses.
  #
  # The longer the player keeps the cursor in the range of the shrinking bar,
  # the higher the score gain level gets. This enables you to make gradually
  # increasing score gains if the player manages to keep the cursor in range
  # long enough.
  #
  # If the cursor gets out of range, the score gain acceleration level resets.
  # This means that if the player constantly keeps getting out of range, he/she
  # will not gain many points in the end of the game.
  #
  # The accumulated score will only be gained if the game is successfully
  # cleared! If the game ends in a failure, the player won't gain any points.
  #
  # Note that the score display can be turned off in the script's setting.
  #
  # The system keeps track of the following score and score related records:
  # - Current Score: The score in the current game. Resets after each game.
  # - Total Score: The total accumulated score during the game. Never resets.
  # - Highest Score: The highest score earned in a single game. Not displayed.
  # - Number of games won: Self-explanatory.
  # - Number of games lost: Self-explanatory.
  # - Last game's score: Self-explanatory. Use this in eventing.
  # - Last game's results (win or lose): Self-explanatory. Use this in eventing.
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Bar Settings: 
  #
  # Settings for the shrinking/moving bar. This is the bar the player must
  # follow with the cursor to win the game.
  #
  # The cursor must remain in the range of the bar until it shrinks to the goal
  # zoom level. When that happens, the game ends and the player gains the
  # accumulated score.
  #
  # If the player fails to keep the cursor in range, the game will start to add
  # up failure points. The amount of points added depends on the distance
  # between the bar and the cursor. The farther the cursor gets from the bar,
  # the more failure points are gained. When the points reach the maximum
  # allowed value, the game ends in a failure, and all accumulated score from
  # the game will be lost.
  #
  # A custom variable will be set whether you win or lose. You can use this
  # variable in your conditional branches to make different things happen when
  # the player loses and when the player wins.
  #
  #   :shrink => value,
  # This value will be subtracted every frame from the zoom level of the bar if
  # the player is within the range of the bar.
  # Remember that the default value starts from 1.0 (one!). The bar image
  # completely disappears when the value reaches 0.0 (zero!).
  #
  #   :goal => value,
  # This sets when the game is considered successful. If the zoom value of the
  # bar reaches this value, the player wins the game.
  # Again, the default is 1.0, so set this to something lower, but remember that
  # the bar disappears at 0.0! If you set this to 0, the game can NOT be won!
  #
  #   :fail => value,
  # This is the maximum allowed failure points. Think of it as a HP for the
  # player in this mini-game. As soon as the cursor gets out of range, the
  # failure points will start to rise. The farther away the cursor is from the
  # bar, the more points are "earned". When the amount of failure points reach
  # this value, the game ends in a failure.
  # Remember that the distance between the cursor and the bar is calculated in
  # pixels!
  #
  #   :speed => [min_value,max_value],
  # This is the moving speed of the bar. Unlike the cursor, the bar will move
  # with linear speed, no acceleration here. However, you can set up the minimum
  # and maximum pixels to move, so you can spice the movement up a little if
  # you want. The bigger the difference between the min and max values here,
  # the more irregularly will the bar move, giving the player a harder time to
  # foresee the movement of the bar.
  # If you don't want any randomness in the speed of the bar, set this to [1,1].
  # You can use 0 for these values if you want, but remember that if 0 is
  # selected from the pool, the bar won't move!
  # You can only use integers and those can NOT be negative numbers!
  #
  #   :mwait => value,
  # The amount of frames the bar will wait before it's next movement.
  # The lower you set this number, the quicker the bar will move.
  # Use integer numbers only, and only numbers from 1 and above, no negatives!
  # 60 frames = 1 second!
  #
  #   :wait => value,
  # The amount of frames to wait before the bar can change directions.
  # So, the lower this number is, the more frequently the bar will change
  # directions. The bar will automatically change it's direction when it reaches
  # the edge of the bar background, and resets the waiting time.
  # Use integer numbers only, and only numbers from 1 and above, no negatives!
  # 60 frames = 1 second!
  #
  #   :chance => value,
  # The bar's chance to change directions in percentages.
  # 1 = 1%, 25 = 25%, 60 = 60%, 100 = 100% ...
  # When the wait time between direction changes is over, the bar gets a chance
  # to change the direction it's currently moving. If it fails to change the
  # direction, it must wait until the waiting time is over again to try again.
  # You can set this to 0 if you want to disable direction changes for the bar.
  #-----------------------------------------------------------------------------
  Games = {
    :easy => { # Easy difficulty.
      :cursor => {
        :acc => {:base => 1, :extra => 0.01, :acc_a => 0.02, :acc_b => 0.01},
        :score => {:base => 1, :extra => 0.01, :acc_a => 0.015, :acc_b => 0.02},
        :await => 5, :dwait => 7, :amax => 50, :dmax => 50,
      },
      :bar => {
        :shrink => 0.0015, :goal => 0.2, :fail => 12000,
        :speed => [1,2], :mwait => 8,
        :wait => 120, :chance => 50,
      },
    },
    :normal => { # Normal difficulty.
      :cursor => {
        :acc => {:base => 1, :extra => 0.01, :acc_a => 0.02, :acc_b => 0.01},
        :score => {:base => 1, :extra => 0.01, :acc_a => 0.02, :acc_b => 0.03},
        :await => 5, :dwait => 7, :amax => 50, :dmax => 50,
      },
      :bar => {
        :shrink => 0.001, :goal => 0.2, :fail => 11000,
        :speed => [1,2], :mwait => 5,
        :wait => 120, :chance => 50,
      },
    },
    :hard => { # Hard difficulty.
      :cursor => {
        :acc => {:base => 1, :extra => 0.01, :acc_a => 0.025, :acc_b => 0.015},
        :score => {:base => 1, :extra => 0.02, :acc_a => 0.025, :acc_b => 0.04},
        :await => 3, :dwait => 6, :amax => 50, :dmax => 50,
      },
      :bar => {
        :shrink => 0.001, :goal => 0.2, :fail => 10000,
        :speed => [1,2], :mwait => 4,
        :wait => 120, :chance => 50,
      },
    },
    :insane => { # Insane difficulty.
      :cursor => {
        :acc => {:base => 1, :extra => 0.01, :acc_a => 0.01, :acc_b => 0.03},
        :score => {:base => 1, :extra => 0.03, :acc_a => 0.04, :acc_b => 0.06},
        :await => 3, :dwait => 6, :amax => 50, :dmax => 50,
      },
      :bar => {
        :shrink => 0.001, :goal => 0.2, :fail => 10000,
        :speed => [1,2], :mwait => 3,
        :wait => 120, :chance => 70,
      },
    },
    :test => { # For testing purposes.
      :cursor => {
        :acc => {:base => 1, :extra => 0.01, :acc_a => 0.01, :acc_b => 0.01},
        :score => {:base => 1, :extra => 0.03, :acc_a => 0.04, :acc_b => 0.06},
        :await => 3, :dwait => 6, :amax => 50, :dmax => 50,
      },
      :bar => {
        :shrink => 0.002, :goal => 0.2, :fail => 1000000,
        :speed => [1,2], :mwait => 2,
        :wait => 120, :chance => 60,
      },
    },
    # Add more game settings here if you want!
  }
 
end
#===============================================================================
# End of Settings! Editing anything below may lead to... you know it, right?
#===============================================================================

class Game_Interpreter
 
  def start_range_game(level,x,y)
    game_on = RangeeMiniGame.new(level,[x,y])
    while $game_system.minigames(:range)[:active] == true
      return if !$game_system.minigames(:range)[:active]
      Fiber.yield
      game_on.update
    end
  end
    
  def change_range_imgs(type,prop,data)
    $game_system.minigames(:range)[:imgs][type][prop] = data
  end
 
end

class RangeeMiniGame

  def initialize(level,pos)
    if RangeMiniGame::Sounds[:bgm]
      @map_bgm = RPG::BGM.last
      RangeMiniGame::Sounds[:bgm].play
    end
    $game_system.minigames(:range)[:active] = true
    $game_system.minigames(:range)[:score][:current] = 0
    @phase = :start
    @pos = pos
    @data = RangeMiniGame::Games[level]
    @imgs = {}
    [:back,:bar,:cursor].each {|type| init_images(type)}
    @score = ScoreDisplay.new(pos,:range) if RangeMiniGame::UseScore
    @failbar = FailBar.new(pos,:range)
  end
 
  def init_images(type)
    dt = $game_system.minigames(:range)[:imgs][type]
    @imgs[type] = Sprite.new
    @imgs[type].bitmap = Cache.custom_imgs(dt[:img],RangeMiniGame::ImgFolder)
    @imgs[type].opacity = dt[:opa]
    @imgs[type].z = dt[:z]
    @imgs[type].ox = @imgs[type].bitmap.width/2
    @imgs[type].oy = @imgs[type].bitmap.height/2
    @imgs[type].x = @pos[0]
    @imgs[type].y = @pos[1]
  end
    
  def update
    case @phase
    when :start
      update_start_game
    when :game
      update_game
    when :end
      update_end_game
    when :dispose
      dispose
    end
    @pop.update if [email protected]?
  end
 
  def update_start_game
    @pop = ResultPop.new(:range,:start,@pos) if @pop.nil?
    if @pop.phase == :wait && Input.trigger?(:C)
      RangeMiniGame::Sounds[:start].play
      @bdir = [-1,1].sample
      @in_range = @cdir = @fail = @acc = @ctimer = @btimer = @mtimer = 0
    end
    if @pop.disposed?
      @phase = :game
      @pop = nil
    end
  end
 
  def update_game
    if Input.press?(:RIGHT)
      update_cursor_data(1)
    elsif Input.press?(:LEFT)
      update_cursor_data(-1)
    else
      update_cursor_data(0)
    end
    update_positions
    update_bar_shrinking
  end
 
  def update_cursor_data(dir)
    prev_dir = @cdir
    @cdir = dir
    if @cdir != prev_dir
      @ctimer = 0
    end
    case dir
    when 0
      if @acc != 0 && @ctimer % @data[:cursor][:dwait] == 0
        if @acc > 0
          @acc -= 1
          @acc = 0 if @acc < 0
        end
        if @acc < 0
          @acc += 1
          @acc = 0 if @acc > 0
        end
      end
    when 1
      @acc += 1
      @acc = @data[:cursor][:amax] if @acc > @data[:cursor][:amax]
    when -1
      @acc -= 1
      @acc = -@data[:cursor][:amax] if @acc < -@data[:cursor][:amax]
    end
  end
 
  def acc_level(level,type)
    lv = level.to_f
    basis = @data[:cursor][type][:base].to_f
    extra = @data[:cursor][type][:extra].to_f
    acc_a = @data[:cursor][type][:acc_a].to_f
    acc_b = @data[:cursor][type][:acc_b].to_f
    return (basis*((lv-1)**(0.9+acc_a/250))*lv*(lv+1)/
      (6+lv**2/50/acc_b)+(lv-1)*extra).round.to_i
  end

  def update_positions
    @btimer += 1
    @ctimer += 1
    @mtimer += 1
    move = @acc != 0 ? acc_level(@acc.abs,:acc) : 0
    if @acc > 0
      @imgs[:cursor].x += move
    elsif @acc < 0
      @imgs[:cursor].x -= move.abs
    end
    @bdir = [-1,1].sample if @btimer % @data[:bar][:wait] == 0 && @data[:bar][:chance] > rand(100)
    if @mtimer % @data[:bar][:mwait] == 0
      @imgs[:bar].x += SixthNum.random(*@data[:bar][:speed]) * @bdir
    end
    bmax = @imgs[:back].x + @imgs[:back].bitmap.width/2
    bmin = @imgs[:back].x - @imgs[:back].bitmap.width/2
    if @imgs[:cursor].x <= bmin
      @imgs[:cursor].x = bmin
    elsif @imgs[:cursor].x >= bmax
      @imgs[:cursor].x = bmax
    end
    if @imgs[:bar].x - @imgs[:bar].zoom_x * @imgs[:bar].bitmap.width/2 <= bmin
      @imgs[:bar].x = bmin + @imgs[:bar].zoom_x * @imgs[:bar].bitmap.width/2
      @bdir = 1; @btimer = 0
    elsif @imgs[:bar].x + @imgs[:bar].zoom_x * @imgs[:bar].bitmap.width/2 >= bmax
      @imgs[:bar].x = bmax - @imgs[:bar].zoom_x * @imgs[:bar].bitmap.width/2
      @bdir = -1; @btimer = 0
    end
  end
 
  def update_bar_shrinking
    tolerance = @imgs[:bar].zoom_x * @imgs[:bar].bitmap.width/2
    dist = (@imgs[:cursor].x - @imgs[:bar].x).abs
    if dist <= tolerance
      @in_range += 1
      $game_system.minigames(:range)[:score][:current] += acc_level(@in_range,:score)
      @score.set_score(:current) if RangeMiniGame::UseScore
      @imgs[:bar].zoom_x -= @data[:bar][:shrink]
      if @imgs[:bar].zoom_x <= @data[:bar][:goal]
        @pop = ResultPop.new(:range,:success,@pos)
        RangeMiniGame::Sounds[:win].play
        $game_system.minigames(:range)[:score][:win] += 1
        if $game_system.minigames(:range)[:score][:current] > $game_system.minigames(:range)[:score][:high]
          $game_system.minigames(:range)[:score][:high] = $game_system.minigames(:range)[:score][:current]
        end
        $game_system.minigames(:range)[:score][:total] += $game_system.minigames(:range)[:score][:current]
        @score.set_score(:total) if RangeMiniGame::UseScore
        $game_system.minigames(:range)[:result] = true
        @phase = :end
      end
    else
      @fail += dist
      rate = @fail.to_f/@data[:bar][:fail]
      @failbar.set_life(rate)
      @in_range = 0
      if @fail >= @data[:bar][:fail]
        @pop = ResultPop.new(:range,:fail,@pos)
        RangeMiniGame::Sounds[:lose].play
        $game_system.minigames(:range)[:score][:lose] += 1
        $game_system.minigames(:range)[:result] = false
        @phase = :end
      end
    end
  end
 
  def update_end_game
    if @pop.phase == :wait && Input.trigger?(:C)
      RangeMiniGame::Sounds[:exit].play
      @phase = :dispose
    end
  end
    
  def dispose
    if @pop.disposed?
      @imgs.each_value {|sp| sp.bitmap.dispose; sp.dispose}
      @score.dispose if RangeMiniGame::UseScore
      @failbar.dispose
      $game_system.minigames(:range)[:active] = false
      @map_bgm.replay if RangeMiniGame::Sounds[:bgm]
    end
  end
 
end
#==============================================================================
# !!END OF SCRIPT - OHH, NOES!!
#==============================================================================

I've moved this to Script Support.

Original thread: https://forums.rpgmakerweb.com/threads/stay-in-range-minigame.128555/