Banking System

    Share
    avatar
    Fooart
    Administrator

    Male
    Number of posts : 170
    Age : 30
    Registration date : 2009-02-16

    Banking System

    Post by Fooart on 15th January 2013, 5:00 pm

    Step:
    1. Buat New event>patu klik Insert>Event commands(page3)>Advanced script>Copy&paste:
    Code:
    $scene = Scene_Bank.new
    >Ok.

    2. Dekat tab grafik tu pilih la mana2 sprite(sebagai Accountant korang)>dah settel klik ok.

    3. Copy code kat bwh ni, lepas tu..buka Script editor>paste code tadi(paste dekat ruang kosong di antara Material/Main)

    Code:
    #===============================================================================
    # * Cng's Banking System
    # * By Crazyninjaguy
    # * http://www.planetdev.net
    #-------------------------------------------------------------------------------
    # Just create two new variables, and set them up below.
    # The script does the rest for you.
    #
    # To use this script, use a call script event command with
    #
    # $scene = Scene_Bank.new
    #
    #===============================================================================
    INTERNAL_BANK = 3
    BANK_VARIABLE = 4

    class Scene_Bank < Scene_Base
      def start
        super
        create_menu_background
        create_main_windows
        create_command_window
      end
      def terminate
        super
        dispose_menu_background
        @command_window.dispose
        @main.dispose
        @inhand.dispose
        @banked.dispose
      end
      def update
        super
        @command_window.update
        if @command_window.active
          update_command
        end
      end
      def create_main_windows
        @main = Window_BankMessage.new("Welcome! What can i do for you?")
        @inhand = Window_InHand.new
        @inhand.y = (416 - @inhand.height)
        @banked = Window_Banked.new
        @banked.x = @inhand.width
        @banked.y = (416 - @banked.height)
      end
      def create_command_window
        s1 = "Withdraw"
        s2 = "Deposit"
        s3 = "Exit"
        @command_window = Window_Command.new(160, [s1, s2, s3])
        @command_window.index = 0
        @command_window.y = @main.y + @main.height
      end
      def update_command
        if Input.trigger?(Input::B)
          $scene = Scene_Map.new
        elsif Input.trigger?(Input::C)
          Sound.play_decision
          case @command_window.index
          when 0
            $scene = Scene_Withdraw.new
          when 1
            $scene = Scene_Deposit.new
          when 2
            $scene = Scene_Map.new
          end
        end
      end
    end

    class Scene_Deposit < Scene_Base
      def start
        super
        create_menu_background
        create_main_windows
      end
      def terminate
        super
        dispose_menu_background
        @number_window.dispose
        @main.dispose
      end
      def update
        super
        @number_window.update
        if Input.trigger?(Input::B)
          $scene = Scene_Bank.new
        elsif Input.trigger?(Input::C)
          Sound.play_decision
          $game_variables[INTERNAL_BANK] = @number_window.number
          $scene = Scene_Confirm.new(1)
        end
      end
      def create_main_windows
        @main = Window_BankMessage.new("How much would you like to Deposit?")
        @number_window = Window_BankInput.new
        @number_window.digits_max = 7
        @number_window.active = true
        @number_window.number = $game_variables[BANK_VARIABLE]
        @number_window.opacity = 255
        @number_window.y = @main.height
      end
    end

    class Scene_Withdraw < Scene_Base
      def start
        super
        create_menu_background
        create_main_windows
      end
      def terminate
        super
        dispose_menu_background
        @number_window.dispose
        @main.dispose
      end
      def update
        super
        @number_window.update
        if Input.trigger?(Input::B)
          $scene = Scene_Bank.new
        elsif Input.trigger?(Input::C)
          $game_variables[INTERNAL_BANK] = @number_window.number
          $scene = Scene_Confirm.new(2)
        end
      end
      def create_main_windows
        @main = Window_BankMessage.new("How much would you like to Withdraw?")
        @number_window = Window_BankInput.new
        @number_window.digits_max = 7
        @number_window.active = true
        @number_window.number = $game_variables[BANK_VARIABLE]
        @number_window.opacity = 255
        @number_window.y = @main.height
      end
    end

    class Scene_Confirm < Scene_Base
      def initialize(scene)
        @scene = scene
      end
      def start
        super
        create_menu_background
        create_main_windows
      end
      def terminate
        super
        dispose_menu_background
        @main.dispose
        @command_window.dispose
      end
      def update
        super
        @command_window.update
        if @command_window.active
          update_command
        end
      end
      def create_main_windows
        if @scene == 1
          @main = Window_BankMessage.new("Are you sure you want to deposit " + $game_variables[INTERNAL_BANK].to_s + "?")
        elsif @scene == 2
          @main = Window_BankMessage.new("Are you sure you want to withdraw " + $game_variables[INTERNAL_BANK].to_s + "?")
        end
        @command_window = Window_Command.new(160, ["Yes", "No"])
        @command_window.x = (544 - @command_window.width) / 2
        @command_window.y = 200
      end
      def update_command
        if Input.trigger?(Input::B)
          if @scene == 1
            $scene = Scene_Deposit.new
          elsif @scene == 2
            $scene = Scene_Withdraw.new
          end
        elsif Input.trigger?(Input::C)
          case @command_window.index
          when 0
            if @scene == 1
              if $game_variables[INTERNAL_BANK] > $game_party.gold
                Sound.play_buzzer
                @main.dispose
                @main = Window_BankMessage.new("Sorry, but you don't have " + $game_variables[INTERNAL_BANK].to_s + " to deposit!")
                Graphics.wait(120)
                $scene = Scene_Deposit.new
              elsif $game_variables[INTERNAL_BANK] <= $game_party.gold
                Audio.se_play("Audio/SE/Shop", 100, 100)
                $game_variables[BANK_VARIABLE] = $game_variables[INTERNAL_BANK]
                $game_party.lose_gold($game_variables[INTERNAL_BANK])
                @main.dispose
                @main = Window_BankMessage.new("Thank you, your money has been stored safely.")
                Graphics.wait(120)
                $scene = Scene_Bank.new
              end
            elsif @scene == 2
              if $game_variables[INTERNAL_BANK] > $game_variables[BANK_VARIABLE]
                @main.dispose
                @main = Window_BankMessage.new("Sorry, but you don't have " + $game_variables[INTERNAL_BANK].to_s + " to withdraw!")
                Sound.play_buzzer
                Graphics.wait(120)
                $scene = Scene_Withdraw.new
              elsif $game_variables[INTERNAL_BANK] <= $game_variables[BANK_VARIABLE]
                Audio.se_play("Audio/SE/Shop", 100, 100)
                $game_variables[BANK_VARIABLE] -= $game_variables[INTERNAL_BANK]
                $game_party.gain_gold($game_variables[INTERNAL_BANK])
                @main.dispose
                @main = Window_BankMessage.new("Thank you, " + $game_variables[INTERNAL_BANK].to_s + " has been withdrawn.")
                Graphics.wait(120)
                $scene = Scene_Bank.new
              end
            end
          when 1
            if @scene == 1
              $scene = Scene_Deposit.new
            elsif @scene == 2
              $scene = Scene_Withdraw.new
            end
          end
        end
      end
    end

    class Window_BankMessage < Window_Base
      def initialize(message)
        super(0, 0, 544, WLH + 40)
        @message = message
        refresh
      end
      def refresh
        self.contents.draw_text(0, 0, 512, WLH, @message, 1)
      end
    end

    class Window_InHand < Window_Base
      def initialize
        super(0, 0, 160, WLH + 62)
        refresh
      end
      def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(0, 0, 136, WLH, "In Hand", 0)
        self.contents.font.color = normal_color
        draw_currency_value($game_party.gold, 4, 32, 120)
      end
    end

    class Window_Banked < Window_Base
      def initialize
        super(0, 0, 160, WLH + 62)
        refresh
      end
      def refresh
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(0, 0, 136, WLH, "In Bank", 0)
        self.contents.font.color = normal_color
        draw_currency_value($game_variables[BANK_VARIABLE], 4, 32, 120)
      end
    end

    class Window_BankInput < Window_Base
      def initialize
        super(0, 0, 190, 64)
        @number = 0
        @digits_max = 6
        @index = 0
        self.opacity = 0
        self.active = false
        self.z += 9999
        refresh
        update_cursor
      end
      def number
        return @number
      end
      def number=(number)
        @number = [[number, 0].max, 10 ** @digits_max - 1].min
        @index = 0
        refresh
      end
      def digits_max
        return @digits_max
      end
      def digits_max=(digits_max)
        @digits_max = digits_max
        refresh
      end
      def cursor_right(wrap)
        if @index < @digits_max - 1 or wrap
          @index = (@index + 1) % @digits_max
        end
      end
      def cursor_left(wrap)
        if @index > 0 or wrap
          @index = (@index + @digits_max - 1) % @digits_max
        end
      end
      def update
        super
        if self.active
          if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
            Sound.play_cursor
            place = 10 ** (@digits_max - 1 - @index)
            n = @number / place % 10
            @number -= n * place
            n = (n + 1) % 10 if Input.repeat?(Input::UP)
            n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
            @number += n * place
            refresh
          end
          last_index = @index
          if Input.repeat?(Input::RIGHT)
            cursor_right(Input.trigger?(Input::RIGHT))
          end
          if Input.repeat?(Input::LEFT)
            cursor_left(Input.trigger?(Input::LEFT))
          end
          if @index != last_index
            Sound.play_cursor
          end
          update_cursor
        end
      end
      def refresh
        self.contents.clear
        self.contents.font.color = normal_color
        s = sprintf("%0*d", @digits_max, @number)
        for i in 0...@digits_max
          self.contents.draw_text(24 + i * 16, 0, 16, WLH, s[i,1], 1)
        end
      end
      def update_cursor
        self.cursor_rect.set(24 + @index * 16, 0, 16, WLH)
      end
    end

    Ni contoh banking sistem yg dah siap

    Download:
    Code:
    http://www.mediafire.com/?1jca6p8ah60h96r

    credit: Cng's a.k.a Crazyninjaguy


      Current date/time is 10th December 2018, 12:45 pm