i really need help , please some one help me the Problem is : i can't descripe so here you go ...
Options :
Yanfly Engine RD - Menu System Options
CODE
#===============================================================================
#
# Yanfly Engine RD - Menu System Options
# Last Date Updated: 2009.05.12
# Level: Easy, Normal
#
# The "End Game" option is quite possibly the most useless function in RPG Maker
# VX games. Not only does it have little functionality but its functions can
# be reproduced by Alt+F4 and F12. This script replaces "End Game" with a new
# menu altogether and giving the player some familiar options seen in many of
# today's commercial RPG's such as changing window skins, adjust sound volume,
# turning off animations during battle, and the like.
#
#===============================================================================
# Updates:
# ----------------------------------------------------------------------------
# o 2009.05.12 - Auto-Dash update. If player holds down the dash button when
# this option is enabled, the player will walk instead of dash.
# o 2009.05.09 - Compatibility update with Woratana's NeoMessage.
# Compatibility update with Modern Algebra's ATS.
# o 2009.05.07 - Started script and finished.
#===============================================================================
# Instructions
#===============================================================================
#
# Input this script anywhere above Main. It's plug and play outside of changing
# a few variables and switches, which will be listed below:
#
# - If you have variables bound to variables 91, 92, 93, and 94, scroll down and
# bind them to unused variables.
# - If you have switches bound to switches 91, 92, 93, 94, 95, or 96, scroll
# down and bind them to unused switches.
#
# Then, download the windows pack, and create a "Windows" folder inside your
# Graphics folder. Input the windows pack there. You're all set to go.
#
#===============================================================================
#
# Compatibility
# - Works With: Woratana's NeoMessage
# - Works With: Modern Algebra's ATS
# - Alias: Game_Player: dash?
# - Alias: Window_Base: initialize
# - Alias: Scene_Battle: display_normal_animation
# - Overwrites: Scene_End: All of it
# - Overwrites: Vocab: game_end
#
#===============================================================================
$imported = {} if $imported == nil
$imported["MenuSystemOptions"] = true
module YE
module SYSTEM
# This changes the "End Game" string to a new string. This completely
# overrides the default term from the database for a reason and that's
# because this is adjustable from the title menu as well.
TITLE = "ﻡﺎﻈﻨﻟﺍ"
#---------------------
# Window Configuration
#---------------------
# This will affect what string data will appear for the window selection
# portion of the system menu.
WINDOW_HELP = ".ﺔﻤﺋﺎﻘﻟﺍ ﻦﻣ ﻪﻠﻀﻔﺗ ﻱﺬﻟﺍ ﻢﻜﺤﺘﻟﺍ ﺔﺷﺎﺷ ﻥﻮﻟ ﺭﺎﺘﺧﺍ"
WINDOW_SKIN = "ﻢﻜﺤﺘﻟﺍ ﺔﺷﺎﺷ ﻥﻮﻟ"
# This sets the default window used when nothing is selected. This also
# determines the window skin used at the title screen. Reference it to
# the list below to determine which window skin. Don't make this 0.
DEFAULT_WINDOW = 1
# This determines the variable used to store the player's windowskin choice.
WINDOW_VARIABLE = 91
# This below determines what the variable refers to when it's used as
# reference. Put your windows inside the Graphics/Windows folder. ID 0 will
# automatically push back to the default window's ID.
WINDOW_HASH ={
# Window ID => Window Name
1 => "ﻢﺗﺎﻗ ﺮﻀﺧﺃ",
2 => "ﺮﻔﺻﺃ",
3 => "ﻲﺋﺎﻤﺳ ﻕﺭﺯﺃ",
4 => "ﺮﻤﺣﺃ",
5 => "ﻱﺮﻫﺯ",
6 => "ﻲﺠﺴﻔﻨﺑ",
7 => "ﻲﻄﻴﺤﻣ",
8 => "ءﺎﻗﺭﺯ ﺔﻴﻟﺎﻋ ﺔﻴﻨﻘﺗ",
9 => "ءﺍﺮﻤﺣ ﺔﻴﻟﺎﻋ ﺔﻴﻨﻘﺗ",
10 => "ﻲﺒﺸﺧ",
11 => "ﺔﻴﻟﺎﻴﺧ",
12 => "ﺔﻳﺮﺤﺳ",
13 => "ﺓﺩﺭﺎﺑ ءﺎﻗﺭﺯ",
14 => "ﺓﺰﻴﻤﻣ ءﺍﺩﻮﺳ",
} # Do not remove this.
#---------------------
# Volume Configuration
#---------------------
# This will affect what string data will appear for the volume adjustment
# portion of the system menu.
BGM_HELP = ".ﺖﻣﺎﺻ ﻪﻠﻌﺠﻟ Q ﻭﺃ W ﻰﻠﻋ ﻂﻐﺿﺍ ﺔﻴﻔﻠﺨﻟﺍ ﺔﻴﻨﻏﻻﺍ ﻂﺒﺿﺍ"
SFX_HELP = ".ﺖﻣﺎﺻ ﻪﻠﻌﺠﻟ Q ﻭﺃ W ﻰﻠﻋ ﻂﻐﺿﺍ ﺔﻴﺗﻮﺼﻟﺍ ﺕﺍﺮﺛﺆﻤﻟﺍ ﻂﺒﺿﺍ"
BGS_HELP = ".ﺖﻣﺎﺻ ﻪﻠﻌﺠﻟ Q ﻭﺃ W ﻰﻠﻋ ﻂﻐﺿﺍ ﺔﻴﻔﻠﺨﻟﺍ ﺕﻮﺻﻻﺍ ﻂﺒﺿﺍ"
BGM_TITLE = "ﺔﻴﻔﻠﺨﻟﺍ ﺔﻴﻨﻏﻻﺍ"
SFX_TITLE = "ﺔﻴﺗﻮﺼﻟﺍ ﺕﺍﺮﺛﺆﻤﻟﺍ"
BGS_TITLE = "ﺔﻴﻔﻠﺨﻟﺍ ﺕﻮﺻﻻﺍ"
VOL_MUTE = "ﺖﻣﺎﺻ"
# These are the variables and switches that govern the sound effect volumes.
# Note that for the variables, the higher they are, the lower the volume.
BGM_VOLUME_VAR = 92 # Variable
SFX_VOLUME_VAR = 93 # Variable
BGS_VOLUME_VAR = 94 # Variable
BGM_MUTE_SWITCH = 92 # Switch
SFX_MUTE_SWITCH = 93 # Switch
BGS_MUTE_SWITCH = 94 # Switch
# This adjusts the gradient colours for each of the volume controls.
BGM_COLOUR1 = 30
BGM_COLOUR2 = 31
SFX_COLOUR1 = 28
SFX_COLOUR2 = 29
BGS_COLOUR1 = 20
BGS_COLOUR2 = 21
#---------------------
# Battle Animations
#---------------------
# This will affect what string data will appear for the toggling of
# battle animations portion of the system menu.
ANI_TITLE = "Battle Animations"
ANI_HELP = "Toggles animations during battle."
ANI_ON = "Shown"
ANI_OFF = "Hidden"
# This is the switch used to adjust battle animations. If it is off,
# animations are enabled. If it is on, animations are disabled.
ANI_SWITCH = 91
#---------------------
# Automatic Dashing
#---------------------
# This will affect what string data will appear for the toggling of
# automatic dashing portion of the system menu.
AUTO_DASH_TITLE = "ﺮﺷﺎﺒﻤﻟﺍ ﺾﻛﺮﻟﺍ"
AUTO_DASH_HELP = ".ﺔﻋﺮﺴﺑ ﻙﺮﺤﺘﺗ ﺔﻴﺼﺨﺸﻟﺍ ﻞﻌﺠﺗ"
AUTO_DASH_ON = "ﺾﻛﺮﻟﺍ"
AUTO_DASH_OFF = "ﻲﺸﻤﻟﺍ"
# This is the switch used to determine whether or not autodashing is on.
AUTO_DASH_SWITCH = 95
#---------------------
# Instant Text
#---------------------
# This will affect what string data will appear for the instant text
# portion of the system menu.
INSTANT_TEXT_TITLE = "ﺓﺮﺷﺎﺒﻣ ﺺﻨﻟﺍ"
INSTANT_TEXT_HELP = ".ﺓﺮﺷﺎﺒﻣ ﺕﺎﻴﺼﺨﺸﻠﻟ ﺺﻨﻟﺍ ﺔﺑﺎﺘﻛ"
INSTANT_TEXT_ON = ".ﺓﺮﺷﺎﺒﻣ"
INSTANT_TEXT_OFF = ".ﻱﺩﺎﻋ"
# This is the switch used to determine whether or not instant text is on.
INSTANT_TEXT_SWITCH = 96
#---------------------
# Remaining Text
#---------------------
# This will affect what remaining string data is left for the system menu.
RETURN_TO_TITLE = "ﺔﻳﺍﺪﺒﻟﺍ ﺔﺤﻔﺻ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ"
RETURN_TITLE_HELP = ".ﺔﻳﺍﺪﺒﻟﺍ ﺔﺤﻔﺻ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ"
RETURN_TO_MENU = "ﺔﺒﻌﻠﻟﺍ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ "
RETURN_MENU_HELP = ".ﺔﻴﺴﻴﺋﺮﻟﺍ ﺔﻤﺋﺎﻘﻟﺍ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ"
end # SYSTEM
end # YE
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
module Vocab
def self.game_end
return YE::SYSTEM::TITLE
end
end
module Cache
def self.windows(filename)
load_bitmap("Graphics/Windows/", filename)
end
end
module RPG
class BGM < AudioFile
def play
if @name.empty?
Audio.bgm_stop
@@last = BGM.new
else
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::BGM_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
end
Audio.bgm_play("Audio/BGM/" + @name, vol, @pitch)
@@last = self
end
end #Play
end # BGM
class ME < AudioFile
def play
if @name.empty?
Audio.me_stop
else
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::BGM_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
end
Audio.me_play("Audio/ME/" + @name, vol, @pitch)
end
end
end # ME
class SE < AudioFile
def play
unless @name.empty?
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::SFX_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::SFX_MUTE_SWITCH]
end
Audio.se_play("Audio/SE/" + @name, vol, @pitch)
end
end
def self.stop
Audio.se_stop
end
end # SE
class BGS < AudioFile
def play
if @name.empty?
Audio.bgs_stop
@@last = BGS.new
else
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::BGS_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::BGS_MUTE_SWITCH]
end
Audio.bgs_play("Audio/BGS/" + @name, vol, @pitch)
@@last = self
end
end
end # BGS
end # RPG
#===============================================================================
# Game Player
#===============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# alias dash?
#--------------------------------------------------------------------------
alias dash_mso dash? unless $@
def dash?
if $game_switches[YE::SYSTEM::AUTO_DASH_SWITCH]
return false if @move_route_forcing
return false if $game_map.disable_dash?
return false if in_vehicle?
return false if Input.press?(Input::A)
return true
else
dash_mso
end
end
end
#===============================================================================
# Window
#===============================================================================
class Window
#--------------------------------------------------------------------------
# update windowskin
#--------------------------------------------------------------------------
def update_windowskin
if $game_variables != nil
winvar = YE::SYSTEM::WINDOW_VARIABLE
if $game_variables[winvar] == 0
$game_variables[winvar] = YE::SYSTEM::DEFAULT_WINDOW
elsif !YE::SYSTEM::WINDOW_HASH.include?($game_variables[winvar])
$game_variables[winvar] = YE::SYSTEM::DEFAULT_WINDOW
end
mso_windowskin = YE::SYSTEM::WINDOW_HASH[$game_variables[winvar]]
else
mso_windowskin = YE::SYSTEM::WINDOW_HASH[YE::SYSTEM::DEFAULT_WINDOW]
end
self.windowskin = Cache.windows(mso_windowskin)
end
end
#===============================================================================
# Window Base
#===============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_window_mso initialize unless $@
def initialize(x, y, width, height)
initialize_window_mso(x, y, width, height)
self.update_windowskin
end
end
#===============================================================================
# Window Message
#===============================================================================
class Window_Message < Window_Selectable
#--------------------------------------------------------------------------
# alias update show fast
#--------------------------------------------------------------------------
alias update_show_fast_mso update_show_fast unless $@
def update_show_fast
if $game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH]
if self.pause or self.openness < 255
@show_fast = false
else
@show_fast = true
end
if @show_fast and @wait_count > 0
@wait_count -= 1
end
else
update_show_fast_mso
end
end
if $worale != nil
if $worale["NMS"]
#--------------------------------------------------------------------------
# alias draw_name
#--------------------------------------------------------------------------
alias draw_name_mso draw_name unless $@
def draw_name(name, x, y)
draw_name_mso(name, x, y)
@namebox.update_windowskin
end
end
end
end
#===============================================================================
# Window System
#===============================================================================
class Window_System < Window_Selectable
#--------------------------------------------------------------------------
# Initialize
#--------------------------------------------------------------------------
def initialize
super(0, 56, 544, 360)
@column_max = 1
self.index = 0
self.active = true
refresh
end
#--------------------------------------------------------------------------
# Refresh
#--------------------------------------------------------------------------
def refresh
@data = []
@data.push(0) # Window Skins
@data.push(1) # Sound Volume/Sound Mute
@data.push(2) # BGM Volume/BGM Mute
@data.push(3) # Ambience Volume/Ambience Mute
@data.push(4) # Battle Animations
@data.push(5) # Auto-Dash
@data.push(6) # Instant Text
@data.push(7) # Return to Title
@data.push(8) # Return to Menu
@item_max = @data.size
self.contents.clear
for i in 0..@item_max
self.contents.font.color.alpha = 255
draw_item(i)
end
#---
end
#--------------------------------------------------------------------------
# Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
sw = self.width - 32
dw = sw
#---
case index
when 0
dx = 0
dy = 0
text = YE::SYSTEM::WINDOW_SKIN
self.contents.draw_text(dx, dy, dw, WLH, text, 1)
winvar = $game_variables[YE::SYSTEM::WINDOW_VARIABLE]
text = YE::SYSTEM::WINDOW_HASH[winvar - 2]
self.contents.draw_text(dx + dw * 0/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar - 1]
self.contents.draw_text(dx + dw * 1/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar]
self.contents.draw_text(dx + dw * 2/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar + 1]
self.contents.draw_text(dx + dw * 3/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar + 2]
self.contents.draw_text(dx + dw * 4/5, dy + WLH, dw/5, WLH, text, 1)
when 1
dx = 0
dy = WLH * 2
text = YE::SYSTEM::BGM_TITLE
self.contents.draw_text(dx + 20, dy, dw/3 - 20, WLH*2, text, 0)
when 2
dx = 0
dy = WLH * 4
text = YE::SYSTEM::SFX_TITLE
self.contents.draw_text(dx + 20, dy, dw/3 - 20, WLH*2, text, 0)
when 3
dx = 0
dy = WLH * 6
text = YE::SYSTEM::BGS_TITLE
self.contents.draw_text(dx + 20, dy, dw/3 - 20, WLH*2, text, 0)
when 4
dx = 0
dy = WLH * 8
text = YE::SYSTEM::ANI_TITLE
self.contents.draw_text(dx + 20, dy, dw/2 - 20, WLH, text, 0)
if $game_switches[YE::SYSTEM::ANI_SWITCH]
en1 = false
en2 = true
else
en1 = true
en2 = false
end
text1 = YE::SYSTEM::ANI_ON
text2 = YE::SYSTEM::ANI_OFF
self.contents.font.color.alpha = en1 ? 255 : 128
self.contents.draw_text(sw*1/2, dy, dw/4, WLH, text1, 1)
self.contents.font.color.alpha = en2 ? 255 : 128
self.contents.draw_text(sw*3/4, dy, dw/4, WLH, text2, 1)
#---
when 5
dx = 0
dy = WLH * 9
text = YE::SYSTEM::AUTO_DASH_TITLE
self.contents.draw_text(dx + 20, dy, dw/2 - 20, WLH, text, 0)
if $game_switches[YE::SYSTEM::AUTO_DASH_SWITCH]
en1 = true
en2 = false
else
en1 = false
en2 = true
end
text1 = YE::SYSTEM::AUTO_DASH_ON
text2 = YE::SYSTEM::AUTO_DASH_OFF
self.contents.font.color.alpha = en1 ? 255 : 128
self.contents.draw_text(sw*1/2, dy, dw/4, WLH, text1, 1)
self.contents.font.color.alpha = en2 ? 255 : 128
self.contents.draw_text(sw*3/4, dy, dw/4, WLH, text2, 1)
#---
when 6
dx = 0
dy = WLH * 10
text = YE::SYSTEM::INSTANT_TEXT_TITLE
self.contents.draw_text(dx + 20, dy, dw/2 - 20, WLH, text, 0)
if $game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH]
en1 = true
en2 = false
else
en1 = false
en2 = true
end
text1 = YE::SYSTEM::INSTANT_TEXT_ON
text2 = YE::SYSTEM::INSTANT_TEXT_OFF
self.contents.font.color.alpha = en1 ? 255 : 128
self.contents.draw_text(sw*1/2, dy, dw/4, WLH, text1, 1)
self.contents.font.color.alpha = en2 ? 255 : 128
self.contents.draw_text(sw*3/4, dy, dw/4, WLH, text2, 1)
#---
when 7
dx = 0
dy = WLH * 11
text = YE::SYSTEM::RETURN_TO_TITLE
self.contents.draw_text(dx + 20, dy, dw - 20, WLH, text, 0)
#---
when 8
dx = 0
dy = WLH * 12
text = YE::SYSTEM::RETURN_TO_MENU
self.contents.draw_text(dx + 20, dy, dw - 20, WLH, text, 0)
end
end
#--------------------------------------------------------------------------
# Update Cursor
#--------------------------------------------------------------------------
def update_cursor
if @index < 0
self.cursor_rect.empty
elsif @index < 4
self.cursor_rect.set(0, @index * 48, self.width - 32, 48)
else
self.cursor_rect.set(0, @index * 24 + 96, self.width - 32, 24)
end
end
end
#===============================================================================
# Window Volume
#===============================================================================
class Window_Volume < Window_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(wx, wy, ww, wh, var)
super(wx, wy, ww, wh)
@var = var
if @var == YE::SYSTEM::BGM_VOLUME_VAR
@gc1 = text_color(YE::SYSTEM::BGM_COLOUR1)
@gc2 = text_color(YE::SYSTEM::BGM_COLOUR2)
@mute = YE::SYSTEM::BGM_MUTE_SWITCH
elsif @var == YE::SYSTEM::SFX_VOLUME_VAR
@gc1 = text_color(YE::SYSTEM::SFX_COLOUR1)
@gc2 = text_color(YE::SYSTEM::SFX_COLOUR2)
@mute = YE::SYSTEM::SFX_MUTE_SWITCH
else
@gc1 = text_color(YE::SYSTEM::BGS_COLOUR1)
@gc2 = text_color(YE::SYSTEM::BGS_COLOUR2)
@mute = YE::SYSTEM::BGS_MUTE_SWITCH
end
self.opacity = 0
refresh
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
sw = self.width - 32
self.contents.fill_rect(0, 14, sw-80, 20, gauge_back_color)
gw = sw-84
gw *= 100 - $game_variables[@var]
gw /= 100
gw = [[gw, 0].max, sw-84].min
self.contents.gradient_fill_rect(2, 16, gw, 16, @gc1, @gc2)
if $game_switches[@mute]
text = YE::SYSTEM::VOL_MUTE
else
text = sprintf("%d%%", 100 - $game_variables[@var])
end
self.contents.draw_text(sw-76, 0, 76, WLH*2, text, 0)
end
end
#===============================================================================
# Modern Algebra ATS Compatibility
#===============================================================================
class Window_FaceBox < Window_Base
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_fb_mso initialize unless $@
def initialize
initialize_fb_mso
self.update_windowskin
end
end
end
class Window_NameBox < Window_Base
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_nb_mso initialize unless $@
def initialize(string = '')
initialize_nb_mso(string)
self.update_windowskin
end
end
end
class Window_ChoiceBox < Window_Command
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_cb_mso initialize unless $@
def initialize
initialize_cb_mso
self.update_windowskin
end
end
end
class Window_Message < Window_Selectable
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_wm_mso initialize unless $@
def initialize
initialize_wm_mso
self.update_windowskin
end
end
end
#===============================================================================
# Scene_Battle
#===============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# alias display_normal_animation
#--------------------------------------------------------------------------
alias display_normal_animation_mso display_normal_animation unless $@
def display_normal_animation(targets, animation_id, mirror = false)
return if $game_switches[YE::SYSTEM::ANI_SWITCH]
display_normal_animation_mso(targets, animation_id, mirror)
end
end
#===============================================================================
# Scene_End
#===============================================================================
class Scene_End < Scene_Base
#--------------------------------------------------------------------------
# Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
@help_window = Window_Base.new(0, 0, 544, 56)
@help_window.contents.clear
#---
text = YE::SYSTEM::WINDOW_HELP
@help_window.contents.draw_text(4, 0, 504, 24, text, 0)
@system_window = Window_System.new
var = YE::SYSTEM::BGM_VOLUME_VAR
@bgm_vol_window = Window_Volume.new(160, 104, 384, 80, var)
var = YE::SYSTEM::SFX_VOLUME_VAR
@sfx_vol_window = Window_Volume.new(160, 152, 384, 80, var)
var = YE::SYSTEM::BGS_VOLUME_VAR
@bgs_vol_window = Window_Volume.new(160, 200, 384, 80, var)
#---
@last_index = 100
end
#--------------------------------------------------------------------------
# Post-Start Processing
#--------------------------------------------------------------------------
def post_start
super
end
#--------------------------------------------------------------------------
# Pre-termination Processing
#--------------------------------------------------------------------------
def pre_terminate
super
end
#--------------------------------------------------------------------------
# Termination Processing
#--------------------------------------------------------------------------
def terminate
super
@help_window.dispose
@system_window.dispose
@bgm_vol_window.dispose
@sfx_vol_window.dispose
@bgs_vol_window.dispose
dispose_menu_background
end
#--------------------------------------------------------------------------
# Update Help
#--------------------------------------------------------------------------
def update_help
@help_window.contents.clear
case @system_window.index
when 0; text = YE::SYSTEM::WINDOW_HELP
when 1; text = YE::SYSTEM::BGM_HELP
when 2; text = YE::SYSTEM::SFX_HELP
when 3; text = YE::SYSTEM::BGS_HELP
when 4; text = YE::SYSTEM::BGS_HELP
when 5; text = YE::SYSTEM::AUTO_DASH_HELP
when 6; text = YE::SYSTEM::INSTANT_TEXT_HELP
when 7; text = YE::SYSTEM::RETURN_TITLE_HELP
when 8; text = YE::SYSTEM::RETURN_MENU_HELP
end
@help_window.contents.draw_text(4, 0, 504, 24, text, 0)
end
#--------------------------------------------------------------------------
# Frame Update
#--------------------------------------------------------------------------
def update
super
update_menu_background
@system_window.update
if @last_index != @system_window.index
@last_index = @system_window.index
update_help
end
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
else
#---
if Input.repeat?(Input::LEFT) and @system_window.index == 0
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] -= 1
if $game_variables[YE::SYSTEM::WINDOW_VARIABLE] == 0
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] = 1
else
Sound.play_cursor
end
@system_window.refresh
@system_window.update_windowskin
@help_window.update_windowskin
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 0
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] += 1
if $game_variables[YE::SYSTEM::WINDOW_VARIABLE] >
YE::SYSTEM::WINDOW_HASH.size
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] =
YE::SYSTEM::WINDOW_HASH.size
else
Sound.play_cursor
end
@system_window.refresh
@system_window.update_windowskin
@help_window.update_windowskin
#---
elsif Input.repeat?(Input::LEFT) and @system_window.index == 1
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] += 10
else
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] += 1
end
if $game_variables[YE::SYSTEM::BGM_VOLUME_VAR] >= 100
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] = 100
end
Sound.play_cursor
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 1
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] -= 10
else
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] -= 1
end
if $game_variables[YE::SYSTEM::BGM_VOLUME_VAR] <= 0
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] = 0
end
Sound.play_cursor
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::L) and @system_window.index == 1
if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = true
end
Sound.play_decision
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::R) and @system_window.index == 1
if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = true
end
Sound.play_decision
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.repeat?(Input::LEFT) and @system_window.index == 2
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] += 10
else
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] += 1
end
if $game_variables[YE::SYSTEM::SFX_VOLUME_VAR] >= 100
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] = 100
end
Sound.play_cursor
@sfx_vol_window.refresh
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 2
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] -= 10
else
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] -= 1
end
if $game_variables[YE::SYSTEM::SFX_VOLUME_VAR] <= 0
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] = 0
end
Sound.play_cursor
@sfx_vol_window.refresh
elsif Input.trigger?(Input::L) and @system_window.index == 2
if $game_switches[YE::SYSTEM::SFX_MUTE_SWITCH]
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = true
end
Sound.play_decision
@sfx_vol_window.refresh
elsif Input.trigger?(Input::R) and @system_window.index == 2
if $game_switches[YE::SYSTEM::SFX_MUTE_SWITCH]
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = true
end
Sound.play_decision
@sfx_vol_window.refresh
elsif Input.repeat?(Input::LEFT) and @system_window.index == 3
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] += 10
else
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] += 1
end
if $game_variables[YE::SYSTEM::BGS_VOLUME_VAR] >= 100
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] = 100
end
Sound.play_cursor
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 3
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] -= 10
else
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] -= 1
end
if $game_variables[YE::SYSTEM::BGS_VOLUME_VAR] <= 0
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] = 0
end
Sound.play_cursor
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::L) and @system_window.index == 3
if $game_switches[YE::SYSTEM::BGS_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = true
end
Sound.play_decision
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::R) and @system_window.index == 3
if $game_switches[YE::SYSTEM::BGS_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = true
end
Sound.play_decision
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::LEFT) and @system_window.index == 4
$game_switches[YE::SYSTEM::ANI_SWITCH] = false
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::RIGHT) and @system_window.index == 4
$game_switches[YE::SYSTEM::ANI_SWITCH] = true
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::LEFT) and @system_window.index == 5
$game_switches[YE::SYSTEM::AUTO_DASH_SWITCH] = true
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::RIGHT) and @system_window.index == 5
$game_switches[YE::SYSTEM::AUTO_DASH_SWITCH] = false
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::LEFT) and @system_window.index == 6
$game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH] = true
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::RIGHT) and @system_window.index == 6
$game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH] = false
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::C) and @system_window.index == 7
Sound.play_decision
RPG::BGM.fade(800)
RPG::BGS.fade(800)
RPG::ME.fade(800)
$scene = Scene_Title.new
Graphics.fadeout(60)
elsif Input.trigger?(Input::C) and @system_window.index == 8
Sound.play_cancel
return_scene
end
#---
end
end
end
#===============================================================================
#
# END OF FILE
#
# Yanfly Engine RD - Menu System Options
# Last Date Updated: 2009.05.12
# Level: Easy, Normal
#
# The "End Game" option is quite possibly the most useless function in RPG Maker
# VX games. Not only does it have little functionality but its functions can
# be reproduced by Alt+F4 and F12. This script replaces "End Game" with a new
# menu altogether and giving the player some familiar options seen in many of
# today's commercial RPG's such as changing window skins, adjust sound volume,
# turning off animations during battle, and the like.
#
#===============================================================================
# Updates:
# ----------------------------------------------------------------------------
# o 2009.05.12 - Auto-Dash update. If player holds down the dash button when
# this option is enabled, the player will walk instead of dash.
# o 2009.05.09 - Compatibility update with Woratana's NeoMessage.
# Compatibility update with Modern Algebra's ATS.
# o 2009.05.07 - Started script and finished.
#===============================================================================
# Instructions
#===============================================================================
#
# Input this script anywhere above Main. It's plug and play outside of changing
# a few variables and switches, which will be listed below:
#
# - If you have variables bound to variables 91, 92, 93, and 94, scroll down and
# bind them to unused variables.
# - If you have switches bound to switches 91, 92, 93, 94, 95, or 96, scroll
# down and bind them to unused switches.
#
# Then, download the windows pack, and create a "Windows" folder inside your
# Graphics folder. Input the windows pack there. You're all set to go.
#
#===============================================================================
#
# Compatibility
# - Works With: Woratana's NeoMessage
# - Works With: Modern Algebra's ATS
# - Alias: Game_Player: dash?
# - Alias: Window_Base: initialize
# - Alias: Scene_Battle: display_normal_animation
# - Overwrites: Scene_End: All of it
# - Overwrites: Vocab: game_end
#
#===============================================================================
$imported = {} if $imported == nil
$imported["MenuSystemOptions"] = true
module YE
module SYSTEM
# This changes the "End Game" string to a new string. This completely
# overrides the default term from the database for a reason and that's
# because this is adjustable from the title menu as well.
TITLE = "ﻡﺎﻈﻨﻟﺍ"
#---------------------
# Window Configuration
#---------------------
# This will affect what string data will appear for the window selection
# portion of the system menu.
WINDOW_HELP = ".ﺔﻤﺋﺎﻘﻟﺍ ﻦﻣ ﻪﻠﻀﻔﺗ ﻱﺬﻟﺍ ﻢﻜﺤﺘﻟﺍ ﺔﺷﺎﺷ ﻥﻮﻟ ﺭﺎﺘﺧﺍ"
WINDOW_SKIN = "ﻢﻜﺤﺘﻟﺍ ﺔﺷﺎﺷ ﻥﻮﻟ"
# This sets the default window used when nothing is selected. This also
# determines the window skin used at the title screen. Reference it to
# the list below to determine which window skin. Don't make this 0.
DEFAULT_WINDOW = 1
# This determines the variable used to store the player's windowskin choice.
WINDOW_VARIABLE = 91
# This below determines what the variable refers to when it's used as
# reference. Put your windows inside the Graphics/Windows folder. ID 0 will
# automatically push back to the default window's ID.
WINDOW_HASH ={
# Window ID => Window Name
1 => "ﻢﺗﺎﻗ ﺮﻀﺧﺃ",
2 => "ﺮﻔﺻﺃ",
3 => "ﻲﺋﺎﻤﺳ ﻕﺭﺯﺃ",
4 => "ﺮﻤﺣﺃ",
5 => "ﻱﺮﻫﺯ",
6 => "ﻲﺠﺴﻔﻨﺑ",
7 => "ﻲﻄﻴﺤﻣ",
8 => "ءﺎﻗﺭﺯ ﺔﻴﻟﺎﻋ ﺔﻴﻨﻘﺗ",
9 => "ءﺍﺮﻤﺣ ﺔﻴﻟﺎﻋ ﺔﻴﻨﻘﺗ",
10 => "ﻲﺒﺸﺧ",
11 => "ﺔﻴﻟﺎﻴﺧ",
12 => "ﺔﻳﺮﺤﺳ",
13 => "ﺓﺩﺭﺎﺑ ءﺎﻗﺭﺯ",
14 => "ﺓﺰﻴﻤﻣ ءﺍﺩﻮﺳ",
} # Do not remove this.
#---------------------
# Volume Configuration
#---------------------
# This will affect what string data will appear for the volume adjustment
# portion of the system menu.
BGM_HELP = ".ﺖﻣﺎﺻ ﻪﻠﻌﺠﻟ Q ﻭﺃ W ﻰﻠﻋ ﻂﻐﺿﺍ ﺔﻴﻔﻠﺨﻟﺍ ﺔﻴﻨﻏﻻﺍ ﻂﺒﺿﺍ"
SFX_HELP = ".ﺖﻣﺎﺻ ﻪﻠﻌﺠﻟ Q ﻭﺃ W ﻰﻠﻋ ﻂﻐﺿﺍ ﺔﻴﺗﻮﺼﻟﺍ ﺕﺍﺮﺛﺆﻤﻟﺍ ﻂﺒﺿﺍ"
BGS_HELP = ".ﺖﻣﺎﺻ ﻪﻠﻌﺠﻟ Q ﻭﺃ W ﻰﻠﻋ ﻂﻐﺿﺍ ﺔﻴﻔﻠﺨﻟﺍ ﺕﻮﺻﻻﺍ ﻂﺒﺿﺍ"
BGM_TITLE = "ﺔﻴﻔﻠﺨﻟﺍ ﺔﻴﻨﻏﻻﺍ"
SFX_TITLE = "ﺔﻴﺗﻮﺼﻟﺍ ﺕﺍﺮﺛﺆﻤﻟﺍ"
BGS_TITLE = "ﺔﻴﻔﻠﺨﻟﺍ ﺕﻮﺻﻻﺍ"
VOL_MUTE = "ﺖﻣﺎﺻ"
# These are the variables and switches that govern the sound effect volumes.
# Note that for the variables, the higher they are, the lower the volume.
BGM_VOLUME_VAR = 92 # Variable
SFX_VOLUME_VAR = 93 # Variable
BGS_VOLUME_VAR = 94 # Variable
BGM_MUTE_SWITCH = 92 # Switch
SFX_MUTE_SWITCH = 93 # Switch
BGS_MUTE_SWITCH = 94 # Switch
# This adjusts the gradient colours for each of the volume controls.
BGM_COLOUR1 = 30
BGM_COLOUR2 = 31
SFX_COLOUR1 = 28
SFX_COLOUR2 = 29
BGS_COLOUR1 = 20
BGS_COLOUR2 = 21
#---------------------
# Battle Animations
#---------------------
# This will affect what string data will appear for the toggling of
# battle animations portion of the system menu.
ANI_TITLE = "Battle Animations"
ANI_HELP = "Toggles animations during battle."
ANI_ON = "Shown"
ANI_OFF = "Hidden"
# This is the switch used to adjust battle animations. If it is off,
# animations are enabled. If it is on, animations are disabled.
ANI_SWITCH = 91
#---------------------
# Automatic Dashing
#---------------------
# This will affect what string data will appear for the toggling of
# automatic dashing portion of the system menu.
AUTO_DASH_TITLE = "ﺮﺷﺎﺒﻤﻟﺍ ﺾﻛﺮﻟﺍ"
AUTO_DASH_HELP = ".ﺔﻋﺮﺴﺑ ﻙﺮﺤﺘﺗ ﺔﻴﺼﺨﺸﻟﺍ ﻞﻌﺠﺗ"
AUTO_DASH_ON = "ﺾﻛﺮﻟﺍ"
AUTO_DASH_OFF = "ﻲﺸﻤﻟﺍ"
# This is the switch used to determine whether or not autodashing is on.
AUTO_DASH_SWITCH = 95
#---------------------
# Instant Text
#---------------------
# This will affect what string data will appear for the instant text
# portion of the system menu.
INSTANT_TEXT_TITLE = "ﺓﺮﺷﺎﺒﻣ ﺺﻨﻟﺍ"
INSTANT_TEXT_HELP = ".ﺓﺮﺷﺎﺒﻣ ﺕﺎﻴﺼﺨﺸﻠﻟ ﺺﻨﻟﺍ ﺔﺑﺎﺘﻛ"
INSTANT_TEXT_ON = ".ﺓﺮﺷﺎﺒﻣ"
INSTANT_TEXT_OFF = ".ﻱﺩﺎﻋ"
# This is the switch used to determine whether or not instant text is on.
INSTANT_TEXT_SWITCH = 96
#---------------------
# Remaining Text
#---------------------
# This will affect what remaining string data is left for the system menu.
RETURN_TO_TITLE = "ﺔﻳﺍﺪﺒﻟﺍ ﺔﺤﻔﺻ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ"
RETURN_TITLE_HELP = ".ﺔﻳﺍﺪﺒﻟﺍ ﺔﺤﻔﺻ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ"
RETURN_TO_MENU = "ﺔﺒﻌﻠﻟﺍ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ "
RETURN_MENU_HELP = ".ﺔﻴﺴﻴﺋﺮﻟﺍ ﺔﻤﺋﺎﻘﻟﺍ ﻰﻟﺍ ﻉﻮﺟﺮﻟﺍ"
end # SYSTEM
end # YE
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
module Vocab
def self.game_end
return YE::SYSTEM::TITLE
end
end
module Cache
def self.windows(filename)
load_bitmap("Graphics/Windows/", filename)
end
end
module RPG
class BGM < AudioFile
def play
if @name.empty?
Audio.bgm_stop
@@last = BGM.new
else
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::BGM_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
end
Audio.bgm_play("Audio/BGM/" + @name, vol, @pitch)
@@last = self
end
end #Play
end # BGM
class ME < AudioFile
def play
if @name.empty?
Audio.me_stop
else
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::BGM_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
end
Audio.me_play("Audio/ME/" + @name, vol, @pitch)
end
end
end # ME
class SE < AudioFile
def play
unless @name.empty?
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::SFX_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::SFX_MUTE_SWITCH]
end
Audio.se_play("Audio/SE/" + @name, vol, @pitch)
end
end
def self.stop
Audio.se_stop
end
end # SE
class BGS < AudioFile
def play
if @name.empty?
Audio.bgs_stop
@@last = BGS.new
else
vol = @volume
if $game_variables != nil
vol *= 100 - $game_variables[YE::SYSTEM::BGS_VOLUME_VAR]
vol /= 100
vol = [[vol, 0].max, 100].min
vol = 0 if $game_switches[YE::SYSTEM::BGS_MUTE_SWITCH]
end
Audio.bgs_play("Audio/BGS/" + @name, vol, @pitch)
@@last = self
end
end
end # BGS
end # RPG
#===============================================================================
# Game Player
#===============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# alias dash?
#--------------------------------------------------------------------------
alias dash_mso dash? unless $@
def dash?
if $game_switches[YE::SYSTEM::AUTO_DASH_SWITCH]
return false if @move_route_forcing
return false if $game_map.disable_dash?
return false if in_vehicle?
return false if Input.press?(Input::A)
return true
else
dash_mso
end
end
end
#===============================================================================
# Window
#===============================================================================
class Window
#--------------------------------------------------------------------------
# update windowskin
#--------------------------------------------------------------------------
def update_windowskin
if $game_variables != nil
winvar = YE::SYSTEM::WINDOW_VARIABLE
if $game_variables[winvar] == 0
$game_variables[winvar] = YE::SYSTEM::DEFAULT_WINDOW
elsif !YE::SYSTEM::WINDOW_HASH.include?($game_variables[winvar])
$game_variables[winvar] = YE::SYSTEM::DEFAULT_WINDOW
end
mso_windowskin = YE::SYSTEM::WINDOW_HASH[$game_variables[winvar]]
else
mso_windowskin = YE::SYSTEM::WINDOW_HASH[YE::SYSTEM::DEFAULT_WINDOW]
end
self.windowskin = Cache.windows(mso_windowskin)
end
end
#===============================================================================
# Window Base
#===============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_window_mso initialize unless $@
def initialize(x, y, width, height)
initialize_window_mso(x, y, width, height)
self.update_windowskin
end
end
#===============================================================================
# Window Message
#===============================================================================
class Window_Message < Window_Selectable
#--------------------------------------------------------------------------
# alias update show fast
#--------------------------------------------------------------------------
alias update_show_fast_mso update_show_fast unless $@
def update_show_fast
if $game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH]
if self.pause or self.openness < 255
@show_fast = false
else
@show_fast = true
end
if @show_fast and @wait_count > 0
@wait_count -= 1
end
else
update_show_fast_mso
end
end
if $worale != nil
if $worale["NMS"]
#--------------------------------------------------------------------------
# alias draw_name
#--------------------------------------------------------------------------
alias draw_name_mso draw_name unless $@
def draw_name(name, x, y)
draw_name_mso(name, x, y)
@namebox.update_windowskin
end
end
end
end
#===============================================================================
# Window System
#===============================================================================
class Window_System < Window_Selectable
#--------------------------------------------------------------------------
# Initialize
#--------------------------------------------------------------------------
def initialize
super(0, 56, 544, 360)
@column_max = 1
self.index = 0
self.active = true
refresh
end
#--------------------------------------------------------------------------
# Refresh
#--------------------------------------------------------------------------
def refresh
@data = []
@data.push(0) # Window Skins
@data.push(1) # Sound Volume/Sound Mute
@data.push(2) # BGM Volume/BGM Mute
@data.push(3) # Ambience Volume/Ambience Mute
@data.push(4) # Battle Animations
@data.push(5) # Auto-Dash
@data.push(6) # Instant Text
@data.push(7) # Return to Title
@data.push(8) # Return to Menu
@item_max = @data.size
self.contents.clear
for i in 0..@item_max
self.contents.font.color.alpha = 255
draw_item(i)
end
#---
end
#--------------------------------------------------------------------------
# Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
sw = self.width - 32
dw = sw
#---
case index
when 0
dx = 0
dy = 0
text = YE::SYSTEM::WINDOW_SKIN
self.contents.draw_text(dx, dy, dw, WLH, text, 1)
winvar = $game_variables[YE::SYSTEM::WINDOW_VARIABLE]
text = YE::SYSTEM::WINDOW_HASH[winvar - 2]
self.contents.draw_text(dx + dw * 0/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar - 1]
self.contents.draw_text(dx + dw * 1/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar]
self.contents.draw_text(dx + dw * 2/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar + 1]
self.contents.draw_text(dx + dw * 3/5, dy + WLH, dw/5, WLH, text, 1)
text = YE::SYSTEM::WINDOW_HASH[winvar + 2]
self.contents.draw_text(dx + dw * 4/5, dy + WLH, dw/5, WLH, text, 1)
when 1
dx = 0
dy = WLH * 2
text = YE::SYSTEM::BGM_TITLE
self.contents.draw_text(dx + 20, dy, dw/3 - 20, WLH*2, text, 0)
when 2
dx = 0
dy = WLH * 4
text = YE::SYSTEM::SFX_TITLE
self.contents.draw_text(dx + 20, dy, dw/3 - 20, WLH*2, text, 0)
when 3
dx = 0
dy = WLH * 6
text = YE::SYSTEM::BGS_TITLE
self.contents.draw_text(dx + 20, dy, dw/3 - 20, WLH*2, text, 0)
when 4
dx = 0
dy = WLH * 8
text = YE::SYSTEM::ANI_TITLE
self.contents.draw_text(dx + 20, dy, dw/2 - 20, WLH, text, 0)
if $game_switches[YE::SYSTEM::ANI_SWITCH]
en1 = false
en2 = true
else
en1 = true
en2 = false
end
text1 = YE::SYSTEM::ANI_ON
text2 = YE::SYSTEM::ANI_OFF
self.contents.font.color.alpha = en1 ? 255 : 128
self.contents.draw_text(sw*1/2, dy, dw/4, WLH, text1, 1)
self.contents.font.color.alpha = en2 ? 255 : 128
self.contents.draw_text(sw*3/4, dy, dw/4, WLH, text2, 1)
#---
when 5
dx = 0
dy = WLH * 9
text = YE::SYSTEM::AUTO_DASH_TITLE
self.contents.draw_text(dx + 20, dy, dw/2 - 20, WLH, text, 0)
if $game_switches[YE::SYSTEM::AUTO_DASH_SWITCH]
en1 = true
en2 = false
else
en1 = false
en2 = true
end
text1 = YE::SYSTEM::AUTO_DASH_ON
text2 = YE::SYSTEM::AUTO_DASH_OFF
self.contents.font.color.alpha = en1 ? 255 : 128
self.contents.draw_text(sw*1/2, dy, dw/4, WLH, text1, 1)
self.contents.font.color.alpha = en2 ? 255 : 128
self.contents.draw_text(sw*3/4, dy, dw/4, WLH, text2, 1)
#---
when 6
dx = 0
dy = WLH * 10
text = YE::SYSTEM::INSTANT_TEXT_TITLE
self.contents.draw_text(dx + 20, dy, dw/2 - 20, WLH, text, 0)
if $game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH]
en1 = true
en2 = false
else
en1 = false
en2 = true
end
text1 = YE::SYSTEM::INSTANT_TEXT_ON
text2 = YE::SYSTEM::INSTANT_TEXT_OFF
self.contents.font.color.alpha = en1 ? 255 : 128
self.contents.draw_text(sw*1/2, dy, dw/4, WLH, text1, 1)
self.contents.font.color.alpha = en2 ? 255 : 128
self.contents.draw_text(sw*3/4, dy, dw/4, WLH, text2, 1)
#---
when 7
dx = 0
dy = WLH * 11
text = YE::SYSTEM::RETURN_TO_TITLE
self.contents.draw_text(dx + 20, dy, dw - 20, WLH, text, 0)
#---
when 8
dx = 0
dy = WLH * 12
text = YE::SYSTEM::RETURN_TO_MENU
self.contents.draw_text(dx + 20, dy, dw - 20, WLH, text, 0)
end
end
#--------------------------------------------------------------------------
# Update Cursor
#--------------------------------------------------------------------------
def update_cursor
if @index < 0
self.cursor_rect.empty
elsif @index < 4
self.cursor_rect.set(0, @index * 48, self.width - 32, 48)
else
self.cursor_rect.set(0, @index * 24 + 96, self.width - 32, 24)
end
end
end
#===============================================================================
# Window Volume
#===============================================================================
class Window_Volume < Window_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(wx, wy, ww, wh, var)
super(wx, wy, ww, wh)
@var = var
if @var == YE::SYSTEM::BGM_VOLUME_VAR
@gc1 = text_color(YE::SYSTEM::BGM_COLOUR1)
@gc2 = text_color(YE::SYSTEM::BGM_COLOUR2)
@mute = YE::SYSTEM::BGM_MUTE_SWITCH
elsif @var == YE::SYSTEM::SFX_VOLUME_VAR
@gc1 = text_color(YE::SYSTEM::SFX_COLOUR1)
@gc2 = text_color(YE::SYSTEM::SFX_COLOUR2)
@mute = YE::SYSTEM::SFX_MUTE_SWITCH
else
@gc1 = text_color(YE::SYSTEM::BGS_COLOUR1)
@gc2 = text_color(YE::SYSTEM::BGS_COLOUR2)
@mute = YE::SYSTEM::BGS_MUTE_SWITCH
end
self.opacity = 0
refresh
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
sw = self.width - 32
self.contents.fill_rect(0, 14, sw-80, 20, gauge_back_color)
gw = sw-84
gw *= 100 - $game_variables[@var]
gw /= 100
gw = [[gw, 0].max, sw-84].min
self.contents.gradient_fill_rect(2, 16, gw, 16, @gc1, @gc2)
if $game_switches[@mute]
text = YE::SYSTEM::VOL_MUTE
else
text = sprintf("%d%%", 100 - $game_variables[@var])
end
self.contents.draw_text(sw-76, 0, 76, WLH*2, text, 0)
end
end
#===============================================================================
# Modern Algebra ATS Compatibility
#===============================================================================
class Window_FaceBox < Window_Base
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_fb_mso initialize unless $@
def initialize
initialize_fb_mso
self.update_windowskin
end
end
end
class Window_NameBox < Window_Base
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_nb_mso initialize unless $@
def initialize(string = '')
initialize_nb_mso(string)
self.update_windowskin
end
end
end
class Window_ChoiceBox < Window_Command
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_cb_mso initialize unless $@
def initialize
initialize_cb_mso
self.update_windowskin
end
end
end
class Window_Message < Window_Selectable
unless method_defined?(:initialize)
#--------------------------------------------------------------------------
# alias initialize
#--------------------------------------------------------------------------
alias initialize_wm_mso initialize unless $@
def initialize
initialize_wm_mso
self.update_windowskin
end
end
end
#===============================================================================
# Scene_Battle
#===============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# alias display_normal_animation
#--------------------------------------------------------------------------
alias display_normal_animation_mso display_normal_animation unless $@
def display_normal_animation(targets, animation_id, mirror = false)
return if $game_switches[YE::SYSTEM::ANI_SWITCH]
display_normal_animation_mso(targets, animation_id, mirror)
end
end
#===============================================================================
# Scene_End
#===============================================================================
class Scene_End < Scene_Base
#--------------------------------------------------------------------------
# Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
@help_window = Window_Base.new(0, 0, 544, 56)
@help_window.contents.clear
#---
text = YE::SYSTEM::WINDOW_HELP
@help_window.contents.draw_text(4, 0, 504, 24, text, 0)
@system_window = Window_System.new
var = YE::SYSTEM::BGM_VOLUME_VAR
@bgm_vol_window = Window_Volume.new(160, 104, 384, 80, var)
var = YE::SYSTEM::SFX_VOLUME_VAR
@sfx_vol_window = Window_Volume.new(160, 152, 384, 80, var)
var = YE::SYSTEM::BGS_VOLUME_VAR
@bgs_vol_window = Window_Volume.new(160, 200, 384, 80, var)
#---
@last_index = 100
end
#--------------------------------------------------------------------------
# Post-Start Processing
#--------------------------------------------------------------------------
def post_start
super
end
#--------------------------------------------------------------------------
# Pre-termination Processing
#--------------------------------------------------------------------------
def pre_terminate
super
end
#--------------------------------------------------------------------------
# Termination Processing
#--------------------------------------------------------------------------
def terminate
super
@help_window.dispose
@system_window.dispose
@bgm_vol_window.dispose
@sfx_vol_window.dispose
@bgs_vol_window.dispose
dispose_menu_background
end
#--------------------------------------------------------------------------
# Update Help
#--------------------------------------------------------------------------
def update_help
@help_window.contents.clear
case @system_window.index
when 0; text = YE::SYSTEM::WINDOW_HELP
when 1; text = YE::SYSTEM::BGM_HELP
when 2; text = YE::SYSTEM::SFX_HELP
when 3; text = YE::SYSTEM::BGS_HELP
when 4; text = YE::SYSTEM::BGS_HELP
when 5; text = YE::SYSTEM::AUTO_DASH_HELP
when 6; text = YE::SYSTEM::INSTANT_TEXT_HELP
when 7; text = YE::SYSTEM::RETURN_TITLE_HELP
when 8; text = YE::SYSTEM::RETURN_MENU_HELP
end
@help_window.contents.draw_text(4, 0, 504, 24, text, 0)
end
#--------------------------------------------------------------------------
# Frame Update
#--------------------------------------------------------------------------
def update
super
update_menu_background
@system_window.update
if @last_index != @system_window.index
@last_index = @system_window.index
update_help
end
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
else
#---
if Input.repeat?(Input::LEFT) and @system_window.index == 0
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] -= 1
if $game_variables[YE::SYSTEM::WINDOW_VARIABLE] == 0
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] = 1
else
Sound.play_cursor
end
@system_window.refresh
@system_window.update_windowskin
@help_window.update_windowskin
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 0
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] += 1
if $game_variables[YE::SYSTEM::WINDOW_VARIABLE] >
YE::SYSTEM::WINDOW_HASH.size
$game_variables[YE::SYSTEM::WINDOW_VARIABLE] =
YE::SYSTEM::WINDOW_HASH.size
else
Sound.play_cursor
end
@system_window.refresh
@system_window.update_windowskin
@help_window.update_windowskin
#---
elsif Input.repeat?(Input::LEFT) and @system_window.index == 1
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] += 10
else
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] += 1
end
if $game_variables[YE::SYSTEM::BGM_VOLUME_VAR] >= 100
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] = 100
end
Sound.play_cursor
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 1
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] -= 10
else
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] -= 1
end
if $game_variables[YE::SYSTEM::BGM_VOLUME_VAR] <= 0
$game_variables[YE::SYSTEM::BGM_VOLUME_VAR] = 0
end
Sound.play_cursor
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::L) and @system_window.index == 1
if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = true
end
Sound.play_decision
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::R) and @system_window.index == 1
if $game_switches[YE::SYSTEM::BGM_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGM_MUTE_SWITCH] = true
end
Sound.play_decision
@bgm_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.repeat?(Input::LEFT) and @system_window.index == 2
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] += 10
else
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] += 1
end
if $game_variables[YE::SYSTEM::SFX_VOLUME_VAR] >= 100
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] = 100
end
Sound.play_cursor
@sfx_vol_window.refresh
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 2
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] -= 10
else
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] -= 1
end
if $game_variables[YE::SYSTEM::SFX_VOLUME_VAR] <= 0
$game_variables[YE::SYSTEM::SFX_VOLUME_VAR] = 0
end
Sound.play_cursor
@sfx_vol_window.refresh
elsif Input.trigger?(Input::L) and @system_window.index == 2
if $game_switches[YE::SYSTEM::SFX_MUTE_SWITCH]
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = true
end
Sound.play_decision
@sfx_vol_window.refresh
elsif Input.trigger?(Input::R) and @system_window.index == 2
if $game_switches[YE::SYSTEM::SFX_MUTE_SWITCH]
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::SFX_MUTE_SWITCH] = true
end
Sound.play_decision
@sfx_vol_window.refresh
elsif Input.repeat?(Input::LEFT) and @system_window.index == 3
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] += 10
else
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] += 1
end
if $game_variables[YE::SYSTEM::BGS_VOLUME_VAR] >= 100
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] = 100
end
Sound.play_cursor
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.repeat?(Input::RIGHT) and @system_window.index == 3
if Input.press?(Input::A)
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] -= 10
else
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] -= 1
end
if $game_variables[YE::SYSTEM::BGS_VOLUME_VAR] <= 0
$game_variables[YE::SYSTEM::BGS_VOLUME_VAR] = 0
end
Sound.play_cursor
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::L) and @system_window.index == 3
if $game_switches[YE::SYSTEM::BGS_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = true
end
Sound.play_decision
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::R) and @system_window.index == 3
if $game_switches[YE::SYSTEM::BGS_MUTE_SWITCH]
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = false
else
$game_switches[YE::SYSTEM::BGS_MUTE_SWITCH] = true
end
Sound.play_decision
@bgs_vol_window.refresh
RPG::BGM.last.play
RPG::BGS.last.play
elsif Input.trigger?(Input::LEFT) and @system_window.index == 4
$game_switches[YE::SYSTEM::ANI_SWITCH] = false
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::RIGHT) and @system_window.index == 4
$game_switches[YE::SYSTEM::ANI_SWITCH] = true
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::LEFT) and @system_window.index == 5
$game_switches[YE::SYSTEM::AUTO_DASH_SWITCH] = true
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::RIGHT) and @system_window.index == 5
$game_switches[YE::SYSTEM::AUTO_DASH_SWITCH] = false
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::LEFT) and @system_window.index == 6
$game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH] = true
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::RIGHT) and @system_window.index == 6
$game_switches[YE::SYSTEM::INSTANT_TEXT_SWITCH] = false
Sound.play_decision
@system_window.refresh
elsif Input.trigger?(Input::C) and @system_window.index == 7
Sound.play_decision
RPG::BGM.fade(800)
RPG::BGS.fade(800)
RPG::ME.fade(800)
$scene = Scene_Title.new
Graphics.fadeout(60)
elsif Input.trigger?(Input::C) and @system_window.index == 8
Sound.play_cancel
return_scene
end
#---
end
end
end
#===============================================================================
#
# END OF FILE
Mouse :
Path Finding by modern algebra
CODE
#==============================================================================
# Path Finding
# Version: 2.0
# Author: modern algebra (rmrk.net)
# Date: April 10, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Thanks:
# Patrick Lester! For his tutorial on A* Pathfinding algorithm (found at:
# http://www.gamedev.net/reference/articles/article2003.asp) as well as
# another amazingly helpful tutorial on using binary heaps (found at:
# http://www.policyalmanac.org/games/binaryHeaps.htm). Without his excellent
# tutorials, this script would not exist. So major thanks to him.
# Zeriab, for tricking me into believing that this was an actual exercise.
# Also, his table printout actually makes Tables useable :P
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Instructions:
# To use, merely use this code in a script call INSIDE a Move Event:
#
# find_path (target_x, target_y, diagonal, max_iterations)
#
# where target_x and target_y are the target coordinates and diagonal is an
# optional boolean value (true or false) stating whether or not to allow
# diagonal movement. max_iterations is also optional, and you can set this if
# you want the algorithm to quit if it is taking too long. The number you set
# here refers to how many nodes you let it search through before cancelling
# the process. If this is set to 0, it will take as many iterations as
# necessary to find the shortest path.
#
# You can also set a default value for diagonal and max_iterations
# by call script with the codes:
#
# $game_system.pathfinding_diagonal = true/false # Allow diagonal movement
# $game_system.pathfinding_iterations = integer # When <= 0, no limit
#
# For scripters, you can force-move a character down a path via:
#
# character.force_path (x, y, diagonal, max_iterations)
#
# character is any Game_Character object, such as $game_player or an event.
#
# Then, when you do not specifically set diagonal or limit, it will default
# to the values you set in there
#==============================================================================
#==============================================================================
# ** Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new instance variables - pathfinding_diagonal, pathfinding_iterations
# aliased method - initialize
#==============================================================================
class Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Public Instance Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
attr_accessor :pathfinding_diagonal
attr_accessor :pathfinding_iterations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_pathfinding_options_init_j5yt initialize
def initialize
modalg_pathfinding_options_init_j5yt
@pathfinding_diagonal = false
@pathfinding_iterations = 0
end
end
#==============================================================================
# ** Game_Character
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new methods - find_path
#==============================================================================
class Game_Character
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Find Path
# trgt_x, trgt_y : the target coordinates
# diagonal : Is diagonal movement allowed?
# max_iterations : maximum number of iterations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def find_path (trgt_x, trgt_y, diagonal = $game_system.pathfinding_diagonal,
max_iterations = $game_system.pathfinding_iterations)
path = $game_map.find_path (self.x, self.y, trgt_x, trgt_y, diagonal,
max_iterations, self)
# Add the path to the move route being executed.
@move_route.list.delete_at (@move_route_index)
path.each { |i| @move_route.list.insert (@move_route_index, i) }
@move_route_index -= 1
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Force Path
# trgt_x, trgt_y : target coordinates
# diagonal : Is diagonal movement allowed?
# max_iterations : maximum number of iterations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def force_path (trgt_x, trgt_y, diagonal = $game_system.pathfinding_diagonal,
max_iterations = $game_system.pathfinding_iterations)
path = $game_map.find_path (self.x, self.y, trgt_x, trgt_y, diagonal,
max_iterations, self)
# The path retrieved is actually backwards, so it must be reversed
path.reverse!
# Add an end ccommand
path.push (RPG::MoveCommand.new (0))
move_route = RPG::MoveRoute.new
move_route.list = path
move_route.repeat = false
force_move_route (move_route)
end
end
#==============================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new method - removefrom_binaryheap, find_path
#==============================================================================
class Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Remove from Heap
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def removefrom_binaryheap
@open_nodes[1] = @open_nodes[@listsize]
@listsize -= 1
v = 1
loop do
u = v
w = 2*u
# Check if it's cost is greater than that of it's children
if w + 1 <= @listsize # If both children exist
v = w if @total_cost[@open_nodes[u]] >= @total_cost[@open_nodes[w]]
v = w + 1 if @total_cost[@open_nodes[v]] >= @total_cost[@open_nodes[w + 1]]
elsif w <= @listsize # If only one child exists
v = w if @total_cost[@open_nodes[u]] >= @total_cost[@open_nodes[w]]
end
# Break if parent has less cost than it's children
if u == v
break
else
temp = @open_nodes[u]
@open_nodes[u] = @open_nodes[v]
@open_nodes[v] = temp
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Find Path
# src_x, src_y : the source coordinates
# trgt_x, trgt_y : the target coordinates
# diagonal : Is diagonal movement allowed?
# max_iterations : maximum number of iterations
# char : character to follow the path
#--------------------------------------------------------------------------
# Uses the A* method of pathfinding to find a path
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def find_path (src_x, src_y, trgt_x, trgt_y, diagonal, max_iterations, char)
# No possible path if the target itself is impassable
path = []
# Finished if Target Location is closed
return path if !char.passable? (trgt_x, trgt_y)
# Initialize
max_elements = width*height + 2
openx = Table.new (max_elements)
openy = Table.new (max_elements)
@open_nodes = Table.new (max_elements)
@total_cost = Table.new (max_elements)
heuristic = Table.new (max_elements)
step_cost = Table.new (width, height)
parent_x = Table.new (width, height)
parent_y = Table.new (width, height)
actual_list = Table.new (width, height)
# Add the source node to the open list
new_openid = 1
@open_nodes[1] = 1
openx[1] = src_x
openy[1] = src_y
dist = [(trgt_x - src_x).abs, (trgt_y - src_y).abs]
heuristic[1] = diagonal ? (dist.max*14) + (dist.min*10) : (dist[0] + dist[1])*10
@total_cost[1] = heuristic[1]
actual_list[src_x, src_y] = 1
@listsize = 1
count = 0
loop do
break if actual_list[trgt_x, trgt_y] != 0
count += 1
# Update Graphics every 500 iterations
Graphics.update if count % 500 == 0
return path if count == max_iterations
return path if @listsize == 0
node = @open_nodes[1]
# Set the x and y value as parent to all possible children
parent_xval, parent_yval = openx[node], openy[node]
actual_list[parent_xval, parent_yval] = 2
removefrom_binaryheap
# Check all adjacent squares
for i in 0...8
break if i > 3 && !diagonal
# Get the node
x, y = case i
when 0 then [parent_xval, parent_yval - 1] # UP
when 1 then [parent_xval, parent_yval + 1] # DOWN
when 2 then [parent_xval - 1, parent_yval] # LEFT
when 3 then [parent_xval + 1, parent_yval] # RIGHT
when 4 then [parent_xval - 1, parent_yval - 1] # UP LEFT
when 5 then [parent_xval + 1, parent_yval - 1] # UP RIGHT
when 6 then [parent_xval - 1, parent_yval + 1] # DOWN LEFT
when 7 then [parent_xval + 1, parent_yval + 1] # DOWN RIGHT
end
# Next if this node is already in the closed list
next if actual_list[x,y] == 2
# Next if this tile in impassable
next unless char.passable? (x, y) # Is the tile passable?
# Take into account diagonal passability concerns
if i > 3
next unless case i
when 4 then char.passable? (x + 1, y) || char.passable? (x, y + 1)
when 5 then char.passable? (x - 1, y) || char.passable? (x, y + 1)
when 6 then char.passable? (x + 1, y) || char.passable? (x, y - 1)
when 7 then char.passable? (x - 1, y) || char.passable? (x, y - 1)
end
end
# Check if this node already open
plus_step_cost = ((x - parent_xval).abs + (y - parent_yval).abs) > 1 ? 14 : 10
temp_step_cost = step_cost[parent_xval, parent_yval] + plus_step_cost
if actual_list[x,y] == 1
# If this is a better path to that node
if temp_step_cost < step_cost[x, y]
# Change Parent, step, and total cost
parent_x[x, y] = parent_xval
parent_y[x, y] = parent_yval
step_cost[x, y] = temp_step_cost
# Find index of this position
index = 1
while index < @listsize
index += 1
break if openx[@open_nodes[index]] == x &&
openy[@open_nodes[index]] == y
end
@total_cost[@open_nodes[index]] = temp_step_cost + heuristic[@open_nodes[index]]
else
next
end
else # If not on open nodes
# Add to open nodes
new_openid += 1 # New Id for new item
@listsize += 1 # Increase List Size
@open_nodes[@listsize] = new_openid
step_cost[x, y] = temp_step_cost
# Calculate Heuristic
d = [(trgt_x - x).abs, (trgt_y - y).abs]
heuristic[new_openid] = diagonal ? (d.max*14) + (d.min*10) : (d[0] + d[1])*10
@total_cost[new_openid] = temp_step_cost + heuristic[new_openid]
parent_x[x, y] = parent_xval
parent_y[x, y] = parent_yval
openx[new_openid] = x
openy[new_openid] = y
index = @listsize
actual_list[x, y] = 1
end
# Sort Binary Heap
while index != 1
temp_node = @open_nodes[index]
if @total_cost[temp_node] <= @total_cost[@open_nodes[index / 2]]
@open_nodes[index] = @open_nodes[index / 2]
index /= 2
@open_nodes[index] = temp_node
else
break
end
end
end
end
# Get actual target node
path_x, path_y = trgt_x, trgt_y
# Make an array of MoveRoute Commands
while path_x != src_x || path_y != src_y
# Get Parent x, Parent Y
prnt_x, prnt_y = parent_x[path_x, path_y], parent_y[path_x, path_y]
# DOWN = 1, LEFT = 2, RIGHT = 3, UP = 4, DL = 5, DR = 6, UL = 7, UR = 8
if path_x < prnt_x # LEFT
# Determine if upper, lower or direct left
code = path_y < prnt_y ? 7 : path_y > prnt_y ? 5 : 2
elsif path_x > prnt_x # RIGHT
# Determine if upper, lower or direct right
code = path_y < prnt_y ? 8 : path_y > prnt_y ? 6 : 3
else # UP or DOWN
code = path_y < prnt_y ? 4 : 1
end
path.push (RPG::MoveCommand.new (code))
path_x, path_y = prnt_x, prnt_y
end
return path
end
end
# Path Finding
# Version: 2.0
# Author: modern algebra (rmrk.net)
# Date: April 10, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Thanks:
# Patrick Lester! For his tutorial on A* Pathfinding algorithm (found at:
# http://www.gamedev.net/reference/articles/article2003.asp) as well as
# another amazingly helpful tutorial on using binary heaps (found at:
# http://www.policyalmanac.org/games/binaryHeaps.htm). Without his excellent
# tutorials, this script would not exist. So major thanks to him.
# Zeriab, for tricking me into believing that this was an actual exercise.
# Also, his table printout actually makes Tables useable :P
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Instructions:
# To use, merely use this code in a script call INSIDE a Move Event:
#
# find_path (target_x, target_y, diagonal, max_iterations)
#
# where target_x and target_y are the target coordinates and diagonal is an
# optional boolean value (true or false) stating whether or not to allow
# diagonal movement. max_iterations is also optional, and you can set this if
# you want the algorithm to quit if it is taking too long. The number you set
# here refers to how many nodes you let it search through before cancelling
# the process. If this is set to 0, it will take as many iterations as
# necessary to find the shortest path.
#
# You can also set a default value for diagonal and max_iterations
# by call script with the codes:
#
# $game_system.pathfinding_diagonal = true/false # Allow diagonal movement
# $game_system.pathfinding_iterations = integer # When <= 0, no limit
#
# For scripters, you can force-move a character down a path via:
#
# character.force_path (x, y, diagonal, max_iterations)
#
# character is any Game_Character object, such as $game_player or an event.
#
# Then, when you do not specifically set diagonal or limit, it will default
# to the values you set in there
#==============================================================================
#==============================================================================
# ** Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new instance variables - pathfinding_diagonal, pathfinding_iterations
# aliased method - initialize
#==============================================================================
class Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Public Instance Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
attr_accessor :pathfinding_diagonal
attr_accessor :pathfinding_iterations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_pathfinding_options_init_j5yt initialize
def initialize
modalg_pathfinding_options_init_j5yt
@pathfinding_diagonal = false
@pathfinding_iterations = 0
end
end
#==============================================================================
# ** Game_Character
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new methods - find_path
#==============================================================================
class Game_Character
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Find Path
# trgt_x, trgt_y : the target coordinates
# diagonal : Is diagonal movement allowed?
# max_iterations : maximum number of iterations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def find_path (trgt_x, trgt_y, diagonal = $game_system.pathfinding_diagonal,
max_iterations = $game_system.pathfinding_iterations)
path = $game_map.find_path (self.x, self.y, trgt_x, trgt_y, diagonal,
max_iterations, self)
# Add the path to the move route being executed.
@move_route.list.delete_at (@move_route_index)
path.each { |i| @move_route.list.insert (@move_route_index, i) }
@move_route_index -= 1
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Force Path
# trgt_x, trgt_y : target coordinates
# diagonal : Is diagonal movement allowed?
# max_iterations : maximum number of iterations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def force_path (trgt_x, trgt_y, diagonal = $game_system.pathfinding_diagonal,
max_iterations = $game_system.pathfinding_iterations)
path = $game_map.find_path (self.x, self.y, trgt_x, trgt_y, diagonal,
max_iterations, self)
# The path retrieved is actually backwards, so it must be reversed
path.reverse!
# Add an end ccommand
path.push (RPG::MoveCommand.new (0))
move_route = RPG::MoveRoute.new
move_route.list = path
move_route.repeat = false
force_move_route (move_route)
end
end
#==============================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new method - removefrom_binaryheap, find_path
#==============================================================================
class Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Remove from Heap
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def removefrom_binaryheap
@open_nodes[1] = @open_nodes[@listsize]
@listsize -= 1
v = 1
loop do
u = v
w = 2*u
# Check if it's cost is greater than that of it's children
if w + 1 <= @listsize # If both children exist
v = w if @total_cost[@open_nodes[u]] >= @total_cost[@open_nodes[w]]
v = w + 1 if @total_cost[@open_nodes[v]] >= @total_cost[@open_nodes[w + 1]]
elsif w <= @listsize # If only one child exists
v = w if @total_cost[@open_nodes[u]] >= @total_cost[@open_nodes[w]]
end
# Break if parent has less cost than it's children
if u == v
break
else
temp = @open_nodes[u]
@open_nodes[u] = @open_nodes[v]
@open_nodes[v] = temp
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Find Path
# src_x, src_y : the source coordinates
# trgt_x, trgt_y : the target coordinates
# diagonal : Is diagonal movement allowed?
# max_iterations : maximum number of iterations
# char : character to follow the path
#--------------------------------------------------------------------------
# Uses the A* method of pathfinding to find a path
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def find_path (src_x, src_y, trgt_x, trgt_y, diagonal, max_iterations, char)
# No possible path if the target itself is impassable
path = []
# Finished if Target Location is closed
return path if !char.passable? (trgt_x, trgt_y)
# Initialize
max_elements = width*height + 2
openx = Table.new (max_elements)
openy = Table.new (max_elements)
@open_nodes = Table.new (max_elements)
@total_cost = Table.new (max_elements)
heuristic = Table.new (max_elements)
step_cost = Table.new (width, height)
parent_x = Table.new (width, height)
parent_y = Table.new (width, height)
actual_list = Table.new (width, height)
# Add the source node to the open list
new_openid = 1
@open_nodes[1] = 1
openx[1] = src_x
openy[1] = src_y
dist = [(trgt_x - src_x).abs, (trgt_y - src_y).abs]
heuristic[1] = diagonal ? (dist.max*14) + (dist.min*10) : (dist[0] + dist[1])*10
@total_cost[1] = heuristic[1]
actual_list[src_x, src_y] = 1
@listsize = 1
count = 0
loop do
break if actual_list[trgt_x, trgt_y] != 0
count += 1
# Update Graphics every 500 iterations
Graphics.update if count % 500 == 0
return path if count == max_iterations
return path if @listsize == 0
node = @open_nodes[1]
# Set the x and y value as parent to all possible children
parent_xval, parent_yval = openx[node], openy[node]
actual_list[parent_xval, parent_yval] = 2
removefrom_binaryheap
# Check all adjacent squares
for i in 0...8
break if i > 3 && !diagonal
# Get the node
x, y = case i
when 0 then [parent_xval, parent_yval - 1] # UP
when 1 then [parent_xval, parent_yval + 1] # DOWN
when 2 then [parent_xval - 1, parent_yval] # LEFT
when 3 then [parent_xval + 1, parent_yval] # RIGHT
when 4 then [parent_xval - 1, parent_yval - 1] # UP LEFT
when 5 then [parent_xval + 1, parent_yval - 1] # UP RIGHT
when 6 then [parent_xval - 1, parent_yval + 1] # DOWN LEFT
when 7 then [parent_xval + 1, parent_yval + 1] # DOWN RIGHT
end
# Next if this node is already in the closed list
next if actual_list[x,y] == 2
# Next if this tile in impassable
next unless char.passable? (x, y) # Is the tile passable?
# Take into account diagonal passability concerns
if i > 3
next unless case i
when 4 then char.passable? (x + 1, y) || char.passable? (x, y + 1)
when 5 then char.passable? (x - 1, y) || char.passable? (x, y + 1)
when 6 then char.passable? (x + 1, y) || char.passable? (x, y - 1)
when 7 then char.passable? (x - 1, y) || char.passable? (x, y - 1)
end
end
# Check if this node already open
plus_step_cost = ((x - parent_xval).abs + (y - parent_yval).abs) > 1 ? 14 : 10
temp_step_cost = step_cost[parent_xval, parent_yval] + plus_step_cost
if actual_list[x,y] == 1
# If this is a better path to that node
if temp_step_cost < step_cost[x, y]
# Change Parent, step, and total cost
parent_x[x, y] = parent_xval
parent_y[x, y] = parent_yval
step_cost[x, y] = temp_step_cost
# Find index of this position
index = 1
while index < @listsize
index += 1
break if openx[@open_nodes[index]] == x &&
openy[@open_nodes[index]] == y
end
@total_cost[@open_nodes[index]] = temp_step_cost + heuristic[@open_nodes[index]]
else
next
end
else # If not on open nodes
# Add to open nodes
new_openid += 1 # New Id for new item
@listsize += 1 # Increase List Size
@open_nodes[@listsize] = new_openid
step_cost[x, y] = temp_step_cost
# Calculate Heuristic
d = [(trgt_x - x).abs, (trgt_y - y).abs]
heuristic[new_openid] = diagonal ? (d.max*14) + (d.min*10) : (d[0] + d[1])*10
@total_cost[new_openid] = temp_step_cost + heuristic[new_openid]
parent_x[x, y] = parent_xval
parent_y[x, y] = parent_yval
openx[new_openid] = x
openy[new_openid] = y
index = @listsize
actual_list[x, y] = 1
end
# Sort Binary Heap
while index != 1
temp_node = @open_nodes[index]
if @total_cost[temp_node] <= @total_cost[@open_nodes[index / 2]]
@open_nodes[index] = @open_nodes[index / 2]
index /= 2
@open_nodes[index] = temp_node
else
break
end
end
end
end
# Get actual target node
path_x, path_y = trgt_x, trgt_y
# Make an array of MoveRoute Commands
while path_x != src_x || path_y != src_y
# Get Parent x, Parent Y
prnt_x, prnt_y = parent_x[path_x, path_y], parent_y[path_x, path_y]
# DOWN = 1, LEFT = 2, RIGHT = 3, UP = 4, DL = 5, DR = 6, UL = 7, UR = 8
if path_x < prnt_x # LEFT
# Determine if upper, lower or direct left
code = path_y < prnt_y ? 7 : path_y > prnt_y ? 5 : 2
elsif path_x > prnt_x # RIGHT
# Determine if upper, lower or direct right
code = path_y < prnt_y ? 8 : path_y > prnt_y ? 6 : 3
else # UP or DOWN
code = path_y < prnt_y ? 4 : 1
end
path.push (RPG::MoveCommand.new (code))
path_x, path_y = prnt_x, prnt_y
end
return path
end
end
DerVVulf's Mouse
CODE
#==============================================================================
# ** Mouse Input Module (Revised)
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.2
# 08-18-2007
#------------------------------------------------------------------------------
# Based on...
# Mouse Input Module
# by Near Fantastica
#------------------------------------------------------------------------------
# Set_Pos feature by
# Freakboy
#------------------------------------------------------------------------------
#
# THE CALLS:
#
# Mouse.click?
# This returns a true/false value when you test whether a button is clicked.
# The values you pass are 1 (for the left mouse button), 2 (for the right) or
# 3 (for the middle button).
#
# Mouse.press?
# This returns a true/false value when you test whether a button is pressed
# and kept depressed. The values you pass are 1 (for the left mouse button),
# 2 (for the right mouse button), or 3 (for the middle).
#
# Mouse.pixels
# This returns the mouse's screen coordinates in pixels. Based on a screen
# with a 640x480 dimension, this returns an array of the mouse's position in
# index values. Calling Mouse.pixels returns both x & y positions in a sin-
# gle string, but calling Mouse.pixels[0] returns the x position (0-639) and
# calling Mouse.pixels[1] returns the y position (0-439). If the mouse is
# outside of the game's window region, this call returns nil.
#
# Mouse.tiles
# This returns the mouse's screen coordinates in map tiles. Based on the
# system's 20x15 tile size, this returns it in index values (a 0-19 width &
# a 0-14 height). This functions the same manner as Mouse.pixels.
#
# Mouse.set_pos
# This allows you to forcefully position the mouse at an x/y position within
# the game screen by pixel coordinates. Given the game's normal screen width
# of 640x480, adding: Mouse.set_pos(320,240) should position the mouse dead
# center of the gaming window.
#
# Mouse.update
# Add this routine into your update routines to update the mouse position.
# It must be called otherwise you won't get valid mouse coordinates.
#
#==============================================================================
module Mouse
@mouse_menu = 0
#--------------------------------------------------------------------------
# * Mouse Click
# button : button
#--------------------------------------------------------------------------
def Mouse.click?(button)
return true if @keys.include?(button)
return false
end
#--------------------------------------------------------------------------
# * Mouse Pressed
# button : button
#--------------------------------------------------------------------------
def Mouse.press?(button)
return true if @press.include?(button)
return false
end
#--------------------------------------------------------------------------
# * Mouse Pressed
# button : button
#--------------------------------------------------------------------------
def Mouse.area?(x, y, width=32, height=32)
return false if @pos == nil
return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
return false
end
#--------------------------------------------------------------------------
# * Mouse Pixel Position
#--------------------------------------------------------------------------
def Mouse.pixels
return @pos == nil ? [0, 0] : @pos
end
#--------------------------------------------------------------------------
# * Mouse Tile Position
#--------------------------------------------------------------------------
def Mouse.tiles
return nil if @pos == nil
x = @pos[0] / 32
y = @pos[1] / 32
return [x, y]
end
#--------------------------------------------------------------------------
# * Set Mouse Position
#--------------------------------------------------------------------------
def Mouse.set_pos(x_pos=0, y_pos=0)
width, height = Mouse.client_size
if (x_pos.between?(0, width) && y_pos.between?(0, height))
x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
end
end
#--------------------------------------------------------------------------
# * Mouse Update
#--------------------------------------------------------------------------
def Mouse.update
@pos = Mouse.pos
@keys, @press = [], []
@keys.push(1) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(1) & 0X01 == 1
@keys.push(2) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(2) & 0X01 == 1
@keys.push(3) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(4) & 0X01 == 1
@press.push(1) if Win32API.new("user32","GetKeyState",['i'],'i').call(1) & 0X01 == 1
@press.push(2) if Win32API.new("user32","GetKeyState",['i'],'i').call(2) & 0X01 == 1
@press.push(3) if Win32API.new("user32","GetKeyState",['i'],'i').call(4) & 0X01 == 1
end
#--------------------------------------------------------------------------
# * Automatic functions below
#--------------------------------------------------------------------------
#
#--------------------------------------------------------------------------
# * Obtain Mouse position in screen
#--------------------------------------------------------------------------
def Mouse.global_pos
pos = [0, 0].pack('ll')
if Win32API.new('user32', 'GetCursorPos', 'p', 'i').call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#--------------------------------------------------------------------------
# * Return Screen mouse position within game window
#--------------------------------------------------------------------------
def Mouse.pos
x, y = Mouse.screen_to_client(*Mouse.global_pos)
width, height = Mouse.client_size
begin
if (x >= 0 and y >= 0 and x < width and y < height)
return x, y
else
return nil
end
rescue
return nil
end
end
#--------------------------------------------------------------------------
# * Pass Screen to Game System
#--------------------------------------------------------------------------
def Mouse.screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if Win32API.new('user32', 'ScreenToClient', %w(l p), 'i').call(Mouse.hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#--------------------------------------------------------------------------
# * Get Screen Window Handle
#--------------------------------------------------------------------------
def Mouse.hwnd
game_name = "\0" * 256
Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l').call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
return Win32API.new('user32', 'FindWindowA', %w(p p), 'l').call('RGSS Player',game_name)
end
#--------------------------------------------------------------------------
# * Get Game Window Size
#--------------------------------------------------------------------------
def Mouse.client_size
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(Mouse.hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
#--------------------------------------------------------------------------
# * Get Window Position (RGSS Player)
#--------------------------------------------------------------------------
def Mouse.client_pos
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(Mouse.hwnd, rect)
left, upper = rect.unpack('l4')[0..1]
return left+4, upper+30
end
end
# ** Mouse Input Module (Revised)
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.2
# 08-18-2007
#------------------------------------------------------------------------------
# Based on...
# Mouse Input Module
# by Near Fantastica
#------------------------------------------------------------------------------
# Set_Pos feature by
# Freakboy
#------------------------------------------------------------------------------
#
# THE CALLS:
#
# Mouse.click?
# This returns a true/false value when you test whether a button is clicked.
# The values you pass are 1 (for the left mouse button), 2 (for the right) or
# 3 (for the middle button).
#
# Mouse.press?
# This returns a true/false value when you test whether a button is pressed
# and kept depressed. The values you pass are 1 (for the left mouse button),
# 2 (for the right mouse button), or 3 (for the middle).
#
# Mouse.pixels
# This returns the mouse's screen coordinates in pixels. Based on a screen
# with a 640x480 dimension, this returns an array of the mouse's position in
# index values. Calling Mouse.pixels returns both x & y positions in a sin-
# gle string, but calling Mouse.pixels[0] returns the x position (0-639) and
# calling Mouse.pixels[1] returns the y position (0-439). If the mouse is
# outside of the game's window region, this call returns nil.
#
# Mouse.tiles
# This returns the mouse's screen coordinates in map tiles. Based on the
# system's 20x15 tile size, this returns it in index values (a 0-19 width &
# a 0-14 height). This functions the same manner as Mouse.pixels.
#
# Mouse.set_pos
# This allows you to forcefully position the mouse at an x/y position within
# the game screen by pixel coordinates. Given the game's normal screen width
# of 640x480, adding: Mouse.set_pos(320,240) should position the mouse dead
# center of the gaming window.
#
# Mouse.update
# Add this routine into your update routines to update the mouse position.
# It must be called otherwise you won't get valid mouse coordinates.
#
#==============================================================================
module Mouse
@mouse_menu = 0
#--------------------------------------------------------------------------
# * Mouse Click
# button : button
#--------------------------------------------------------------------------
def Mouse.click?(button)
return true if @keys.include?(button)
return false
end
#--------------------------------------------------------------------------
# * Mouse Pressed
# button : button
#--------------------------------------------------------------------------
def Mouse.press?(button)
return true if @press.include?(button)
return false
end
#--------------------------------------------------------------------------
# * Mouse Pressed
# button : button
#--------------------------------------------------------------------------
def Mouse.area?(x, y, width=32, height=32)
return false if @pos == nil
return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
return false
end
#--------------------------------------------------------------------------
# * Mouse Pixel Position
#--------------------------------------------------------------------------
def Mouse.pixels
return @pos == nil ? [0, 0] : @pos
end
#--------------------------------------------------------------------------
# * Mouse Tile Position
#--------------------------------------------------------------------------
def Mouse.tiles
return nil if @pos == nil
x = @pos[0] / 32
y = @pos[1] / 32
return [x, y]
end
#--------------------------------------------------------------------------
# * Set Mouse Position
#--------------------------------------------------------------------------
def Mouse.set_pos(x_pos=0, y_pos=0)
width, height = Mouse.client_size
if (x_pos.between?(0, width) && y_pos.between?(0, height))
x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
end
end
#--------------------------------------------------------------------------
# * Mouse Update
#--------------------------------------------------------------------------
def Mouse.update
@pos = Mouse.pos
@keys, @press = [], []
@keys.push(1) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(1) & 0X01 == 1
@keys.push(2) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(2) & 0X01 == 1
@keys.push(3) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(4) & 0X01 == 1
@press.push(1) if Win32API.new("user32","GetKeyState",['i'],'i').call(1) & 0X01 == 1
@press.push(2) if Win32API.new("user32","GetKeyState",['i'],'i').call(2) & 0X01 == 1
@press.push(3) if Win32API.new("user32","GetKeyState",['i'],'i').call(4) & 0X01 == 1
end
#--------------------------------------------------------------------------
# * Automatic functions below
#--------------------------------------------------------------------------
#
#--------------------------------------------------------------------------
# * Obtain Mouse position in screen
#--------------------------------------------------------------------------
def Mouse.global_pos
pos = [0, 0].pack('ll')
if Win32API.new('user32', 'GetCursorPos', 'p', 'i').call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#--------------------------------------------------------------------------
# * Return Screen mouse position within game window
#--------------------------------------------------------------------------
def Mouse.pos
x, y = Mouse.screen_to_client(*Mouse.global_pos)
width, height = Mouse.client_size
begin
if (x >= 0 and y >= 0 and x < width and y < height)
return x, y
else
return nil
end
rescue
return nil
end
end
#--------------------------------------------------------------------------
# * Pass Screen to Game System
#--------------------------------------------------------------------------
def Mouse.screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if Win32API.new('user32', 'ScreenToClient', %w(l p), 'i').call(Mouse.hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#--------------------------------------------------------------------------
# * Get Screen Window Handle
#--------------------------------------------------------------------------
def Mouse.hwnd
game_name = "\0" * 256
Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l').call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
return Win32API.new('user32', 'FindWindowA', %w(p p), 'l').call('RGSS Player',game_name)
end
#--------------------------------------------------------------------------
# * Get Game Window Size
#--------------------------------------------------------------------------
def Mouse.client_size
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(Mouse.hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
#--------------------------------------------------------------------------
# * Get Window Position (RGSS Player)
#--------------------------------------------------------------------------
def Mouse.client_pos
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(Mouse.hwnd, rect)
left, upper = rect.unpack('l4')[0..1]
return left+4, upper+30
end
end
Simple Mouse System 1.5
CODE
#==============================================================================
# [VX] SMS - Simple Mouse System
#------------------------------------------------------------------------------
# ◦ by Woratana [woratana@hotmail.com]
# ◦ Released on: 14/04/2008 (D-M-Y)
# ◦ Version: 1.5
#
# ◦ Credit: DerVVulfman, Near Fantastica, and Freak Boy [Mouse Input Module]
# lambchop, shun, Cybersam, Astro_mech, and Mr.Mo [Super Simple Mouse System]
# - Modern Algebra, Zeriab, Patrick Lester [Path Finding]
# - Near Fantastica, Fuso [Path Finding]
#
# - I will not be able to script this without those people and scripts above
#-----------------------------------------------------------------------------
#====[REQUIRE]=====
# - DerVVulfman's Mouse Input Module
# - Modern Algebra's Path Finding [version 2.0]
#
#====[FEATURE]=====
# - Support to use mouse in many scenes / windows
# - Mouse Pointer
# - Click on map to move player with Path Finding
# - Click on event to go talk/interact with that event
# - Click on event to walk to that event
# - You can choose scene(s) that don't want to use mouse
# - You can turn mouse ON/OFF automatically by call script:
# $scene.no_mouse = (true/false) # True to turn off mouse
#====[MOUSE TAGS]=====
# Put one (or more) of these tags in the event command 'Comment..'
# [mauto] : This event will run automatically after click on it
# [mnone] : This event will not be determine as event when click on it
# (a.k.a. Player will not interact with it)
# [mtop] : Player will always stop at tile above this event when click on it
# [mleft] : Same as [mtop], but left side
# [mright] : Same as [mtop], but right side
# [mdown] : Same as [mtop], but below
#------------------------------------------------------------------------------
module Mouse
#==============================================================================
# MOUSE SETUP PART
#----------------------------------------------------------------------------
Scroll_Delay = 30 # (in Frames)
# Mouse Delay when scroll up or down the list
Path_Finding_Iteration = 0 # (Integer, 0 for no limit)
# How deep you want path finding to process until find the way
# less number will be able to find only easy path, less lag
# high number will be able to find complicated path, possible to increase lag
Scene_No_Mouse = []
# Scene(s) that you don't want to use mouse
# e.g. Scene_No_Mouse = [Scene_File, Scene_Map, Scene_Title]
Auto_Find_Destination = true
# It will automatically find the cloeset destination on map
# when click on unpassable tile.
#==============================================================================
end
#==============================================================================
# ** Mouse Input Module
#==============================================================================
class << Mouse
show_cursor = Win32API.new('user32', 'ShowCursor', 'l', 'l')
show_cursor.call(0)
$mousec = Sprite.new
$mousec.z = 10001
$mousec.x = $mousec.y = 1000
$mouse_icon = $base_cursor = 'sword_cursor'
$mousec.bitmap = Cache.system($base_cursor)
$mouse_duration = -1
$mouse_changed = false
alias wor_mouse_upd_mouse update unless $@
def Mouse.update
wor_mouse_upd_mouse
if $scene.no_mouse
$mousec.visible = false if $mousec.visible
return
else; $mousec.visible = true if !$mousec.visible
end
if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
$mouse_old_icon = $mouse_icon
$mousec.bitmap = Cache.system($mouse_old_icon)
end
if @pos.nil?
$mousec.x = 1000 if $mousec.x != 1000
$mousec.y = 1000 if $mousec.y != 1000
else
$mousec.x = @pos[0] if $mousec.x != @pos[0]
$mousec.y = @pos[1] if $mousec.y != @pos[1]
end
end
def Mouse.map_pos
return nil if @pos == nil
x = ($game_map.display_x / 256) + (@pos[0] / 32)
y = ($game_map.display_y / 256) + (@pos[1] / 32)
return [x, y]
end
end
#==============================================================================
# ** Input
#==============================================================================
class << Input
alias wor_input_upd_mouse update unless $@
alias wor_input_trig_mouse trigger? unless $@
alias wor_input_rep_mouse repeat? unless $@
def Input.update
wor_input_upd_mouse
Mouse.update
end
def Input.trigger?(input)
return wor_input_trig_mouse(input) if Mouse.pos.nil?
if input == Input::B and !$scene.no_mouse
return (wor_input_trig_mouse(input) or Mouse.click?(2))
elsif input == Input::C and !$scene.no_mouse
if $scene.is_a?(Scene_Map) and !$game_message.visible
return wor_input_trig_mouse(input)
else
return (wor_input_trig_mouse(input) or Mouse.click?(1))
end
else
return wor_input_trig_mouse(input)
end
end
def Input.repeat?(input)
if input == Input::B and !$scene.no_mouse
return (wor_input_rep_mouse(input) or Mouse.click?(2))
else
return wor_input_rep_mouse(input)
end
end
end
#==============================================================================
# ** Graphics
#==============================================================================
class << Graphics
alias wor_graph_fadeout_mouse fadeout unless $@
def Graphics.fadeout(frames = 1)
$mousec.visible = false if !$mousec.nil?
wor_graph_fadeout_mouse(frames)
end
end
#==============================================================================
# ** Window_Selectable
#==============================================================================
class Window_Selectable < Window_Base
alias wor_winsel_ini_mouse initialize
alias wor_winsel_upd_mouse update
def initialize(*args)
wor_winsel_ini_mouse(*args)
@scroll_wait = 0
@cursor_wait = 0
end
def update
wor_winsel_upd_mouse
update_mouse if self.active and self.visible
end
def update_mouse
@cursor_wait -= 1 if @cursor_wait > 0
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
move_cursor(i) if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
def move_cursor(index)
return if @index == index
@scroll_wait -= 1 if @scroll_wait > 0
row1 = @index / @column_max
row2 = index / @column_max
bottom = self.top_row + (self.page_row_max - 1)
if row1 == self.top_row and row2 < self.top_row
return if @scroll_wait > 0
@index = [@index - @column_max, 0].max
@scroll_wait = Mouse::Scroll_Delay
elsif row1 == bottom and row2 > bottom
return if @scroll_wait > 0
@index = [@index + @column_max, @item_max - 1].min
@scroll_wait = Mouse::Scroll_Delay
else
@index = index
end
return if @cursor_wait > 0
Sound.play_cursor
@cursor_wait += 2
end
end
#==============================================================================
# ** Window_MenuStatus
#==============================================================================
class Window_MenuStatus < Window_Selectable
def item_rect(index)
return Rect.new(0, index * 96, contents.width, 96)
end
end
#==============================================================================
# ** Window_NameInput
#==============================================================================
class Window_NameInput < Window_Base
alias wor_winnam_upd_mouse update
def update
wor_winnam_upd_mouse
if self.active and self.visible
(0..TABLE[@mode].size - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
@index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
end
#==============================================================================
# ** Window_PartyCommand
#==============================================================================
class Window_PartyCommand < Window_Command
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 16 + irect.x - self.ox
iry = 288 + 16 + irect.y - self.oy
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Window_ActorCommand
#==============================================================================
class Window_ActorCommand < Window_Command
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 288 + 16 + irect.x
iry = 288 + 16 + irect.y
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Window_Message
#==============================================================================
class Window_Message < Window_Selectable
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Scene_Base
#==============================================================================
class Scene_Base
alias wor_scebase_posstr_mouse post_start
alias wor_scebase_preter_mouse pre_terminate
attr_accessor :no_mouse
def post_start
if !$mousec.nil?
$mousec.visible = true
@no_mouse = false
# If this scene is in Scene_No_Mouse
Mouse::Scene_No_Mouse.each do |sce|
if $scene.is_a?(sce)
$mousec.visible = false
@no_mouse = true
end
end
end
wor_scebase_posstr_mouse
end
def pre_terminate
$mousec.visible = false if !$mousec.nil?
wor_scebase_preter_mouse
end
end
#==============================================================================
# ** Scene_File
#==============================================================================
class Scene_File < Scene_Base
alias wor_scefil_upd_mouse update
def update
(0..@item_max - 1).each do |i|
ix = @savefile_windows[i].x
iy = @savefile_windows[i].y
iw = @savefile_windows[i].width
ih = @savefile_windows[i].height
if Mouse.area?(ix, iy, iw, ih)
@savefile_windows[@index].selected = false
@savefile_windows[i].selected = true
@index = i
end
end
wor_scefil_upd_mouse
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
alias wor_scemap_upd_mouse update
def update
wor_scemap_upd_mouse
if !@no_mouse
# IF left click
if Mouse.click?(1) and !$game_message.visible and
!$game_map.interpreter.running?
mouse_xy = Mouse.map_pos
return if mouse_xy.nil?
old_direction = $game_player.direction
$game_player.turn_toward_pos(mouse_xy[0], mouse_xy[1])
# IF click near player, and there's trigger to event, run event
return if ($game_player.front?(mouse_xy[0],mouse_xy[1]) and
$game_player.check_action_event)
$game_player.clear_path
$game_player.mouse_force_path(mouse_xy[0], mouse_xy[1])
# IF middle click
elsif Mouse.click?(3) and !$game_message.visible and
!$game_map.interpreter.running?
mouse_xy = Mouse.map_pos
return if mouse_xy.nil?
$game_player.clear_path
$game_player.turn_toward_pos(mouse_xy[0], mouse_xy[1])
end
end
end
end
#==============================================================================
# ** Game_Character
#==============================================================================
class Game_Character
def mouse_force_path(x, y, auto_check = ($game_map.events_xy(x, y).size > 0))
ori_x, ori_y = x, y
path_xy = $game_map.find_dest_xy(x, y, @x, @y)
return if path_xy.nil?
x, y = path_xy[0] ,path_xy[1]
# Force_move from MA's path finding
if map_passable?(x,y)
path = $game_map.find_path (self.x, self.y, x, y, false,
Mouse::Path_Finding_Iteration, self)
path.reverse!
# Turn toward destination
newmove = RPG::MoveCommand.new
newmove.code = 45 # Script..
newmove.parameters = ["turn_toward_pos(#{ori_x},#{ori_y})"]
path.push newmove
# Add script to check if there's event trigger
if auto_check
newmove = RPG::MoveCommand.new
newmove.code = 45
newmove.parameters = ['check_action_event']
path.push newmove
end
# Add an end command
path.push (RPG::MoveCommand.new (0))
move_route = RPG::MoveRoute.new
move_route.list = path
move_route.repeat = false
force_move_route (move_route)
end
end
def clear_path
@move_route_index = 0
@move_route = RPG::MoveRoute.new
@move_route.repeat = false
end
def turn_toward_pos(x,y)
sx = distance_x_from_pos(x)
sy = distance_y_from_pos(y)
if sx.abs > sy.abs # Horizontal distance is longer
sx > 0 ? turn_left : turn_right
elsif sx.abs < sy.abs # Vertical distance is longer
sy > 0 ? turn_up : turn_down
end
end
def distance_x_from_pos(x)
sx = @x - x
if $game_map.loop_horizontal?
if sx.abs > $game_map.width / 2
sx -= $game_map.width
end
end
return sx
end
def distance_y_from_pos(y)
sy = @y - y
if $game_map.loop_vertical?
if sy.abs > $game_map.height / 2
sy -= $game_map.height
end
end
return sy
end
def front?(x,y)
case @direction
when 2; return true if (x == @x-1 and y == @y)
when 4; return true if (x == @x and y == @y-1)
when 6; return true if (x == @x and y == @y+1)
when 8; return true if (x == @x+1 and y == @y)
end
return false
end
end
#==============================================================================
# ** Game_Map
#==============================================================================
class Game_Map
# Find Destination for Path Finding
def find_dest_xy(x, y, self_x, self_y)
has_event = false
event_ary = events_xy(x, y)
# Remove Event that has 'mnone'
(event_ary).each do |i|
event_ary.delete(i) if i.comment?('[mnone]')
end
# Return original x, y if there are more than 1 events,
# or the only event has priority type 'Below Character'
if (event_ary.size == 1 and event_ary[0].priority_type != 1) or
event_ary.size > 1
return [x, y]
elsif event_ary.size == 1
# IF there's event, check for reserved direction
has_event = true
if event_ary[0].comment?('[mtop]')
return [x, y-1]
elsif event_ary[0].comment?('[mleft]')
return [x-1, y]
elsif event_ary[0].comment?('[mright]')
return [x+1, y]
elsif event_ary[0].comment?('[mdown]')
return [x, y+1]
elsif event_ary[0].comment?('[mauto]')
event_ary[0].start
return nil
end
end
# Check for passable direction or it's Same X/Y or doesn't allow auto-find
if (event_ary.size != 1 and $game_player.map_passable?(x, y)) or (self_x == x and self_y == y) or
(!Mouse::Auto_Find_Destination and !has_event)
return [x, y]
end
# Find nearest path
nx = (self_x - x)
ny = (self_y - y)
npath_real = []
if (nx.abs < ny.abs and nx != 0) or (ny == 0) # X is closer than Y
npath_real << (nx > 0 ? 'right' : 'left')
else # EQUAL, or Y is closer than X
npath_real << (ny > 0 ? 'up' : 'down')
end
npath_real_tran = move_translate(npath_real, x, y) # Translate word to value
# If the fastest way is possible, return it
if $game_player.map_passable?(npath_real_tran[0][0], npath_real_tran[0][1])
return [npath_real_tran[0][0], npath_real_tran[0][1]]
end
npath = []
# Add other possible ways
npath << 'up' if !npath_real.include?('up')
npath << 'left' if !npath_real.include?('left')
npath << 'down' if !npath_real.include?('down')
npath << 'right' if !npath_real.include?('right')
npath = move_translate(npath, x, y) # Translate other possible ways
(0..npath.size-1).each do |np| # Calculate distance from each point
npath[np] =
[npath[np], (self_x - npath[np][0]).abs + (self_y - npath[np][1]).abs]
end
npath = npath.sort_by {|i| i[1]} # Sort by Distance
# Check to move~
npath.each do |n|
return [n[0][0], n[0][1]] if $game_player.map_passable?(n[0][0], n[0][1])
end
# IF there's no way to go
return nil
end
def move_translate(ary, x, y)
(0..ary.size - 1).each do |n|
if ary[n] == 'up'
ary[n] = [x, y-1]
elsif ary[n] == 'left'
ary[n] = [x-1, y]
elsif ary[n] == 'right'
ary[n] = [x+1, y]
elsif ary[n] == 'down'
ary[n] = [x, y+1]
end
end
return ary
end
end
#==============================================================================
# ** Game_Event
#==============================================================================
class Game_Event < Game_Character
def comment?(comment, return_index = false )
if !@list.nil?
for i in 0...@list.size - 1
next if @list[i].code != 108
(0..@list[i].parameters.size - 1).each do |j|
if @list[i].parameters[j].include?(comment)
return [true, [i,j]] if return_index
return true
end
end
end
end
return [false, nil] if return_index
return false
end
end
# [VX] SMS - Simple Mouse System
#------------------------------------------------------------------------------
# ◦ by Woratana [woratana@hotmail.com]
# ◦ Released on: 14/04/2008 (D-M-Y)
# ◦ Version: 1.5
#
# ◦ Credit: DerVVulfman, Near Fantastica, and Freak Boy [Mouse Input Module]
# lambchop, shun, Cybersam, Astro_mech, and Mr.Mo [Super Simple Mouse System]
# - Modern Algebra, Zeriab, Patrick Lester [Path Finding]
# - Near Fantastica, Fuso [Path Finding]
#
# - I will not be able to script this without those people and scripts above
#-----------------------------------------------------------------------------
#====[REQUIRE]=====
# - DerVVulfman's Mouse Input Module
# - Modern Algebra's Path Finding [version 2.0]
#
#====[FEATURE]=====
# - Support to use mouse in many scenes / windows
# - Mouse Pointer
# - Click on map to move player with Path Finding
# - Click on event to go talk/interact with that event
# - Click on event to walk to that event
# - You can choose scene(s) that don't want to use mouse
# - You can turn mouse ON/OFF automatically by call script:
# $scene.no_mouse = (true/false) # True to turn off mouse
#====[MOUSE TAGS]=====
# Put one (or more) of these tags in the event command 'Comment..'
# [mauto] : This event will run automatically after click on it
# [mnone] : This event will not be determine as event when click on it
# (a.k.a. Player will not interact with it)
# [mtop] : Player will always stop at tile above this event when click on it
# [mleft] : Same as [mtop], but left side
# [mright] : Same as [mtop], but right side
# [mdown] : Same as [mtop], but below
#------------------------------------------------------------------------------
module Mouse
#==============================================================================
# MOUSE SETUP PART
#----------------------------------------------------------------------------
Scroll_Delay = 30 # (in Frames)
# Mouse Delay when scroll up or down the list
Path_Finding_Iteration = 0 # (Integer, 0 for no limit)
# How deep you want path finding to process until find the way
# less number will be able to find only easy path, less lag
# high number will be able to find complicated path, possible to increase lag
Scene_No_Mouse = []
# Scene(s) that you don't want to use mouse
# e.g. Scene_No_Mouse = [Scene_File, Scene_Map, Scene_Title]
Auto_Find_Destination = true
# It will automatically find the cloeset destination on map
# when click on unpassable tile.
#==============================================================================
end
#==============================================================================
# ** Mouse Input Module
#==============================================================================
class << Mouse
show_cursor = Win32API.new('user32', 'ShowCursor', 'l', 'l')
show_cursor.call(0)
$mousec = Sprite.new
$mousec.z = 10001
$mousec.x = $mousec.y = 1000
$mouse_icon = $base_cursor = 'sword_cursor'
$mousec.bitmap = Cache.system($base_cursor)
$mouse_duration = -1
$mouse_changed = false
alias wor_mouse_upd_mouse update unless $@
def Mouse.update
wor_mouse_upd_mouse
if $scene.no_mouse
$mousec.visible = false if $mousec.visible
return
else; $mousec.visible = true if !$mousec.visible
end
if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
$mouse_old_icon = $mouse_icon
$mousec.bitmap = Cache.system($mouse_old_icon)
end
if @pos.nil?
$mousec.x = 1000 if $mousec.x != 1000
$mousec.y = 1000 if $mousec.y != 1000
else
$mousec.x = @pos[0] if $mousec.x != @pos[0]
$mousec.y = @pos[1] if $mousec.y != @pos[1]
end
end
def Mouse.map_pos
return nil if @pos == nil
x = ($game_map.display_x / 256) + (@pos[0] / 32)
y = ($game_map.display_y / 256) + (@pos[1] / 32)
return [x, y]
end
end
#==============================================================================
# ** Input
#==============================================================================
class << Input
alias wor_input_upd_mouse update unless $@
alias wor_input_trig_mouse trigger? unless $@
alias wor_input_rep_mouse repeat? unless $@
def Input.update
wor_input_upd_mouse
Mouse.update
end
def Input.trigger?(input)
return wor_input_trig_mouse(input) if Mouse.pos.nil?
if input == Input::B and !$scene.no_mouse
return (wor_input_trig_mouse(input) or Mouse.click?(2))
elsif input == Input::C and !$scene.no_mouse
if $scene.is_a?(Scene_Map) and !$game_message.visible
return wor_input_trig_mouse(input)
else
return (wor_input_trig_mouse(input) or Mouse.click?(1))
end
else
return wor_input_trig_mouse(input)
end
end
def Input.repeat?(input)
if input == Input::B and !$scene.no_mouse
return (wor_input_rep_mouse(input) or Mouse.click?(2))
else
return wor_input_rep_mouse(input)
end
end
end
#==============================================================================
# ** Graphics
#==============================================================================
class << Graphics
alias wor_graph_fadeout_mouse fadeout unless $@
def Graphics.fadeout(frames = 1)
$mousec.visible = false if !$mousec.nil?
wor_graph_fadeout_mouse(frames)
end
end
#==============================================================================
# ** Window_Selectable
#==============================================================================
class Window_Selectable < Window_Base
alias wor_winsel_ini_mouse initialize
alias wor_winsel_upd_mouse update
def initialize(*args)
wor_winsel_ini_mouse(*args)
@scroll_wait = 0
@cursor_wait = 0
end
def update
wor_winsel_upd_mouse
update_mouse if self.active and self.visible
end
def update_mouse
@cursor_wait -= 1 if @cursor_wait > 0
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
move_cursor(i) if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
def move_cursor(index)
return if @index == index
@scroll_wait -= 1 if @scroll_wait > 0
row1 = @index / @column_max
row2 = index / @column_max
bottom = self.top_row + (self.page_row_max - 1)
if row1 == self.top_row and row2 < self.top_row
return if @scroll_wait > 0
@index = [@index - @column_max, 0].max
@scroll_wait = Mouse::Scroll_Delay
elsif row1 == bottom and row2 > bottom
return if @scroll_wait > 0
@index = [@index + @column_max, @item_max - 1].min
@scroll_wait = Mouse::Scroll_Delay
else
@index = index
end
return if @cursor_wait > 0
Sound.play_cursor
@cursor_wait += 2
end
end
#==============================================================================
# ** Window_MenuStatus
#==============================================================================
class Window_MenuStatus < Window_Selectable
def item_rect(index)
return Rect.new(0, index * 96, contents.width, 96)
end
end
#==============================================================================
# ** Window_NameInput
#==============================================================================
class Window_NameInput < Window_Base
alias wor_winnam_upd_mouse update
def update
wor_winnam_upd_mouse
if self.active and self.visible
(0..TABLE[@mode].size - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
@index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
end
#==============================================================================
# ** Window_PartyCommand
#==============================================================================
class Window_PartyCommand < Window_Command
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 16 + irect.x - self.ox
iry = 288 + 16 + irect.y - self.oy
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Window_ActorCommand
#==============================================================================
class Window_ActorCommand < Window_Command
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 288 + 16 + irect.x
iry = 288 + 16 + irect.y
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Window_Message
#==============================================================================
class Window_Message < Window_Selectable
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Scene_Base
#==============================================================================
class Scene_Base
alias wor_scebase_posstr_mouse post_start
alias wor_scebase_preter_mouse pre_terminate
attr_accessor :no_mouse
def post_start
if !$mousec.nil?
$mousec.visible = true
@no_mouse = false
# If this scene is in Scene_No_Mouse
Mouse::Scene_No_Mouse.each do |sce|
if $scene.is_a?(sce)
$mousec.visible = false
@no_mouse = true
end
end
end
wor_scebase_posstr_mouse
end
def pre_terminate
$mousec.visible = false if !$mousec.nil?
wor_scebase_preter_mouse
end
end
#==============================================================================
# ** Scene_File
#==============================================================================
class Scene_File < Scene_Base
alias wor_scefil_upd_mouse update
def update
(0..@item_max - 1).each do |i|
ix = @savefile_windows[i].x
iy = @savefile_windows[i].y
iw = @savefile_windows[i].width
ih = @savefile_windows[i].height
if Mouse.area?(ix, iy, iw, ih)
@savefile_windows[@index].selected = false
@savefile_windows[i].selected = true
@index = i
end
end
wor_scefil_upd_mouse
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
alias wor_scemap_upd_mouse update
def update
wor_scemap_upd_mouse
if !@no_mouse
# IF left click
if Mouse.click?(1) and !$game_message.visible and
!$game_map.interpreter.running?
mouse_xy = Mouse.map_pos
return if mouse_xy.nil?
old_direction = $game_player.direction
$game_player.turn_toward_pos(mouse_xy[0], mouse_xy[1])
# IF click near player, and there's trigger to event, run event
return if ($game_player.front?(mouse_xy[0],mouse_xy[1]) and
$game_player.check_action_event)
$game_player.clear_path
$game_player.mouse_force_path(mouse_xy[0], mouse_xy[1])
# IF middle click
elsif Mouse.click?(3) and !$game_message.visible and
!$game_map.interpreter.running?
mouse_xy = Mouse.map_pos
return if mouse_xy.nil?
$game_player.clear_path
$game_player.turn_toward_pos(mouse_xy[0], mouse_xy[1])
end
end
end
end
#==============================================================================
# ** Game_Character
#==============================================================================
class Game_Character
def mouse_force_path(x, y, auto_check = ($game_map.events_xy(x, y).size > 0))
ori_x, ori_y = x, y
path_xy = $game_map.find_dest_xy(x, y, @x, @y)
return if path_xy.nil?
x, y = path_xy[0] ,path_xy[1]
# Force_move from MA's path finding
if map_passable?(x,y)
path = $game_map.find_path (self.x, self.y, x, y, false,
Mouse::Path_Finding_Iteration, self)
path.reverse!
# Turn toward destination
newmove = RPG::MoveCommand.new
newmove.code = 45 # Script..
newmove.parameters = ["turn_toward_pos(#{ori_x},#{ori_y})"]
path.push newmove
# Add script to check if there's event trigger
if auto_check
newmove = RPG::MoveCommand.new
newmove.code = 45
newmove.parameters = ['check_action_event']
path.push newmove
end
# Add an end command
path.push (RPG::MoveCommand.new (0))
move_route = RPG::MoveRoute.new
move_route.list = path
move_route.repeat = false
force_move_route (move_route)
end
end
def clear_path
@move_route_index = 0
@move_route = RPG::MoveRoute.new
@move_route.repeat = false
end
def turn_toward_pos(x,y)
sx = distance_x_from_pos(x)
sy = distance_y_from_pos(y)
if sx.abs > sy.abs # Horizontal distance is longer
sx > 0 ? turn_left : turn_right
elsif sx.abs < sy.abs # Vertical distance is longer
sy > 0 ? turn_up : turn_down
end
end
def distance_x_from_pos(x)
sx = @x - x
if $game_map.loop_horizontal?
if sx.abs > $game_map.width / 2
sx -= $game_map.width
end
end
return sx
end
def distance_y_from_pos(y)
sy = @y - y
if $game_map.loop_vertical?
if sy.abs > $game_map.height / 2
sy -= $game_map.height
end
end
return sy
end
def front?(x,y)
case @direction
when 2; return true if (x == @x-1 and y == @y)
when 4; return true if (x == @x and y == @y-1)
when 6; return true if (x == @x and y == @y+1)
when 8; return true if (x == @x+1 and y == @y)
end
return false
end
end
#==============================================================================
# ** Game_Map
#==============================================================================
class Game_Map
# Find Destination for Path Finding
def find_dest_xy(x, y, self_x, self_y)
has_event = false
event_ary = events_xy(x, y)
# Remove Event that has 'mnone'
(event_ary).each do |i|
event_ary.delete(i) if i.comment?('[mnone]')
end
# Return original x, y if there are more than 1 events,
# or the only event has priority type 'Below Character'
if (event_ary.size == 1 and event_ary[0].priority_type != 1) or
event_ary.size > 1
return [x, y]
elsif event_ary.size == 1
# IF there's event, check for reserved direction
has_event = true
if event_ary[0].comment?('[mtop]')
return [x, y-1]
elsif event_ary[0].comment?('[mleft]')
return [x-1, y]
elsif event_ary[0].comment?('[mright]')
return [x+1, y]
elsif event_ary[0].comment?('[mdown]')
return [x, y+1]
elsif event_ary[0].comment?('[mauto]')
event_ary[0].start
return nil
end
end
# Check for passable direction or it's Same X/Y or doesn't allow auto-find
if (event_ary.size != 1 and $game_player.map_passable?(x, y)) or (self_x == x and self_y == y) or
(!Mouse::Auto_Find_Destination and !has_event)
return [x, y]
end
# Find nearest path
nx = (self_x - x)
ny = (self_y - y)
npath_real = []
if (nx.abs < ny.abs and nx != 0) or (ny == 0) # X is closer than Y
npath_real << (nx > 0 ? 'right' : 'left')
else # EQUAL, or Y is closer than X
npath_real << (ny > 0 ? 'up' : 'down')
end
npath_real_tran = move_translate(npath_real, x, y) # Translate word to value
# If the fastest way is possible, return it
if $game_player.map_passable?(npath_real_tran[0][0], npath_real_tran[0][1])
return [npath_real_tran[0][0], npath_real_tran[0][1]]
end
npath = []
# Add other possible ways
npath << 'up' if !npath_real.include?('up')
npath << 'left' if !npath_real.include?('left')
npath << 'down' if !npath_real.include?('down')
npath << 'right' if !npath_real.include?('right')
npath = move_translate(npath, x, y) # Translate other possible ways
(0..npath.size-1).each do |np| # Calculate distance from each point
npath[np] =
[npath[np], (self_x - npath[np][0]).abs + (self_y - npath[np][1]).abs]
end
npath = npath.sort_by {|i| i[1]} # Sort by Distance
# Check to move~
npath.each do |n|
return [n[0][0], n[0][1]] if $game_player.map_passable?(n[0][0], n[0][1])
end
# IF there's no way to go
return nil
end
def move_translate(ary, x, y)
(0..ary.size - 1).each do |n|
if ary[n] == 'up'
ary[n] = [x, y-1]
elsif ary[n] == 'left'
ary[n] = [x-1, y]
elsif ary[n] == 'right'
ary[n] = [x+1, y]
elsif ary[n] == 'down'
ary[n] = [x, y+1]
end
end
return ary
end
end
#==============================================================================
# ** Game_Event
#==============================================================================
class Game_Event < Game_Character
def comment?(comment, return_index = false )
if !@list.nil?
for i in 0...@list.size - 1
next if @list[i].code != 108
(0..@list[i].parameters.size - 1).each do |j|
if @list[i].parameters[j].include?(comment)
return [true, [i,j]] if return_index
return true
end
end
end
end
return [false, nil] if return_index
return false
end
end
the problem is ...



when ever i point to any choice , like : when i point to "Battle Animations" the choice go to "الركض المباشر" (another choice)