VX-Maus-Skript XP-kompatibel machen?
Hi.
ich habe hier ein Mausskript für den VX, welches ich gerne für den XP verwenden würde.
Gibt es da vielleicht eine Möglichkeit, es dementsprechend zu verändern, dass es auch mit dem XP läuft?
Hab von mehr als Copy & Paste leider keine Ahnung, wär also toll, wenn mir jemand helfen könnte^^
Hier ist das Simple Mouse System:
#==============================================================================
# [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 and interact
# - 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 = 'foxkeh_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.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
Die zwei Skripte werden auch noch benötigt:
#==============================================================================
# ** 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
#==============================================================================
# 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] >= @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
Gruß Sain
ich habe hier ein Mausskript für den VX, welches ich gerne für den XP verwenden würde.
Gibt es da vielleicht eine Möglichkeit, es dementsprechend zu verändern, dass es auch mit dem XP läuft?
Hab von mehr als Copy & Paste leider keine Ahnung, wär also toll, wenn mir jemand helfen könnte^^
Hier ist das Simple Mouse System:
#==============================================================================
# [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 and interact
# - 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 = 'foxkeh_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.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
zum Lesen den Text mit der Maus markieren
Die zwei Skripte werden auch noch benötigt:
#==============================================================================
# ** 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
zum Lesen den Text mit der Maus markieren
#==============================================================================
# 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] >= @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
zum Lesen den Text mit der Maus markieren
Gruß Sain
Benutzerinformationen überspringen
Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.
Hier, das Simple Mouse System
Bei jeder Scene musst du nun noch folgendes tun:
1. nach der Zeile class Scene_irgendwas "attr_accessor :no_mouse" einfügen (ohne die ")
2. Nach der Zeile def main das hier einfügen:
3. Suche das letzte "end" vor der Zeile "def update". VOR der Zeile fügst du
ein.
Dann müsstes eigentlich gehen
|
|
Ruby Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
#============================================================================== # [VX] SMS - Simple Mouse System #------------------------------------------------------------------------------ # ◦ by Woratana [[email]woratana@hotmail.com[/email]] # ◦ 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 and interact # - 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 = '001-Weapon01' $mousec.bitmap = RPG::Cache.icon($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 = RPG::Cache.icon($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 transition 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 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_File #============================================================================== class Scene_File alias wor_scefil_upd_mouse update def update (0..@item_max - 1).each do |i| ix = @savefile_windows.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 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 |
zum Lesen den Text mit der Maus markieren
Bei jeder Scene musst du nun noch folgendes tun:
1. nach der Zeile class Scene_irgendwas "attr_accessor :no_mouse" einfügen (ohne die ")
2. Nach der Zeile def main das hier einfügen:
|
|
Ruby Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
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 |
3. Suche das letzte "end" vor der Zeile "def update". VOR der Zeile fügst du
|
|
Ruby Quellcode |
1 |
$mousec.visible = false if !$mousec.nil? |
Dann müsstes eigentlich gehen
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Neo-Bahamut« (4. Januar 2009, 17:15)
Danke für deine Hilfe, allerdings befindet sich in dem Skript keine Zeile mit def main!
Wenn ich den Rest dementsprechend so verändere kommt bei mir die Fehlermeldung:
Script "Simple Mouse System" line 79: NoMethoderror occured. undefined method "no_mouse" for #<Scene_Title:0x15befb8>
Wenn man alle Skripte im Originalzustand belässt kommt stattdessen die Fehlermeldung:
Script "Simple Mouse System" line 74: NameError occured. uninitialized constant Module;:Cache
Wenn ich den Rest dementsprechend so verändere kommt bei mir die Fehlermeldung:
Script "Simple Mouse System" line 79: NoMethoderror occured. undefined method "no_mouse" for #<Scene_Title:0x15befb8>
Wenn man alle Skripte im Originalzustand belässt kommt stattdessen die Fehlermeldung:
Script "Simple Mouse System" line 74: NameError occured. uninitialized constant Module;:Cache
Benutzerinformationen überspringen
Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.
Ich sagt "bei jeder Scene"
Also Scene_Title, Scene_Map, Scene_Battle, Scene_Shop, Scene_Name und die anderen fallen mir grad nicht ein^^
Also Scene_Title, Scene_Map, Scene_Battle, Scene_Shop, Scene_Name und die anderen fallen mir grad nicht ein^^
Ah, so war das gemeint, mein Fehler^^
Hab jetzt bei allen Scene-Skripten die entsprechenden Zeilen ergänzt und das
neue Maus-Skript eingefügt! Dennoch kommt noch immer die Fehlermeldung:
Script 'Simple Mouse System' line 88: NameError occurred
uninitalized constant module::Cache
Die betroffene Zeile sieht so aus:
"$mousec.bitmap = Cache.system($mouse_old_icon)"
Hab jetzt bei allen Scene-Skripten die entsprechenden Zeilen ergänzt und das
neue Maus-Skript eingefügt! Dennoch kommt noch immer die Fehlermeldung:
Script 'Simple Mouse System' line 88: NameError occurred
uninitalized constant module::Cache
Die betroffene Zeile sieht so aus:
"$mousec.bitmap = Cache.system($mouse_old_icon)"
Benutzerinformationen überspringen
Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.
Okay, hab ich oben editiert =)
Benutzerinformationen überspringen
Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.
Komisch, das kommt nur beim XP? Ich hatte diesen Fehler auch gar nicht^^
Na egal, ein paar Zeilen dadrunter lösch diese Zeilen:
bzw. ich änder es oben auch mal^^
Na egal, ein paar Zeilen dadrunter lösch diese Zeilen:
|
|
Ruby Quellcode |
1 2 3 4 5 |
end #============================================================================== # ** Window_MenuStatus #============================================================================== class Window_MenuStatus < Window_Selectable |
bzw. ich änder es oben auch mal^^
Beim VX klappts zumindest einwandfrei, keine Ahnung worans genau liegt.
Inzwischen lässt sich das Testspiel zwar starten, sobald ich danach
allerdings mit meiner Maus übers Spielfenster gehe, erscheint die Meldung:
Script 'Simple Mouse System' line 124: NoMethodError occurred
undefined method 'visible' for nil:NilClass
line 124 = if $scene.is_a?(Scene_Map) and !$game_message.visible
Im Titelmenü funktioniert die Maus jedoch noch einwandfrei!
Inzwischen lässt sich das Testspiel zwar starten, sobald ich danach
allerdings mit meiner Maus übers Spielfenster gehe, erscheint die Meldung:
Script 'Simple Mouse System' line 124: NoMethodError occurred
undefined method 'visible' for nil:NilClass
line 124 = if $scene.is_a?(Scene_Map) and !$game_message.visible
Im Titelmenü funktioniert die Maus jedoch noch einwandfrei!
Benutzerinformationen überspringen
Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.
Hm, probiers so nochmal^^
Übrigens, ich hab kurz was geschrieben. Scene_s brauchst du nun nicht mehr zu editieren, einfach diesen Code über Main einfügen (mehrmals) und imm die passende Scene_ hinschreiben
|
|
Ruby Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
#============================================================================== # [VX] SMS - Simple Mouse System #------------------------------------------------------------------------------ # ◦ by Woratana [[email]woratana@hotmail.com[/email]] # ◦ 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 and interact # - 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 = '001-Weapon01' $mousec.bitmap = RPG::Cache.icon($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 = RPG::Cache.icon($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 != nil 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 transition 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 $game_system.se_play($data_system.cursor_se) @cursor_wait += 2 end 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_Selectable def update_mouse (0..@item_max - 1).each do |i| irect = item_rect(i) irx = self.x + 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_File #============================================================================== class Scene_File alias wor_scefil_upd_mouse update def update (0..@item_max - 1).each do |i| ix = @savefile_windows.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 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 != nil 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 |
zum Lesen den Text mit der Maus markieren
Übrigens, ich hab kurz was geschrieben. Scene_s brauchst du nun nicht mehr zu editieren, einfach diesen Code über Main einfügen (mehrmals) und imm die passende Scene_ hinschreiben
|
|
Ruby Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
class Scene_Map attr_accessor :no_mouse alias old_simple_mouse_system_vx_main main def main 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 old_simple_mouse_system_vx_main $mousec.visible = false if !$mousec.nil? end end |
Prima, danke dir^^
Jetzt wird der Zeiger immerhin schon fehlerfrei angezeigt und die Maustasten funktionieren auch so weit! Kann, es sein, dass an den anderen beiden Skripten, die auch benötigt werden, noch etwas geändert werden muss?
Denn das Pathfinding klappt nicht, bzw wenn ich irgendwo in die Gegend klicke, dann bewegt sich mein Held nicht. Und bei dem Versuch, ein Event anzusprechen, welches eine Auswahl ausgibt, stürzt das Spiel mit dieser Meldung ab:
"Script 'Simple Mouse System' line 256: NoMethodError occurred
undefined method 'choice_start' for nil:NilClass"
line 256= iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
Jetzt wird der Zeiger immerhin schon fehlerfrei angezeigt und die Maustasten funktionieren auch so weit! Kann, es sein, dass an den anderen beiden Skripten, die auch benötigt werden, noch etwas geändert werden muss?
Denn das Pathfinding klappt nicht, bzw wenn ich irgendwo in die Gegend klicke, dann bewegt sich mein Held nicht. Und bei dem Versuch, ein Event anzusprechen, welches eine Auswahl ausgibt, stürzt das Spiel mit dieser Meldung ab:
"Script 'Simple Mouse System' line 256: NoMethodError occurred
undefined method 'choice_start' for nil:NilClass"
line 256= iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
Benutzerinformationen überspringen
Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.
Hm, das Pathfinding weiß ich nicht. Sollte eigentlich klappen :-/
Ich arbeite auch normalerweise mit RGSS, nicht mit RGSS2.
Überall, wo
steht und du einen Fehler kriegst, ersetz das mit
Ich arbeite auch normalerweise mit RGSS, nicht mit RGSS2.
Überall, wo
|
|
Ruby Quellcode |
1 |
$game_message |
|
|
Ruby Quellcode |
1 |
$game_temp |
Ähnliche Themen
-
Kampfsysteme »-
Gothik 3 - Absturzskript V1
(8. Juli 2008, 19:00)
-
RGSS 1 Probleme & Talk »-
Problem mit 2 Scripten
(17. Mai 2007, 21:09)
-
Kampfsysteme »-
Item Shortcut V1
(30. Juli 2006, 15:40)
-
RGSS Archiv »-
Maus Skript?
(10. April 2005, 17:49)
-
RGSS Archiv »-
Mausscript.
(19. Dezember 2004, 20:25)

