Create Autosave no matter what

Hi guys,

I'm currently having some gambling games like Poker and Blackjack. I consider those my "smaller games" which I try to improve at the moment.

Because those games rely on gambling only, I don't really want to allow my players to abuse the save option. If they lose all their chips by playing bad, I don't want to give them the ability to simply load a previous save game and try again having their chips stack recovered. My current solution for this games is to not allow saving the game at all, which isn't optimal either as it may discourage players from even playing these games. Imagine you gamble your way up from 500 to 1000 chips just to know it means nothing as your progress will be lost upon closing the game. That is my current dilemma.

Now, what I'm thinking of - while not even knowing if this is possible - is having the ability to create a single autosave that is created (if not present) or overwritten (if already present) in any given scenario:
  • when the game is ended normally (Shutdown command)
  • when the game is ended using the normal F12 reset
  • when the game is ended by closing the game window using "X" or ALT+F4
  • when the game is ended by shutting it down using Win Task Manager
Basically, if I were able to create or update a single auto save file (without giving the player any other "manual" save options) right before the player returns to the title menu (by ending the game or using F12) and before any other scenario that shuts the Game.EXE down, this would be insane.

I know this is an unusual request and I don't know if that is even possible and if so, how much work this will require.

Hoping to get any input or help (best case) here. :LZScheeze:

Yours
TwoFace
What I don't like about your request is the F12 and task manager parts. They're supposed to abruptly terminate the game session one way or another, and it could corrupt the saved game because of an open data stream. It has to be saved after every turn only, IMHO.
What I don't like about your request is the F12 and task manager parts. They're supposed to abruptly terminate the game session one way or another, and it could corrupt the saved game because of an open data stream. It has to be saved after every turn only, IMHO.
I get your point. I lack of ideas on how to workaround this one, however, for me it would also be fine to have the autosave be created/updated every x Frames if that makes it more possible without affecting the game's performance too much. That said, with those time difference between each save, technically, players could cheat by closing the game between the time window of two autosaves, however, they most likely won't because they don't know about this, right? Also, it would be unlikely they could benefit from it in any way.
A possible solution that I would recommend is that of saving players data BEFORE displaying gambling results.
Everything happens in the background and is saved, than things are displayed.

This way players will have their data overwritten before knowing the result. Once they see it, it is already too late, even if they want to close the game.
A possible solution that I would recommend is that of saving players data BEFORE displaying gambling results.
Everything happens in the background and is saved, than things are displayed.
This also makes sense for me. Maybe we could also trigger the save upon the chips value increase or decrease. Would be also possible.

I'm gonna post the two scripts I'm using. I don't use both of them in the same game. Each script is a different game.

Spoiler: Scripts
The chips for this one are equal to Gold. Chips means Gold.

Spoiler: Blackjack
Ruby:
#==============================================================================
# ** RMW 2016 Christmas Gift - Blackjack
#    Code written by Kazama
#    Bundled Graphics by http://kenney.nl/
#------------------------------------------------------------------------------
#  * Updates
#  - 1.0.0 Base Script
#------------------------------------------------------------------------------
#  * Description
#  Blackjack is a very simple card game and is very fun to play. Although,
#  I've never actually seen one written and released for any of the makers.
#  So, I'd like to present this script as a gift from me to you.
#------------------------------------------------------------------------------
#  * Features
#  - Basic Blackjack
#  - Bundled Graphical set for quick Installation
#  - Basic Score keeping using Variables
#  - Adjustable Audio Settings for various moments
#  - Adjustable Messages for various moments
#  - YOU MAY REQUEST ADDITIONAL FEATURES IF YOU LIKE
#------------------------------------------------------------------------------
#  * License
#  - Both Non-Commercial and Commercial usage is allowed.
#  - Credit Kazama for the code.
#  - Credit Kenney for the wonderful graphical assets.
#  - Do not distribute or repost on other websites.
#  - Free to edit for personal usage but do not post your edits.
#  - Feel free to Donate if you'd like too. (not required at all)
#------------------------------------------------------------------------------
#  * Engine
#  - This script only works in the RPG Maker VX Ace engine.
#------------------------------------------------------------------------------
#  * How to Use
#  If you're using everything included in the sample project, then all you
#  will have to do is use a script call: SceneManager.call(Scene_KCG_Blackjack)
#  The script will handle the rest.
#------------------------------------------------------------------------------
#  * Extra Notes
#  Being a member for a full year on RMW has been pretty great. You all have
#  been so kind and supportive of all the work I've done. So this me hoping
#  I'll be able to give back some more! Happy Holidays and game making!
#==============================================================================

module KCG_Blackjack_Settings

    # Base Settings #

    # Determine the player's name.
    PLAYER_NAME = Tw0Face_Translate::SpielerName

    # Determine the Dealer's name.
    DEALER_NAME = Tw0Face_Translate::DealerName

    # Determine what value the Dealer will stand at.
  STAND_POINT = 17

  # Determine what Variable the victories will be stored in.
  VICTORY_VARIABLE = 98

  # Determine what Variable the defeats will be stored in.
  DEFEAT_VARIABLE = 99

  # Message Settings #

  BLACKJACK = Tw0Face_Translate::GewonnenBlackJack
  PLAYER_BEAT_DEALER = Tw0Face_Translate::Gewonnen
  DEALER_BEAT_PLAYER = Tw0Face_Translate::Verloren
  DEALER_BUSTED = Tw0Face_Translate::DealerBusted
  PLAYER_BUSTED = Tw0Face_Translate::PlayerBusted
  PARTICIPANTS_TIED = Tw0Face_Translate::Tie

    # Audio Settings #

    # Determine the BGM track played. (filename, volume, pitch)
    BGM_TRACK = ["1-07 158-B - White Elephants _Back it Up_ Mix (Loop)", 80, 100]

    # Determine the Victory ME played. (filename, volume, pitch)
    SE_VICTORY = ["Applause2", 80, 100]

    # Determine the Tied ME played. (filename, volume, pitch)
    SE_TIED = ["Miss", 80, 100]

    # Determine the Defeat ME played. (filename, volume, pitch)
    SE_DEFEAT = ["Disappointment", 80, 100]

    # Update 1.?.? Settings #
    # None yet. But if one of us think of something, I'll add it here.

end

# Do not modify these values out of curiosity. You will break the script.
SUIT = ["Clubs", "Hearts", "Spades", "Diamonds"]
FACE = [2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A"]

#==============================================================================
# ** Cache
#------------------------------------------------------------------------------
#  This module loads graphics, creates bitmap objects, and retains them.
# To speed up load times and conserve memory, this module holds the
# created bitmap object in the internal hash, allowing the program to
# return preexisting objects when the same bitmap is requested again.
#==============================================================================

module Cache
  #--------------------------------------------------------------------------
  # * Get Blackjack Graphic
  #--------------------------------------------------------------------------
  def self.kcg_blackjack(filename)
    load_bitmap("Graphics/Blackjack/", filename)
  end
end

#==============================================================================
# ** KCG_Card
#------------------------------------------------------------------------------
#  This class handles a card object. Each card is handled as a separate object
# instance and is then passed on to the 'Deck of Cards'.
#==============================================================================

class KCG_Card
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_reader :suit, :face, :value
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize(suit, face)
        # Get Suit and Face for a Card
        @suit, @face = suit, face
    end
    #--------------------------------------------------------------------------
    # * Get Value for each Card
    #--------------------------------------------------------------------------
    def value
        # Go through each face and assign a value to it.
        case @face
        when 2..10 then @value = @face
        when "J", "Q", "K" then @value = 10
        when "A" then @value = 11
        end
        # Return Value of Card
        return @value
    end
    #--------------------------------------------------------------------------
    # * Convert Card to a Readable String
    #--------------------------------------------------------------------------
    def to_s
        @face.to_s + "_of_" + @suit
    end
end

#==============================================================================
# ** KCG_Deck
#------------------------------------------------------------------------------
#  This class handles a deck of cards.
#==============================================================================

class KCG_Deck
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_accessor :cards
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
        # Create Card Array
        @cards = Array.new
        # Map Cards to Array
        map_cards_to_array
    end
    #--------------------------------------------------------------------------
    # * Map Cards to the Array
    #--------------------------------------------------------------------------
    def map_cards_to_array
        # Go through each Suit
        SUIT.each do |suit|
            # Go through each Face
            FACE.each do |face|
                # Push a Card to the Deck Array
                @cards.push(KCG_Card.new(suit, face))
            end
        end
    end
    #--------------------------------------------------------------------------
    # * Shuffle the Deck
    #--------------------------------------------------------------------------
    def shuffle!
        @cards.shuffle!
    end
    #--------------------------------------------------------------------------
    # * Draw Card from Deck
    #--------------------------------------------------------------------------
    def draw_card
        @cards.pop
    end
    #--------------------------------------------------------------------------
    # * Get Remaining Cards in the Deck
    #--------------------------------------------------------------------------
    def remaining
        @cards.length
    end
end

#==============================================================================
# ** KCG_Participant
#------------------------------------------------------------------------------
#  This class handles participants in the game. It's used for both players
# and dealers.
#==============================================================================

class KCG_Participant
    #--------------------------------------------------------------------------
    # * Included Modules
    #--------------------------------------------------------------------------
    include KCG_Blackjack_Settings
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_reader :hand_sprites
    attr_accessor :hand, :hand_value, :ace_count, :index
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize(index)
        # Acquire participant index
        @index = index
        # Reset all Settings
        reset_participant_data
    end
    #--------------------------------------------------------------------------
    # * Reset Participant Data
    #--------------------------------------------------------------------------
    def reset_participant_data
        # Create a new Hand Array
        @hand = Array.new
        # Create a new Hand Sprite Array
        @hand_sprites = Array.new
        # Set Hand Value
        @hand_value = 0
        # Set Ace Count
        @ace_count = 0
    end
    #--------------------------------------------------------------------------
    # * Determine an Ace Card's Value
    #--------------------------------------------------------------------------
    def determine_ace_value
        # Adjust hand value while total is over 21 and ace cards are present
        while @hand_value > 21 and @ace_count > 0
            # Remove the Ace card and subtract the points
            @ace_count -= 1 ; @hand_value -= 10
        end
    end
    #--------------------------------------------------------------------------
    # * Deal Card to Participant
    #--------------------------------------------------------------------------
    def deal_card
        # Grab card object from the Deck
        card = SceneManager.scene.deck.draw_card
        # Add the value of the card to the Hand
        @hand_value += card.value
        # Add to the Ace Pile if we Acquire an Ace
        @ace_count += 1 if card.value == 11
        # Push Card to the Hand
        @hand.push(card)
        # Double check the value of aces and apply any changes
        determine_ace_value
        # Get the Sprite X-Position
        sx_position = @hand.length * 72
        # Get the Sprite Y-Position
        sy_position = @index > 0 ? 135 : Graphics.height - 135#100
        # Get the Sprite Filename
        s_filename = card.to_s
        # Push Sprite to the Hand Sprite Array
        @hand_sprites.push(Sprite_Card.new(s_filename, sx_position, sy_position))
        # Hide the Original Card if the Participant is the dealer
        @hand_sprites[0].hide_card if @index > 0
    end
    #--------------------------------------------------------------------------
    # * Dispose Cards
    #--------------------------------------------------------------------------
    def dispose_cards
        # Go through all sprites and dispose them
        @hand_sprites.each { |card| card.dispose }
        # Reset Participant Data
        reset_participant_data
    end
    #--------------------------------------------------------------------------
    # * Get Participant Name
    #--------------------------------------------------------------------------
    def name
        @index > 0 ? DEALER_NAME : PLAYER_NAME
    end
end

#==============================================================================
# ** Sprite_Felt
#------------------------------------------------------------------------------
#  This sprite displays a felt background on screen.
#==============================================================================

class Sprite_Felt < Sprite
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
        super(nil)
        # Create Bitmap Image
        self.bitmap = Cache.kcg_blackjack("Felt_Background")
    end
    #--------------------------------------------------------------------------
    # * Free
    #--------------------------------------------------------------------------
    def dispose
        # Dispose Bitmap unless it's nil or already disposed
        bitmap.dispose unless (bitmap.nil? or bitmap.disposed?)
        super
    end
end

#==============================================================================
# ** Sprite_Card
#------------------------------------------------------------------------------
#  This sprite displays a card on the screen based on card data found in
# a participant's hand.
#==============================================================================

class Sprite_Card < Sprite
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize(filename, x, y)
        super(nil)
        # Create Bitmap Image
        self.bitmap = Cache.kcg_blackjack(filename)
        # Set the Zoom Factor of the sprite (nearest neighbor)
        self.zoom_x = self.zoom_y = 0.5
        # Set Origin X and Y of the sprite
        self.ox, self.oy = bitmap.width / 2, bitmap.height / 2
        # Set X and Y positions
        self.x, self.y = x, y
        # Get Filename Tag
        @filename = filename
    end
    #--------------------------------------------------------------------------
    # * Hide Card Sprite
    #--------------------------------------------------------------------------
    def hide_card
        # Clone the Filename
        @last_card = @filename.dup
        # Dispose Bitmap unless it's nil or already disposed
        bitmap.dispose unless (bitmap.nil? or bitmap.disposed?)
        # Create Bitmap Image
        self.bitmap = Cache.kcg_blackjack("back_of_deck")
    end
    #--------------------------------------------------------------------------
    # * Show Card Sprite
    #--------------------------------------------------------------------------
    def show_card
        # Dispose Bitmap unless it's nil or already disposed
        bitmap.dispose unless (bitmap.nil? or bitmap.disposed?)
        # Create Bitmap Image
        self.bitmap = Cache.kcg_blackjack(@last_card)
    end
    #--------------------------------------------------------------------------
    # * Free
    #--------------------------------------------------------------------------
    def dispose
        # Dispose Bitmap unless it's nil or already disposed
        bitmap.dispose unless (bitmap.nil? or bitmap.disposed?)
        super
    end
end

#==============================================================================
# ** Window_KCG_Status
#------------------------------------------------------------------------------
#  This window displays the name of participant and their hand value.
#==============================================================================

class Window_KCG_Status < Window_Base
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_reader :participant, :show_value
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize(participant)
        super(0, 0, Graphics.width / 2, fitting_height(1))
        # Get Participant
        @participant = participant
        # Set Show Flag to False
        @show_value = false
        # Refresh Name
        refresh_name
    end
    #--------------------------------------------------------------------------
    # * Set Value Boolean
    #--------------------------------------------------------------------------
    def show_value=(boolean)
        # Set Boolean to Show Flag
        @show_value = boolean
        # Refresh Value
        refresh_value
    end
    #--------------------------------------------------------------------------
    # * Refresh
    #--------------------------------------------------------------------------
    def refresh_name
        # Clear Contents Rect
        contents.clear_rect(0, 0, contents.width / 2, 24)
        # Draw Participant Name
        draw_text(contents.rect, @participant.name)
    end
    #--------------------------------------------------------------------------
    # * Refresh Value
    #--------------------------------------------------------------------------
    def refresh_value
        # Clear Contents Rect
        contents.clear_rect(contents.width / 2 - 24, 0, contents.width / 2 + 24, 24)
        # Get Value
        value = @show_value ? @participant.hand_value : "? "
        # Draw Participant Hand Value
        draw_text(contents.rect, "#{Tw0Face_Translate::Wert} #{value.to_s}", 2)
    end
end

#==============================================================================
# ** Window_KCG_Actions
#------------------------------------------------------------------------------
#  This window displays variable actions that the player can perform.
#==============================================================================

class Window_KCG_Actions < Window_HorzCommand
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
        super(Graphics.width / 2, Graphics.height - window_height)
    end
    #--------------------------------------------------------------------------
    # * Get Window Width
    #--------------------------------------------------------------------------
    def window_width
        return Graphics.width / 2
    end
    #--------------------------------------------------------------------------
    # * Get Digit Count
    #--------------------------------------------------------------------------
    def col_max
        return item_max
    end
    #--------------------------------------------------------------------------
    # * Create Command List
    #--------------------------------------------------------------------------
    def make_command_list
        add_command(Tw0Face_Translate::HIT, :hit)
        add_command(Tw0Face_Translate::STAY, :stay)
        #add_command(Tw0Face_Translate::RETIRE, :retire)
    end
end

#==============================================================================
# ** Window_KCG_Result
#------------------------------------------------------------------------------
#  This window displays the final post-round results.
#==============================================================================

class Window_KCG_Result < Window_Command
    #--------------------------------------------------------------------------
    # * Included Modules
    #--------------------------------------------------------------------------
    include KCG_Blackjack_Settings
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
        super(0, 0)
        # Set X-Position
        self.x = (Graphics.width - window_width) / 2
        # Set Y-Position
        self.y = (Graphics.height - window_height) / 2
        # Set Openness
        self.openness = 0
        # Set Default Message
        @message = ""
    end
    #--------------------------------------------------------------------------
    # * Get Window Width
    #--------------------------------------------------------------------------
    def window_width
        return Graphics.width / 1.2
    end
    #--------------------------------------------------------------------------
    # * Get Window Height
    #--------------------------------------------------------------------------
    def window_height
        return fitting_height(4)
    end
    #--------------------------------------------------------------------------
    # * Get Digit Count
    #--------------------------------------------------------------------------
    def col_max
        return item_max
    end
    #--------------------------------------------------------------------------
    # * Get Alignment
    #--------------------------------------------------------------------------
    def alignment
        return 1
    end
    #--------------------------------------------------------------------------
    # * Create Command List
    #--------------------------------------------------------------------------
    def make_command_list
        add_command(Tw0Face_Translate::NEXTROUND, :next_round)
        add_command(Tw0Face_Translate::RETIRE, :retire)
    end
    #--------------------------------------------------------------------------
  # * Get Rectangle for Drawing Items
  #--------------------------------------------------------------------------
  def item_rect(index)
      # Get original Rectangle
      rect = super(index)
      # Modify Y-Position
      rect.y += line_height * 3
      # Return new Rectangle
      rect
  end
  #--------------------------------------------------------------------------
  # * Set Message
  #--------------------------------------------------------------------------
  def set_message=(message)
      # Set Message Text
      @message = message
      # Refresh Contents
      refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
      super
      # Change Color to Crisis Color
      #change_color(crisis_color)
      # Draw Message
      draw_text(0, 0, contents.width, line_height, @message, 1)
      # Change Color to System Color
      #change_color(system_color)
      # Draw Victory Header
      draw_text(0, line_height, contents.width, line_height, Tw0Face_Translate::Victories)
      # Draw Defeat Header
      draw_text(0, line_height * 2, contents.width, line_height, Tw0Face_Translate::Defeats)
      # Change Color to Normal Color
      change_color(normal_color)
      # Get Victory Variable
      victory_variable = $game_variables[VICTORY_VARIABLE]
      # Get Defeat Variable
      loss_variable = $game_variables[DEFEAT_VARIABLE]
      # Draw Victory Variable
      draw_text(0, line_height, contents.width, line_height, victory_variable, 2)
      # Draw Defeat Variable
      draw_text(0, line_height * 2, contents.width, line_height, loss_variable, 2)
  end
end

#==============================================================================
# ** Scene_KCG_Blackjack
#------------------------------------------------------------------------------
#  This class performs blackjack processing.
#==============================================================================

class Scene_KCG_Blackjack < Scene_Base
    #--------------------------------------------------------------------------
    # * Included Modules
    #--------------------------------------------------------------------------
    include KCG_Blackjack_Settings
    #--------------------------------------------------------------------------
    # * Public Instance Variables
    #--------------------------------------------------------------------------
    attr_reader :deck
    #--------------------------------------------------------------------------
    # * Start Processing
    #--------------------------------------------------------------------------
    def start
        super
    @gold_window = Window_Gold.new
    @gold_window.x = Graphics.width - @gold_window.width
    @gold_window.y = 0
    @gold_window.openness = 255
        # Save Game BGM
        $game_system.save_bgm
        # Create Background Felt
        @background = Sprite_Felt.new
        # Create Player Object
        @player = KCG_Participant.new(0)
        # Create Dealer Object
        @dealer = KCG_Participant.new(1)
        # Create Player Status Window
        @player_status_window = Window_KCG_Status.new(@player)
        # Set Player Status Window Y-Position
        @player_status_window.y = Graphics.height - 48
        # Show Player Value
        @player_status_window.show_value = true
        # Create Dealer Status Window
        @dealer_status_window = Window_KCG_Status.new(@dealer)
        # Create Action Window
        @actions_window = Window_KCG_Actions.new
        # Set Action Window Handlers
        @actions_window.set_handler(:hit, method(:on_action_hit))
        @actions_window.set_handler(:stay, method(:on_action_stay))
        @actions_window.set_handler(:retire, method(:return_scene))
        # Create Result Window
        @result_window = Window_KCG_Result.new
        # Set Result Window Handlers
        @result_window.set_handler(:next_round, method(:reset_game_data))
        @result_window.set_handler(:retire, method(:return_scene))
    # Reset Game Data
        reset_game_data
        # Judge Win/Loss Initially
        judge_win_loss(true)
    end
    #--------------------------------------------------------------------------
    # * Reset Game Data
    #--------------------------------------------------------------------------
    def reset_game_data
    if $game_party.gold >= $game_variables[1]
        # Close Result Window unless it's nil
        @result_window.close unless @result_window.nil?
        # Stop All Audio
        #RPG::BGM.stop ;
    RPG::SE.stop
    Sound.play_ok
        # Play Theme BGM
        #RPG::BGM.new(*BGM_TRACK).play
        # Create a new Deck and Shuffle it
        @deck = KCG_Deck.new ; @deck.shuffle!
        # Dispose Player and Dealer Cards
        @player.dispose_cards ; @dealer.dispose_cards
        # Deal 2 Cards to the Player and Dealer
        2.times { @player.deal_card ; @dealer.deal_card }
    # Force Dealer Value to Hide
    @dealer_status_window.show_value = false
        # Refresh Player and Dealer Status Window
        @player_status_window.refresh_value ; @dealer_status_window.refresh_value
        # Activate Action Window and Select the First Command
        @actions_window.activate.select(0)
  else
    Sound.play_buzzer
    SceneManager.return
    $game_switches[1] = true
    end
    end
    #--------------------------------------------------------------------------
    # * On Action Hit
    #--------------------------------------------------------------------------
    def on_action_hit
    
        # Deal Card to Player
        @player.deal_card
        # Refresh Player Status Window
        @player_status_window.refresh_value
        # Activate Action Window
        @actions_window.activate
        # Judge Win/Loss unless Player's hand value is under 21
        judge_win_loss unless @player.hand_value < 21
    end
    #--------------------------------------------------------------------------
    # * On Action Stay
    #--------------------------------------------------------------------------
    def on_action_stay
        # Deal Cards to the Dealer until conditions are met
        until @dealer.hand_value >= STAND_POINT
            # Deal Card to Dealer
            @dealer.deal_card
            # Refresh Dealer Status Window
            @dealer_status_window.refresh_value
        end
        # Judge Win/Loss
        judge_win_loss
    end
    #--------------------------------------------------------------------------
    # * Wait for Result Window
    #--------------------------------------------------------------------------
    def wait_for_result_window
        # Open Result Window
      @result_window.open.activate
      # Deactivate Action Window
      @actions_window.deactivate
  end
    #--------------------------------------------------------------------------
  # * Determine Win/Loss Results
  #--------------------------------------------------------------------------
  def judge_win_loss(inital_check = false)
      # Check for Blackjack
      if @player.hand_value == 21
          # Add 1 to Victory Variable
          $game_variables[VICTORY_VARIABLE] += 1
      $game_party.gain_gold(+$game_variables[1]*3/2)
      @gold_window.refresh
          # Play Victory ME
          play_result_track(:victory)
          # Show Dealer's Card
          @dealer.hand_sprites[0].show_card
          # Show Dealer's Value
          @dealer_status_window.show_value = true
          # Set Result Message
          @result_window.set_message = BLACKJACK
          # Wait for Result Window to show
          wait_for_result_window
          # Replay Main Game BGM
      $game_system.replay_bgm
          # Break any additional Checks
          return
      end
      # Return if we just want the initial check
      return unless !inital_check
      # Check if Dealer has Busted
      if @dealer.hand_value > 21
          # Add 1 to Victory Variable
          $game_variables[VICTORY_VARIABLE] += 1
      $game_party.gain_gold(+$game_variables[1])
      @gold_window.refresh
          # Play Victory ME
          play_result_track(:victory)
          # Show Dealer's Card
          @dealer.hand_sprites[0].show_card
          # Show Dealer's Value
          @dealer_status_window.show_value = true
          # Set Result Message
          @result_window.set_message = DEALER_BUSTED
          # Wait for Result Window to show
          wait_for_result_window
          # Replay Main Game BGM
      $game_system.replay_bgm
          # Break any additional Checks
          return
      end
      # Check Results Based if Player has stayed
      if @player.hand_value <= 21
          # If Player's hand is greater then the Dealer's hand
          if @player.hand_value > @dealer.hand_value
              # Add 1 to Victory Variable
              $game_variables[VICTORY_VARIABLE] += 1
        $game_party.gain_gold(+$game_variables[1])
        @gold_window.refresh
              # Play Victory ME
              play_result_track(:victory)
              # Show Dealer's Card
              @dealer.hand_sprites[0].show_card
              # Show Dealer's Value
              @dealer_status_window.show_value = true
              # Set Result Message
              @result_window.set_message = PLAYER_BEAT_DEALER
              # Wait for Result Window to show
              wait_for_result_window
              # Replay Main Game BGM
        $game_system.replay_bgm
              # Break any additional Checks
              return
              # If Player and Dealer are Tied
          elsif @player.hand_value == @dealer.hand_value
        @gold_window.refresh
              # Play Tied ME
              play_result_track(:tied)
              # Show Dealer's Card
              @dealer.hand_sprites[0].show_card
              # Show Dealer's Value
              @dealer_status_window.show_value = true
              # Set Result Message
              @result_window.set_message = PARTICIPANTS_TIED
              # Wait for Result Window to show
              wait_for_result_window
              # Replay Main Game BGM
        $game_system.replay_bgm
              # Break any additional Checks
              return
              # If Dealer has beaten the Player
          else
              # Add 1 to Defeat Variable
              $game_variables[DEFEAT_VARIABLE] += 1
        $game_party.gain_gold(-$game_variables[1])
        @gold_window.refresh
              # Play Victory ME
              play_result_track(:defeat)
              # Show Dealer's Card
              @dealer.hand_sprites[0].show_card
              # Show Dealer's Value
              @dealer_status_window.show_value = true
              # Set Result Message
              @result_window.set_message = DEALER_BEAT_PLAYER
              # Wait for Result Window to show
              wait_for_result_window
              # Replay Main Game BGM
        $game_system.replay_bgm
              # Break any additional Checks
              return
              # Check if Player has Busted
      end
    else
      # Add 1 to Defeat Variable
      $game_variables[DEFEAT_VARIABLE] += 1
      $game_party.gain_gold(-$game_variables[1])
      @gold_window.refresh
      # Play Victory ME
      play_result_track(:defeat)
      # Show Dealer's Card
      @dealer.hand_sprites[0].show_card
      # Show Dealer's Value
      @dealer_status_window.show_value = true
      # Set Result Message
      @result_window.set_message = PLAYER_BUSTED
      # Wait for Result Window to show
      wait_for_result_window
      # Replay Main Game BGM
      $game_system.replay_bgm
      # Break any additional Checks
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Play Result ME
  #--------------------------------------------------------------------------
  def play_result_track(type)
      # Get Meta Type
      case type
      when :victory then meta = SE_VICTORY
      when :tied then meta = SE_TIED
      when :defeat then meta = SE_DEFEAT
      end
      # Stop Blackjack BGM
      #RPG::BGM.stop
      # Play Result ME
      RPG::SE.new(*meta).play
  end
end

The chips stack for this one are defined by Variable 7 (IDV_COIN)

Spoiler: Poker
Ruby:
#******************************************************************************
#
#    * ポーカー
#
#  --------------------------------------------------------------------------
#    バージョン : 1.0.2
#    対      応 : RPGツクールVX Ace : RGSS3
#    制  作  者 : CACAO
#    配  布  元 : http://cacaosoft.webcrow.jp/
#  --------------------------------------------------------------------------
#   == 概    要 ==
#
#    : ポーカーの機能を追加します。
#
#  --------------------------------------------------------------------------
#   == 注意事項 ==
#
#    ※ 動作には、トランプの画像が必要です。
#
#  --------------------------------------------------------------------------
#   == 使用方法 ==
#
#    ★ ポーカーの開始
#     イベントコマンド「スクリプト」に start_poker と記述
#
#
#******************************************************************************


#==============================================================================
# ◆ 設定項目
#==============================================================================
module CAO
module Poker
  #--------------------------------------------------------------------------
  # ◇ コインを保存するEV変数の番号
  #--------------------------------------------------------------------------
  IDV_COIN = 7
  #--------------------------------------------------------------------------
  # ◇ 掛け金で最初に表示される枚数
  #--------------------------------------------------------------------------
  DEFAULT_COIN = 100
  #--------------------------------------------------------------------------
  # ◇ 掛け金の増減数
  #--------------------------------------------------------------------------
  BET_RATE = 10
  #--------------------------------------------------------------------------
  # ◇ 掛け金の最大枚数
  #--------------------------------------------------------------------------
  MAX_BET = 1000
  #--------------------------------------------------------------------------
  # ◇ 掛け金の増加量 ( n 倍)
  #--------------------------------------------------------------------------
  DIVIDEND_COVER = [0, 1, 2, 3, 5, 7, 10, 50, 100, 500]
  #--------------------------------------------------------------------------
  # ◇ 配当金の下三桁が 000 の場合 K と表示する
  #--------------------------------------------------------------------------
  ADDR_DIVIDEND = true
  #--------------------------------------------------------------------------
  # ◇ 役の名前
  #--------------------------------------------------------------------------
  VOCAB_HANDS = [ "High Card", "One Pair", "Two Pair", "Three of a Kind",
                  "Straight", "Flush", "Full House", "Four of a Kind",
                  "Straight Flush", "Royal Flush" ]
  #--------------------------------------------------------------------------
  # ◇ 掛け金の名称と単位
  #--------------------------------------------------------------------------
  VOCAB_COIN = ""
  VOCAB_COIN_U = " Chips"
  #--------------------------------------------------------------------------
  # ◇ 掛け金選択時のメッセージ
  #--------------------------------------------------------------------------
  VOCAB_BET  = "Choose your bet."
  #--------------------------------------------------------------------------
  # ◇ 1ゲーム終了後のメッセージ
  #--------------------------------------------------------------------------
  VOCAB_WIN  = "Congratulations! You have won\n\\C[3]%s \\C[0]Chips."
  VOCAB_LOSE = "You lost. You got \\C[3]%s \\C[0]Chips."
  #--------------------------------------------------------------------------
  # ◇ ヘルプウィンドウの文章
  #--------------------------------------------------------------------------
  VOCAB_HELP = "Poker Hand Ranking"
  DESC_ICON = 1951
  #--------------------------------------------------------------------------
  # ◇ ゲームの説明
  #--------------------------------------------------------------------------
  MANUAL_LINE = 13            # 行数
  TEXT_MANUAL = <<-'[EOS]'    # 文章 (次の行から [EOS] まで)
        \{Poker Hand Ranking\}
 
  1. \C[16]Royal Flush\C[0]      \I[5604] \I[5603] \I[5602] \I[5601] \I[5600]
  2. \C[16]Straight Flush\C[0]   \I[5561] \I[5560] \I[5559] \I[5558] \I[5557]
  3. \C[16]Four of a Kind\C[0]   \I[5600] \I[5568] \I[5584] \I[5552] \I[5612]
  4. \C[16]Full House\C[0]       \I[5552] \I[5584] \I[5568] \I[5601] \I[5553]
  5. \C[16]Flush\C[0]            \I[5612] \I[5610] \I[5608] \I[5606] \I[5601]
  6. \C[16]Straight\C[0]         \I[5609] \I[5576] \I[5591] \I[5558] \I[5605]
  7. \C[16]Three of a Kind\C[0]  \I[5568] \I[5600] \I[5552] \I[5596] \I[5575]
  8. \C[16]Two Pair\C[0]         \I[5585] \I[5569] \I[5602] \I[5554] \I[5587]
  9. \C[16]One Pair\C[0]         \I[5568] \I[5600] \I[5557] \I[5590] \I[5575]
 10. \C[16]High Card\C[0]        \I[5600] \I[5558] \I[5592] \I[5578] \I[5612]
 
  [EOS]
  #--------------------------------------------------------------------------
  # ◇ 効果音
  #--------------------------------------------------------------------------
  SOUND_START   = "Flash2"      # カードを表にして選択可能になったとき
  SOUND_WIN     = "Applause2"   # 役あり
  SOUND_LOSE    = "Disappointment"      # 役なし
  SOUND_BET     = "Shop"        # 掛け金を決定したとき
  SOUND_COIN    = "Coin"        # 掛け金を変更したとき
  SOUND_DEAL    = "Book2"       # 手札を配るとき
  SOUND_SLOUGH  = "Book2"       # 手札を捨てるとき
  SOUND_REVERSE = "Book1"       # カードを裏返すとき
  SOUND_CHANGE  = "Book2"       # 裏のカードを交換するとき
end
end


#/////////////////////////////////////////////////////////////////////////////#
#                                                                             #
#                下記のスクリプトを変更する必要はありません。                 #
#                                                                             #
#/////////////////////////////////////////////////////////////////////////////#


class << CAO::Poker
  #--------------------------------------------------------------------------
  # ● 所持コインの枚数を取得
  #--------------------------------------------------------------------------
  def coin
    return $game_variables[CAO::Poker::IDV_COIN]
  end
  #--------------------------------------------------------------------------
  # ● コインの増加(減少)
  #--------------------------------------------------------------------------
  def gain_coin(amount)
    $game_variables[CAO::Poker::IDV_COIN] += amount
    $game_variables[CAO::Poker::IDV_COIN] = 0 if self.coin < 0
  end
end

module Sound
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def self.define_poker_sound(method_name, file_name)
    if file_name.empty?
      instance_eval %Q{
        def #{method_name}
        end
      }
    else
      instance_eval %Q{
        @#{method_name} = RPG::SE.new(file_name, 80)
        def #{method_name}
          @#{method_name}.play
        end
      }
    end
  end
  #--------------------------------------------------------------------------
  # ● ポーカーの効果音
  #--------------------------------------------------------------------------
  define_poker_sound :play_poker_start,   CAO::Poker::SOUND_START
  define_poker_sound :play_poker_win,     CAO::Poker::SOUND_WIN
  define_poker_sound :play_poker_lose,    CAO::Poker::SOUND_LOSE
  define_poker_sound :play_poker_bet,     CAO::Poker::SOUND_BET
  define_poker_sound :play_poker_coin,    CAO::Poker::SOUND_COIN
  define_poker_sound :play_poker_deal,    CAO::Poker::SOUND_DEAL
  define_poker_sound :play_poker_slough,  CAO::Poker::SOUND_SLOUGH
  define_poker_sound :play_poker_reverse, CAO::Poker::SOUND_REVERSE
  define_poker_sound :play_poker_change,  CAO::Poker::SOUND_CHANGE
end

class CAO::Poker::Trump
  #--------------------------------------------------------------------------
  # ● スートの識別番号
  #--------------------------------------------------------------------------
  SUIT_SPADES   = 0
  SUIT_HEARTS   = 1
  SUIT_DIAMONDS = 2
  SUIT_CLUBS    = 3
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :suit                     # スート (0..3)
  attr_reader   :number                   # 番号   (1..13)
  #--------------------------------------------------------------------------
  # ● オブジェクトの初期化
  #--------------------------------------------------------------------------
  def initialize(suit, number)
    @suit = suit
    @number = number
  end
  #--------------------------------------------------------------------------
  # ● トランプのID
  #--------------------------------------------------------------------------
  def id
    return 100 * @suit + @number
  end
  #--------------------------------------------------------------------------
  # ● デバッグ用
  #--------------------------------------------------------------------------
  def inspect
    return sprintf('%s%02d', '????'[@suit], @number)  # ????
  end
end

class CAO::Poker::Hand
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  @@deck = Array.new(13*4) {|i| CAO::Poker::Trump.new(i/13, i%13+1) }.freeze
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  attr_reader :hand                       # 手札
  attr_reader :stock                      # 山札
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def initialize
    @stock = @@deck.shuffle
    @hand = @stock.pop(5)
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def change(index)
    @hand[index] = @stock.pop
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def [](index)
    return @hand[index]
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def each
    @hand.each {|card| yield card }
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def sort!
    @hand.sort! {|a,b| a.number <=> b.number }
  end
  #--------------------------------------------------------------------------
  # ● 役の判定
  #--------------------------------------------------------------------------
  def final
    sort!       # 役を判定する前に手札のソートが必要
    royal    = _royal?
    straight = _straight?
    flush    = _flush?
    pairs    = _pairs
    pair_max = pairs.max
    pair_min = pairs.min
    pair_cnt = pairs.count(pair_max)
    
    return 9 if royal && flush                    # ロイヤルフラッシュ
    return 8 if straight && flush                 # ストレートフラッシュ
    return 7 if pair_max == 4                     # フォーカード
    return 6 if pair_max == 3 && pair_min == 2    # フルハウス
    return 5 if flush                             # フラッシュ
    return 4 if straight                          # ストレート
    return 3 if pair_max == 3 && pair_min == 1    # スリーカード
    return 2 if pair_max == 2 && pair_cnt == 4    # ツーペア
    return 1 if pair_max == 2                     # ワンペア
    return 0                                      # ハイカード
  end
  #--------------------------------------------------------------------------
  # ● ロイヤルストレートの判定
  #--------------------------------------------------------------------------
  def _royal?
    return @hand.map {|card| card.number } == [1, 10, 11, 12, 13]
  end
  #--------------------------------------------------------------------------
  # ● ストレートの判定
  #--------------------------------------------------------------------------
  def _straight?
    return true if _royal?
    @hand.each_with_index do |card,i|
      return false if card.number - @hand[0].number != i
    end
    return true
  end
  #--------------------------------------------------------------------------
  # ● フラッシュの判定
  #--------------------------------------------------------------------------
  def _flush?
    return @hand.all? {|card| card.suit == @hand[0].suit }
  end
  #--------------------------------------------------------------------------
  # ● ペア数を配列で取得 (重複する)
  #--------------------------------------------------------------------------
  def _pairs
    return @hand.map {|c1| @hand.count{|c2| c1.number == c2.number } }
  end
  protected :_royal?, :_straight?, :_flush?, :_pairs
end

class Game_Interpreter
  #--------------------------------------------------------------------------
  # ● ポーカー起動
  #--------------------------------------------------------------------------
  def start_poker
    SceneManager.call(Scene_Poker)
    Fiber.yield
  end
end

class Window_PokerHands < Window_Base
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  attr_reader :index
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, Graphics.width, fitting_height(5))
    clear
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def clear
    @index = -1
    @coin = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_all_items
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def draw_all_items
    10.times {|i| draw_item(i) }
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def draw_item(index)
    change_color(@index == index ? text_color(3) : normal_color)
    rect = Rect.new(0, 0, self.item_width, self.line_height)
    rect.x = (index / 5) * (rect.width + self.space)
    rect.y = (index % 5) * rect.height
    draw_text(rect, CAO::Poker::VOCAB_HANDS[index])
    draw_text(rect, prize_s(index), 2)
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def item_width
    return (contents_width - self.space) / 2
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def space
    return 16
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def prize(index = nil)
    return Integer(@coin * CAO::Poker::DIVIDEND_COVER[index || @index])
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def prize_s(index)
    if @coin == 0
      return "x#{CAO::Poker::DIVIDEND_COVER[index]}"
    else
      value = String(prize(index))
      value.sub!(/000$/, 'K') if CAO::Poker::ADDR_DIVIDEND && value.size > 4
      return value
    end
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def coin=(value)
    @coin = value
    refresh
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def index=(index)
    @index = index
    refresh
  end
end

class Window_Base
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
def draw_poker_coin(x, y, width, value, text = "", enabled = true)
    change_color(normal_color) 
    draw_text(x, y, width, line_height, text) unless text.empty?
    draw_text(x, y, width, line_height, CAO::Poker::VOCAB_COIN_U, 2) 
    change_color(normal_color, enabled)
    cx = text_size(CAO::Poker::VOCAB_COIN_U).width
    draw_text(x, y, width - cx - 2, line_height, value, 2)
  end
end

class Window_PokerCoin < Window_Base
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  WIDTH = Graphics.width / 8 * 3
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize()
    super(0, 0, WIDTH, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_poker_coin(0,0,contents_width,CAO::Poker.coin,CAO::Poker::VOCAB_COIN)
  end
end

class Window_PokerBet < Window_Base
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :number                   # 入力された数
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 272, fitting_height(2))
    self.viewport = viewport
    @digits_max = CAO::Poker::MAX_BET % 10 + 1
    self.openness = 0
    deactivate
    reset
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def reset
    @count = 0
    @number = CAO::Poker::DEFAULT_COIN
    refresh
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def enable?
    @number <= CAO::Poker.coin
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    change_color(normal_color)
    draw_text(0, 0, contents_width, line_height, CAO::Poker::VOCAB_BET, 2)
    draw_icon(1936, 0, 0, true)
    draw_icon(1937, 24, 0, true)
    draw_poker_coin(0, line_height, contents_width, sprintf("%0*d", @digits_max, @number), "", self.enable?)
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    process_digit_change
    process_handling
  end
  #--------------------------------------------------------------------------
  # ● 数字の変更処理
  #--------------------------------------------------------------------------
  def process_digit_change
    return unless open? && active
    if Input.repeat?(:UP) || Input.repeat?(:DOWN)
      last_number = @number
      if @count < 3
        @count += 1
        @number += CAO::Poker::BET_RATE if Input.repeat?(:UP)
        @number -= CAO::Poker::BET_RATE if Input.repeat?(:DOWN)
      else
        @number += CAO::Poker::BET_RATE * 10 if Input.repeat?(:UP)
        @number -= CAO::Poker::BET_RATE * 10 if Input.repeat?(:DOWN)
      end
      @number = CAO::Poker::BET_RATE if @number < CAO::Poker::BET_RATE
      @number = CAO::Poker::MAX_BET if CAO::Poker::MAX_BET < @number
      if @number != last_number
        Sound.play_poker_coin
        refresh
      end
    else
      @count = 0
    end
  end
  #--------------------------------------------------------------------------
  # ● 決定とキャンセルのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless open? && active
    return process_ok     if Input.trigger?(:C)
    return process_cancel if Input.trigger?(:B)
  end
  #--------------------------------------------------------------------------
  # ● 決定ボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_ok
    if self.enable?
      Sound.play_poker_bet
      deactivate
      close
      @ok_handler.call
    else
      Sound.play_buzzer
    end
  end
  #--------------------------------------------------------------------------
  # ● キャンセルボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_cancel
    Sound.play_cancel
    @cancel_handler.call
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def set_ok_handler(method)
    @ok_handler = method
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def set_cancel_handler(method)
    @cancel_handler = method
  end
end

class Window_PokerMessage < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 320, fitting_height(2))
    self.openness = 0
    deactivate
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    process_handling
  end
  #--------------------------------------------------------------------------
  # ● 決定とキャンセルのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless active
    return process_ok     if Input.trigger?(:C)
    return process_cancel if Input.trigger?(:B)
  end
  #--------------------------------------------------------------------------
  # ● 決定ボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_ok
    Sound.play_poker_slough
    deactivate
    close
    @handler.call
    Input.update
  end
  #--------------------------------------------------------------------------
  # ● キャンセルボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_cancel
    process_ok
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def set_ok_handler(method)
    @handler = method
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def set_cancel_handler(method)
    @handler = method
  end
  #--------------------------------------------------------------------------
  # ● テキスト設定
  #--------------------------------------------------------------------------
  def set_text(text)
    if text != @text
      @text = text
      refresh
    end
  end
  #--------------------------------------------------------------------------
  # ● クリア
  #--------------------------------------------------------------------------
  def clear
    set_text("")
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text_ex(4, 0, @text)
  end
end

class Window_PokerHelp < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, Graphics.width - Window_PokerCoin::WIDTH, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_text(36, 0, contents_width, contents_height, CAO::Poker::VOCAB_HELP)
    draw_icon(CAO::Poker::DESC_ICON, 0, 0, true)
  end
end

class Window_PokerManual < Window_Base
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def initialize
    bitmap = Bitmap.new(Graphics.width, Graphics.height)
    bitmap.fill_rect(bitmap.rect, Color.new(0, 0, 0, 160))
    @background = Sprite.new
    @background.bitmap = bitmap
    @background.visible = false
    super(0, 0, 424, fitting_height(CAO::Poker::MANUAL_LINE))
    self.openness = 0
    @background.z = self.z
    deactivate
    refresh
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def dispose
    @background.bitmap.dispose
    @background.dispose
    super
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_text_ex(0, 0, CAO::Poker::TEXT_MANUAL)
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def update
    super
    @background.visible = !close?
    if open? && (Input.trigger?(:A) || Input.trigger?(:B))
      Sound.play_cancel
      @close_handler.call
    elsif close? && Input.trigger?(:A)
      Sound.play_ok
      @open_handler.call
    end
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def open_handler=(method)
    @open_handler = method
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def close_handler=(method)
    @close_handler = method
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def viewport=(value)
    @background.viewport = value
    super
  end
end

class Sprite_PokerTrump < Sprite
  #--------------------------------------------------------------------------
  # ● 定数
  #--------------------------------------------------------------------------
  CARD_WIDTH  = Cache.system("PokerTrump").width  / 14
  CARD_HEIGHT = Cache.system("PokerTrump").height / 4
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader :wait_count
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x, y, viewport)
    @pos_x = x
    @pos_y = y
    super(viewport)
    self.x = x
    self.y = y
    self.opacity = 0
    create_backface
    centering_origin
    init_instance_variables
    hide
  end
  #--------------------------------------------------------------------------
  # ● オブジェクト解放
  #--------------------------------------------------------------------------
  def dispose
    @trump_bitmap.dispose if @trump_bitmap
    super
  end
  #--------------------------------------------------------------------------
  # ● カードの裏柄
  #--------------------------------------------------------------------------
  def create_backface
    @backface = Bitmap.new(CARD_WIDTH, CARD_HEIGHT)
    @backface.blt(0, 0, Cache.system("PokerTrump"),
      Rect.new(CARD_WIDTH * 13, CARD_HEIGHT * 0, CARD_WIDTH, CARD_HEIGHT))
    self.bitmap = @backface
  end
  #--------------------------------------------------------------------------
  # ● インスタンス変数の初期化
  #--------------------------------------------------------------------------
  def init_instance_variables
    @trump = nil
    @opening = @closing = false
    @openness = 100
    @wait_count = 0
    @target_bitmap = nil
    @target_x = self.x
    @target_y = self.y
    @target_opacity = self.opacity
    @speed_x = 0.0
    @speed_y = 0.0
    @speed_opacity = 0.0
  end
  #--------------------------------------------------------------------------
  # ● 転送元原点を中央にする
  #--------------------------------------------------------------------------
  def centering_origin
    self.ox = CARD_WIDTH / 2
    self.oy = CARD_HEIGHT / 2
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    if @wait_count > 0
      @wait_count -= 1
    else
      # update_deal_sound
      update_reverse
      update_position
    end
  end
  #--------------------------------------------------------------------------
  # ● カード表示時に効果音を鳴らす (未使用)
  #--------------------------------------------------------------------------
  def update_deal_sound
    if @start_deal
      Sound.play_poker_deal
      @start_deal = false
    end
  end
  #--------------------------------------------------------------------------
  # ● カードの向きを更新
  #--------------------------------------------------------------------------
  def update_reverse
    return if self.x != @target_x
    return if self.y != @target_y
    return if self.opacity != @target_opacity
    if @closing
      @openness -= 20
      if @openness <= 0
        self.bitmap = @target_bitmap
        @openness = 0
        @closing = false
      end
      self.zoom_x = @openness / 100.0
    elsif @openning
      @openness += 20
      if @openness >= 100
        @openness = 100
        @openning = false
      end
      self.zoom_x = @openness / 100.0
    end
  end
  #--------------------------------------------------------------------------
  # ● カードの位置を更新
  #--------------------------------------------------------------------------
  def update_position
    return if @openness != 0 && @openness != 100
    if self.x != @target_x
      @x += @speed_x
      self.x = @x
      if @speed_x < 0
        self.x = @target_x if self.x < @target_x
      else
        self.x = @target_x if self.x > @target_x
      end
    end
    if self.y != @target_y
      @y += @speed_y
      self.y = @y
      if @speed_y < 0
        self.y = @target_y if self.y < @target_y
      else
        self.y = @target_y if self.y > @target_y
      end
    end
    if self.opacity != @target_opacity
      @opacity += @speed_opacity
      self.opacity = @opacity
    end
  end
  #--------------------------------------------------------------------------
  # ● カードを表向きにする
  #--------------------------------------------------------------------------
  def open(wait = -1)
    self.wait = wait unless wait < 0
    @target_bitmap = @trump_bitmap
    reverse_motion
  end
  #--------------------------------------------------------------------------
  # ● カードを裏向きにする
  #--------------------------------------------------------------------------
  def close
    @target_bitmap = @backface
    reverse_motion
  end
  #--------------------------------------------------------------------------
  # ● カードを反転する
  #--------------------------------------------------------------------------
  def reverse
    front? ? close : open
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def reverse_motion
    @openness = 100
    @closing = true
    @openning = true
  end
  #--------------------------------------------------------------------------
  # ● カードの表示予約
  #--------------------------------------------------------------------------
  def deal
    @start_deal = true    # 未使用 (update_deal_sound)
    self.bitmap = @backface
    self.x = @pos_x - 4
    self.y = @pos_y - 4
    @target_x = @pos_x
    @target_y = @pos_y
    @target_opacity = 255
    calc_speed(10)
  end
  #--------------------------------------------------------------------------
  # ● カードの消去予約
  #--------------------------------------------------------------------------
  def slough
    @target_x = self.x
    @target_y = self.y - 20
    @target_opacity = 0
    calc_speed(10)
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def calc_speed(frame)
    @x = self.x
    @y = self.y
    @opacity = self.opacity
    @speed_x = (@target_x - self.x) / frame.to_f
    @speed_y = (@target_y - self.y) / frame.to_f
    @speed_opacity = (@target_opacity - self.opacity) / frame.to_f
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def show
    self.opacity = 255
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def hide
    self.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def in_motion?
    return true if reversing?
    return true if moving?
    return false
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def reversing?
    return @closing || @openning
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def moving?
    return true if self.x != @target_x
    return true if self.y != @target_y
    return true if self.opacity != @target_opacity
    return false
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def wait?
    return @wait_count != 0
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def front?
    return self.bitmap != @backface
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def trump=(trump)
    return if @trump == trump
    @trump = trump
    @trump_bitmap.dispose if @trump_bitmap
    @trump_bitmap = Bitmap.new(CARD_WIDTH, CARD_HEIGHT)
    rect = Rect.new(0, 0, CARD_WIDTH, CARD_HEIGHT)
    rect.x = CARD_WIDTH * (trump.number - 1)
    rect.y = CARD_HEIGHT * trump.suit
    @trump_bitmap.blt(0, 0, Cache.system("PokerTrump"), rect)
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def wait=(value)
    @wait_count = value
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def select
    self.oy = CARD_HEIGHT / 2 + 8
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def unselect
    self.oy = CARD_HEIGHT / 2
  end
  #--------------------------------------------------------------------------
  # ● 原点は固定、拡大率はカードをめくる動作で使用
  #--------------------------------------------------------------------------
  protected :ox=, :oy=, :zoom_x=, :zoom_y=
end

class Spriteset_PokerTrump
  #--------------------------------------------------------------------------
  # ● 定数
  #--------------------------------------------------------------------------
  CARD_MAX = 5
  WAIT_TIME = 8
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :index                    # カーソル位置
  attr_reader   :active                   #
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(viewport)
    @wait_count = -1
    @viewport = viewport
    @viewport.z = 50
    cw = @viewport.rect.width / CARD_MAX
    sx = @viewport.rect.width / 2 - cw * 2
    sy = @viewport.rect.height / 2
    @card_sprites = Array.new(CARD_MAX) do |i|
      Sprite_PokerTrump.new(sx + cw * i, sy, @viewport)
    end
    clear_handler
    unselect
    deactivate
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def dispose
    @viewport.dispose
    @card_sprites.each {|sp| sp.dispose }
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def update
    @viewport.update
    @card_sprites.each {|sp| sp.update }
    update_timer
    update_cursor
    if self.active
      process_ok                           if Input.trigger?(:C)
      process_cancel                       if Input.trigger?(:B)
      cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
      cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
    end
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def deal(hand)
    Sound.play_poker_deal
    CARD_MAX.times do |i|
      @card_sprites[i].trump = hand[i]
      @card_sprites[i].wait = WAIT_TIME * i
      @card_sprites[i].deal
    end
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def slough
    @card_sprites.each {|sp| sp.slough }
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def open(hand = nil)
    if hand
      CARD_MAX.times {|i| @card_sprites[i].trump = hand[i] }
      list = @card_sprites.select {|sp| !sp.front? }
    else
      list = @card_sprites
    end
    list.each_with_index {|sp,i| sp.open(WAIT_TIME * i) }
    return self
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def reversed_indexes
    result = []
    @card_sprites.each_with_index do |sp,i|
      result << i unless sp.front?
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● ウィンドウのアクティブ化
  #--------------------------------------------------------------------------
  def activate
    @active = true
    self
  end
  #--------------------------------------------------------------------------
  # ● ウィンドウの非アクティブ化
  #--------------------------------------------------------------------------
  def deactivate
    @active = false
    self
  end
  #--------------------------------------------------------------------------
  # ● 項目の選択
  #--------------------------------------------------------------------------
  def select(index)
    @index = index
    update_cursor
  end
  #--------------------------------------------------------------------------
  # ● 項目の選択解除
  #--------------------------------------------------------------------------
  def unselect
    @index = -1
    update_cursor
  end
  #--------------------------------------------------------------------------
  # ● ハンドラの設定をクリア
  #--------------------------------------------------------------------------
  def clear_handler
    @handler = {}
  end
  #--------------------------------------------------------------------------
  # ● 動作に対応するハンドラの設定
  #     method : ハンドラとして設定するメソッド (Method オブジェクト)
  #--------------------------------------------------------------------------
  def set_handler(symbol, method)
    @handler[symbol] = method
  end
  #--------------------------------------------------------------------------
  # ● ハンドラの存在確認
  #--------------------------------------------------------------------------
  def handle?(symbol)
    @handler.include?(symbol)
  end
  #--------------------------------------------------------------------------
  # ● ハンドラの呼び出し
  #--------------------------------------------------------------------------
  def call_handler(symbol)
    @handler[symbol].call if handle?(symbol)
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def update_cursor
    @card_sprites.each {|sp| sp.unselect }
    @card_sprites[@index].select unless @index < 0
  end
  #--------------------------------------------------------------------------
  # ● カーソルの移動可能判定
  #--------------------------------------------------------------------------
  def cursor_movable?
    return self.active
  end
  #--------------------------------------------------------------------------
  # ● カーソルを右に移動
  #--------------------------------------------------------------------------
  def cursor_right(wrap = false)
    if index < CARD_MAX - 1 || wrap
      Sound.play_cursor
      select((index + 1) % CARD_MAX)
    end
  end
  #--------------------------------------------------------------------------
  # ● カーソルを左に移動
  #--------------------------------------------------------------------------
  def cursor_left(wrap = false)
    if index > 0 || wrap
      Sound.play_cursor
      select((index - 1 + CARD_MAX) % CARD_MAX)
    end
  end
  #--------------------------------------------------------------------------
  # ● 選択項目のカードを取得
  #--------------------------------------------------------------------------
  def current_card
    return @index < 0 ? nil : @card_sprites[@index]
  end
  #--------------------------------------------------------------------------
  # ● 決定ボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_ok
    Sound.play_poker_reverse
    Input.update
    unless @index < 0
      @card_sprites[@index].reverse
    end
  end
  #--------------------------------------------------------------------------
  # ● キャンセルボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_cancel
    Sound.play_poker_change
    Input.update
    deactivate
    call_handler(:cancel)
  end
  #--------------------------------------------------------------------------
  # ● すべてのカードの動作が完了するまでの時間
  #--------------------------------------------------------------------------
  def wait_count
    return @card_sprites.max_by {|sp| sp.wait_count }.wait_count
  end
  #--------------------------------------------------------------------------
  # ● ビューポートのサイズ
  #--------------------------------------------------------------------------
  def viewport
    return @viewport.rect
  end
  #--------------------------------------------------------------------------
  # ● 移動中判定
  #--------------------------------------------------------------------------
  def update_timer
    return if @wait_count < 0
    return if @card_sprites.any? {|card| card.in_motion? }
    @wait_count -= 1
    @deferred.call if @wait_count < 0 && @deferred
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def wait(duration, method = nil)
    @wait_count = duration
    @deferred = method
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def waiting?
    return @wait_count >= 0
  end
end

class Scene_Poker < Scene_MenuBase
  #--------------------------------------------------------------------------
  # ● 開始処理
  #--------------------------------------------------------------------------
  def start
    super
    create_hands_window
    create_help_window
    create_gold_window
    create_card_sprite
    create_info_windows
    start_game
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_hands_window
    @hands_window = Window_PokerHands.new
    @hands_window.x = (Graphics.width - @hands_window.width) / 2
    @hands_window.y = 0#32
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_help_window
    @help_window = Window_PokerHelp.new
    @help_window.y = Graphics.height - @help_window.height
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_gold_window
    @coin_window = Window_PokerCoin.new
    @coin_window.x = Graphics.width - @coin_window.width
    @coin_window.y = Graphics.height - @coin_window.height
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_card_sprite
    viewport = Viewport.new
    viewport.rect.y = @hands_window.y + @hands_window.height
    viewport.rect.height -= viewport.rect.y + @help_window.height
    @spriteset = Spriteset_PokerTrump.new(viewport)
    @spriteset.set_handler(:cancel, method(:change_card))
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_info_windows
    @info_viewport = Viewport.new
    @info_viewport.z = 100
    create_bet_window
    create_message_window
    create_manual_window
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_bet_window
    @bet_window = Window_PokerBet.new
    @bet_window.viewport = @info_viewport
    @bet_window.x = (@info_viewport.rect.width - @bet_window.width) / 2
    @bet_window.y = (@info_viewport.rect.height - @bet_window.height) / 2
    @bet_window.y = @spriteset.viewport.y + 16
    @bet_window.set_ok_handler(method(:on_bet_ok))
    @bet_window.set_cancel_handler(method(:return_scene))
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_message_window
    @message_window = Window_PokerMessage.new
    @message_window.viewport = @info_viewport
    @message_window.x = (@info_viewport.rect.width - @message_window.width) / 2
    @message_window.y = (@info_viewport.rect.height-@message_window.height) / 2
    @message_window.y = @spriteset.viewport.y + 16
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def create_manual_window
    @manual_window = Window_PokerManual.new
    @manual_window.viewport = @info_viewport
    @manual_window.x = (@info_viewport.rect.width - @manual_window.width) / 2
    @manual_window.y = (@info_viewport.rect.height - @manual_window.height) / 2
    @manual_window.open_handler = proc do
      @manual_window.open
    end
    @manual_window.close_handler = proc do
      @manual_window.close
    end
  end
  #--------------------------------------------------------------------------
  # ● 終了処理
  #--------------------------------------------------------------------------
  def terminate
    super
    @info_viewport.dispose
    @spriteset.dispose
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    @spriteset.update if @manual_window.close?
  end
  #--------------------------------------------------------------------------
  # ● 全ウィンドウの更新
  #--------------------------------------------------------------------------
  def update_all_windows
    if @manual_window.close?
      super
    else
      @manual_window.update
    end
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def start_game
    @hands_window.clear
    @hand = CAO::Poker::Hand.new
    @spriteset.deal(@hand)
    @spriteset.wait(0, method(:start_bet))
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def end_game
    @spriteset.slough
    @spriteset.wait(10, method(:start_game))
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def start_bet
    @bet_window.refresh
    @bet_window.open.activate
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def start_select
    Sound.play_poker_start
    @spriteset.select(0)
    @spriteset.activate
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def show_mes_win
    Sound.play_poker_win
    CAO::Poker.gain_coin(@hands_window.prize)
    @coin_window.refresh
    @message_window.set_text(CAO::Poker::VOCAB_WIN % @hands_window.prize)
    @message_window.open.activate
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def show_mes_lose
    Sound.play_poker_lose
    @message_window.set_text(CAO::Poker::VOCAB_LOSE % @hands_window.prize)
    @message_window.open.activate
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def on_bet_ok
    CAO::Poker.gain_coin(-@bet_window.number)
    @coin_window.refresh
    @hands_window.coin = @bet_window.number
    @bet_window.close
    @spriteset.open
    @spriteset.wait(0, method(:start_select))
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def on_mes_change_ok
    start_select
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def on_mes_win_ok
    end_game
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def on_mes_lose_ok
    end_game
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def change_card
    @spriteset.unselect
    @spriteset.reversed_indexes.each {|index| @hand.change(index) }
    @spriteset.open(@hand)
    @hands_window.index = @hand.final
    if @bet_window.number <= @hands_window.prize
      @message_window.set_ok_handler(method(:on_mes_win_ok))
      @message_window.set_cancel_handler(method(:on_mes_win_ok))
      @spriteset.wait(0, method(:show_mes_win))
    else
      @message_window.set_ok_handler(method(:on_mes_lose_ok))
      @message_window.set_cancel_handler(method(:on_mes_lose_ok))
      @spriteset.wait(0, method(:show_mes_lose))
    end
  end
end
I still see an issue with save files.
How does your save system work? Is it the default?
I can load my save game (1) -> save to slot 2 -> play blackjack -> lose badly -> load save slot 1.
win good save to slot 1 & 2 -> continue playing

If your request is to have only one save file then there are scripts for that, plus you can just change the scripts so that the maximum number of slots is 1.

Then we can just do save command in the scripts.
DataManager.save_game(0)

for the blackjack it can be put at the bottom of the judge_win_loss method or on_action_stay.

The poker one is a little more complicated as it doesn't have one method where money is processed.
on_bet_ok losing money for betting, (which looks like it will only process after the player selects ok in the message window) and show_mes_win for winning money.
I don't see the poker one being easy to adjust. Plus there is method calls that I'm not sure about. Only a better scripter would know.
@Roninator2 You're right about that. In this case, I don't care how the save system looks like, I would be totally fine using something like this to have only one save slot and no save interface at all.

Spoiler: Single Save File v1.0 by AABattery
Ruby:
#==============================================================================
# .: Single Save :.
# .: Version 1.0 :.
# .: By AABattery :.
# http://www.rpgmakervxace.net/topic/8772-single-save-file/
#==============================================================================
# Some games are better off with only one save file. That's what this does!
#==============================================================================
#  INSTRUCTIONS
#------------------------------------------------------------------------------
# This script is just a plug-n-play, and doesn't need any configuration,
# however, if you want to change the name of the save file, just change the
# word "Save" inside the quotes in the DataManager module.
#
# Be sure that both instances of "Save" are written the same and that the
# extension (.rvdata2) is intact. Otherwise you will receive some problems.
#==============================================================================
#   If you encounter any problems, please post in the thread shown above!
#==============================================================================
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================
module DataManager
 #--------------------------------------------------------------------------
 # * Determine Existence of Save File
 #--------------------------------------------------------------------------
 def self.save_file_exists?
!Dir.glob('Save.rvdata2').empty? # Change 'Save' to whatever you want
 end
 #--------------------------------------------------------------------------
 # * Create Filename
 #     index : File Index
 #--------------------------------------------------------------------------
 def self.make_filename(index)
sprintf("Save.rvdata2")          # Change "Save" to whatever you want
 end
end
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This class performs common processing for the save screen and load screen.
#==============================================================================
class Scene_File < Scene_MenuBase
 #--------------------------------------------------------------------------
 # * Start Processing
 #--------------------------------------------------------------------------
 def start
super
save_load_file
 end
 def terminate
 end
 #--------------------------------------------------------------------------
 # * Saves/Loads
 #--------------------------------------------------------------------------
 def save_load_file
 end
end
#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
#  This class performs load screen processing.
#==============================================================================
class Scene_Load < Scene_File
 #--------------------------------------------------------------------------
 # * Loads
 #--------------------------------------------------------------------------
 def save_load_file
DataManager.load_game(0)
Graphics.transition(30)
fadeout_all
$game_system.on_after_load
SceneManager.goto(Scene_Map)
 end
end
#==============================================================================
# ** Scene_Save
#------------------------------------------------------------------------------
#  This class performs save screen processing.
#==============================================================================
class Scene_Save < Scene_File
 #--------------------------------------------------------------------------
 # * Saves
 #--------------------------------------------------------------------------
 def save_load_file
DataManager.save_game(0)
Sound.play_save
return_scene
 end
end

I don't see the poker one being easy to adjust. Plus there is method calls that I'm not sure about. Only a better scripter would know.
The best scripter around here by far is kyonides.

@kyonides Could you tell if there's anything more to consider for the poker script like what Ronny said?
I don't think I've got the exclusive rights to being called the best scripter around here, anyway.

Here's my take on this poker face issue. 😛
I can't test it because I don't have the card pictures used here.

REVISITED VERSION

Ruby:
# * Poker2Face Patch * #
#   Scripter : Kyonides Arkanthes
#   2023-12-21

module CAO::Poker
  SAVE_FILE = "PokerChips.rvdata2"
  def self.gain_coin(amount)
    coins = [$game_variables[IDV_COIN] + amount, 0].max
    $game_variables[IDV_COIN] = coins
    save_data(coins, SAVE_FILE)
  end
end

class Scene_Poker
  alias :kyon_cacao_poker_scn_pkr_start :start
  def start
    save_fn = CAO::Poker::SAVE_FILE
    coins = 0
    if FileTest.exist?(save_fn)
      coins = load_data(save_fn) rescue 0
    end
    CAO::Poker.gain_coin(coins)
    kyon_cacao_poker_scn_pkr_start
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/create-autosave-no-matter-what.164027/