Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

HBGames

Quick Keys

By Blazingamer




Well, I just spent about 15 mins and did this script 'cause I felt like it. It's a quick keys script that when you press a number key it will bring up a scene from the menu. It's an easy just follow the instructions script that isn't all that complex.

Code:
#==============================================================================
# ** Quick Keys
#
#	 By Blazingamer
#------------------------------------------------------------------------------
#  This allows the function that if on the map, when a number key is pressed, it will take you to that 
#  scene.  It has the capability to have 2 extras scenes that you will be able to call.  
#
#------------------------------------------------------------------------------
#  Instructions
#
# To assign numbers to scenes, just change the line $scene = ___________.new underneath the 
#  number to what ever scene you want.  Also add $game_switches[*] == true to all scenes called 
#  and put it in an if statement for the scenes called so it will bring you back to the map and not 
#  the menu.
#
#------------------------------------------------------------------------------
#	   Requirements
#
# This script requires the number part of the Keyboard script by Cybersam to run properly, which is
#  included.
#
#==============================================================================


class Scene_Map
  def update
	if Kboard.keyboard($R_Key_1)
	  $scene = Scene_Menu.new
	  return
	end
	if Kboard.keyboard($R_Key_2)
	  $scene = Scene_Item.new
	  $game_switches[1] = true
	  return
	end	
	if Kboard.keyboard($R_Key_3)
	  $scene = Scene_Skill.new
	  $game_switches[1] = true
	  return
	end
	if Kboard.keyboard($R_Key_4)
	  $scene = Scene_Equip.new
	  $game_switches[1] = true
	  return
	end
	if Kboard.keyboard($R_Key_5)
	  $scene = Scene_Status.new
	  $game_switches[1] = true
	  return
	end
=begin #Erase this line to enable keys 6 and 7  
	if Kboard.keyboard($R_Key_6)
	  $scene =
	  $game_switches[1] = true
	  return
	end
	if Kboard.keyboard($R_Key_7)
	  $scene = 
	  $game_switches[1] = true
	  return
	end
=end #Erase this line to enable keys 6 and 7
	if Kboard.keyboard($R_Key_8)
	  $scene = Scene_Load.new
	  $game_switches[1] = true
	  return
	end
	if Kboard.keyboard($R_Key_9)
	  if $game_system.save_disabled
		# Play buzzer SE
		$game_system.se_play($data_system.buzzer_se)
	  else
		$scene = Scene_Save.new
		$game_switches[1] = true
	  end
	  return
	end
	if Kboard.keyboard($R_Key_0)
	  $scene = Scene_End.new
	  $game_switches[1] = true
	  return
	end
  end
end

#==============================================================================
# ** Scene_Item
#==============================================================================
class Scene_Item
  def update_item
	# If B button was pressed
	if Input.trigger?(Input::B)
	  if $game_switches[1] == true
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Map.new
	  else
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Menu.new(0)
	  end
	  return
	end
  end
end
#==============================================================================
# ** Scene_Skill
#==============================================================================
class Scene_Skill
  def update_skill
	# If B button was pressed
	if Input.trigger?(Input::B)
	  if $game_switches[1] == true
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Map.new
	  else
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Menu.new(1)
	  end
	  return
	end
  end
end
#==============================================================================
# ** Scene_Equip
#==============================================================================
class Scene_Equip
  def update_right
	# If B button was pressed
	if Input.trigger?(Input::B)
	  if $game_switches[1] == true
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Map.new
	  else
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Menu.new(2)
	  end
	  return
	end
  end
end
#==============================================================================
# ** Scene_Status
#==============================================================================
class Scene_Status
  def update
	# If B button was pressed
	if Input.trigger?(Input::B)
	  if $game_switches[1] == true
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Map.new
	  else
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Menu.new(3)
	  end
	  return
	end
  end
end
#==============================================================================
# ** Scene_Load
#==============================================================================
class Scene_Load
  def on_cancel
	if $game_switches[1] == true
	  # Play cancel SE
	  $game_system.se_play($data_system.cancel_se)
	  # Switch to menu screen
	  $scene = Scene_Map.new
	else
	  # Play cancel SE
	  $game_system.se_play($data_system.cancel_se)
	  # Switch to title screen
	  $scene = Scene_Title.new
	end
  end
end
#==============================================================================
# ** Scene_Save
#==============================================================================
class Scene_Save
  def on_cancel
	# Play cancel SE
	$game_system.se_play($data_system.cancel_se)
	# If called from event
	if $game_temp.save_calling
	  # Clear save call flag
	  $game_temp.save_calling = false
	  # Switch to map screen
	  $scene = Scene_Map.new
	end
	if $game_switches[1] == true
	  # Switch to map screen
	  $scene = Scene_Map.new
	else
	  # Switch to menu screen
	  $scene = Scene_Menu.new(4)
	end
  end
end
#==============================================================================
# ** Scene_End
#==============================================================================
class Scene_End
  def update
	# Update command window
	@command_window.update
	# If B button was pressed
	if Input.trigger?(Input::B)
	  if $game_switches[1] == true
		# Switch to map screen
		$scene = Scene_Map.new
	  else
		# Play cancel SE
		$game_system.se_play($data_system.cancel_se)
		# Switch to menu screen
		$scene = Scene_Menu.new(5)
	  end
	  return
	end
  end
end
#======================================
# ? Keyboard Script
#---------------------------------------------------------------------------
# By: Cybersam
#   Date: 25/05/05
#   Version 4
#======================================
# call using Kboard.keyboard($R_Key_*) where
# * is the letter you want to use
#======================================  
module Kboard
  $R_Key_0		 = 0x30		# 0 key
  $R_Key_1		 = 0x31		# 1 key
  $R_Key_2		 = 0x32		# 2 key
  $R_Key_3		 = 0x33		# 3 key
  $R_Key_4		 = 0x34		# 4 key
  $R_Key_5		 = 0x35		# 5 key
  $R_Key_6		 = 0x36		# 6 key
  $R_Key_7		 = 0x37		# 7 key
  $R_Key_8		 = 0x38		# 8 key
  $R_Key_9		 = 0x39		# 9 key
  #--------------------------------------------------------------------------
  GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  GetKeyboardState = Win32API.new("user32","GetKeyState",['i'],'i')
  GetSetKeyState = Win32API.new("user32","SetKeyboardState",['i'],'i')
  #--------------------------------------------------------------------------
  module_function
  #--------------------------------------------------------------------------
  def keyb(rkey)
	if GetKeyState.call(rkey) != 0
	  return 1
	end
	return 0
  end
  #--------------------------------------------------------------------------
  def keyboard(rkey)
	GetKeyState.call(rkey) & 0x01 == 1  #
  end
  #--------------------------------------------------------------------------
  def key(rkey, key = 0)
	GetKeyboardState.call(rkey) & 0x01 == key #
  end
end

Included in this script is the keyboard numbers function by cybersam.

FAQ

Q:Where do I put this?

A:Where ever your heart desires, except after main and before Scene_Debug:)

Q:How do I use this in game?

A:Just press any of the number keys.



Demo
Not needed, it's just copy paste above the main script

Screenshots
Also not needed, all it does is make menus pop up.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top