SMWma
18.01.2009, 19:13
Es gibt hier zwar eins, aber dies erfüllt das, wass ich will nicht 100%.
Es besitzt nähmlich ein Problem...
Nämlich benutze ich Karten, die größer als 20X15
Und dies ist das Problem:
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
Die vielen W´s ist die Karte.
Der bunte Berreich[Rot, Orange undGelb] ist die Sicht, die man gerade hat. Warum ich die jetzt bunt gemacht habe, weiß ich nicht mehr :eek:
Nun komm aber das besagte Problem.
Die obere und untere Karte ist die selbe.
Aber die Sicht ist jewals um ein W verschoben.
Trozdem haben die grüne und blaue W´s die gleichen Koordianten.
Und daher, wo man die Karte scrollen kann, kann ich dies nicht mit
Variable X => 123
Variable Y =< 185
bestimmen, sonst würde dies ja bei jeder Srollstellung gehen.
Genauer kann ich dies nicht erklären.
Das folgende Script soll so erweitert werden, dass die Koordianten sich nicht auf das Fenster sondern auf die Karte bestimmen:
#==============================================================================
#
# Mouse Script 1.0 created by: cybersam
# edited by: MagicMagor
#
#==============================================================================
#
# (got rid of cybersams explanation here, because it isn't true for this module)
# MagicMagor
#==============================================================================
#==============================================================================
# I have edited cybersams script, to fit my needs and my personal style of
# coding. I have also extended the script and got rid of several bugs.
# If you use this, give credit to cybersam and me.
#------------------------------------------------------------------------------
# MagicMagor
#==============================================================================
module Mouse
MOUSE_LEFT = 0x01 # left mouse button
MOUSE_RIGHT = 0x02 # right mouse button
attr_reader :MOUSE_LEFT, :MOUSE_RIGHT
# Flags
INIT_CURSOR = 0x01
INIT_SAVE = 0x02
INIT_TYPE = 0x03
CURSOR_PIC = 0x01
CURSOR_ROOT = 0x02
CURSOR_BITMAP = 0x03
attr_reader :INIT_CURSOR, :INIT_SAVE, :INIT_TYPE,
:CURSOR_PIC, :CURSOR_ROOT, :CURSOR_BITMAP
@getCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
@getWindowRect = Win32API.new('user32', 'GetWindowRect', ['p', 'p'], 'i')
@scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
@client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
@readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
@findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
@getKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
#---------------------------------------------------------------------------
# Initialize the mouse-system, with given arguments. Is automaticly called
# if needed.
#---------------------------------------------------------------------------
def Mouse.initSystem(*args)
@init = true
@handle = self.getHandle()
@cursor = Sprite.new()
if args.length >= 1
flags = args[0]
@showCursor = (flags & INIT_CURSOR)
@saveToGame = (flags & INIT_SAVE)
withType = (flags & INIT_TYPE)
if (@showCursor != 0)
@showCursor = true
else
@showCursor = false
end
if (@saveToGame != 0)
@saveToGame = true
else
@saveToGame = false
end
@cursor.visible = @showCursor
@originX = 0
@originY = 0
if (@saveToGame)
@gameX = args[-2]
@gameY = args[-1]
end
if (@showCursor)
if (withType)
self.setCursor(args[1], args[2])
else
self.setCursor(args[1])
end
end
end
return nil
end
#---------------------------------------------------------------------------
# Checks if key was pressed.
#---------------------------------------------------------------------------
def Mouse.pressed?(key)
return ((@getKeyState.call(key) & 0x01) == 1)
end
#---------------------------------------------------------------------------
# Returns true if saving mouse positions to game-variables is enabled
#---------------------------------------------------------------------------
def Mouse.saveToGame?()
if !(@init)
self.initSystem(nil)
end
return @saveToGame
end
#---------------------------------------------------------------------------
# Enables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.enableSaveToGame(game_x = nil, game_y = nil )
if !(@init)
self.initSystem(nil)
end
@saveToGame = true
if (game_x != nil)
@gameX = game_x
end
if (game_y != nil)
@gameY = game_y
end
return nil
end
#---------------------------------------------------------------------------
# Disables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.disableSaveToGame()
if !(@init)
self.initSystem(nil)
end
@saveToGame = false
return nil
end
#---------------------------------------------------------------------------
# Sets the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.setGameX(game_x)
if !(@init)
self.initSystem(nil)
end
@gameX = game_x
return nil
end
#---------------------------------------------------------------------------
# Sets the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.setGameY(game_y)
if !(@init)
self.initSystem(nil)
end
@gameY = game_y
return nil
end
#---------------------------------------------------------------------------
# Returns the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.gameX
return @gameX
end
#---------------------------------------------------------------------------
# Returns the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.gameY
return @gameY
end
#---------------------------------------------------------------------------
# Returns X-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.x()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return x
end
#---------------------------------------------------------------------------
# Returns Y-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.y()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return y
end
#---------------------------------------------------------------------------
# Returns TRUE when the mouse-cursor is shown.
#---------------------------------------------------------------------------
def Mouse.shown?()
if !(@init)
self.initSystem(nil)
end
return @showCursor
end
#---------------------------------------------------------------------------
# Enables showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.enableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = true
@cursor.visible = true
return nil
end
#---------------------------------------------------------------------------
# Disable showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.disableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = false
@cursor.visible = false
return nil
end
#---------------------------------------------------------------------------
# Sets a new bitmap for the cursor.
#---------------------------------------------------------------------------
def Mouse.setCursor(filename, type = CURSOR_PIC, originX = 0, originY = 0)
if !(@init)
self.initSystem(nil)
end
@originX = originX
@originY = originY
case type
when CURSOR_PIC
@cursor.bitmap = RPG::Cache.picture(filename)
@cursor.z = 999
return nil
when CURSOR_ROOT
@cursor.bitmap = Bitmap.new(filename)
@cursor.z = 999
return nil
when CURSOR_BITMAP
@cursor.bitmap = filename
@cursor.z = 999
return nil
end
end
#---------------------------------------------------------------------------
# Sets the x-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginX(originX)
if !(@init)
self.initSystem(nil)
end
@originX = originX
return nil
end
#---------------------------------------------------------------------------
# Sets the y-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginY(originY)
if !(@init)
self.initSystem(nil)
end
@originY = originY
return nil
end
#---------------------------------------------------------------------------
# Updates the position of the mouse-cursor on screen.
#---------------------------------------------------------------------------
def Mouse.update()
if !(@init)
self.initSystem(nil)
end
if (@showCursor)
if Mouse.x() != nil
@cursor.x = Mouse.x() - @originX
end
if Mouse.y() != nil
@cursor.y = Mouse.y() - @originY
end
end
if ((@saveToGame) && (@gameX != nil) && (@gameY != nil))
$game_variables[@gameX] = Mouse.x()
$game_variables[@gameY] = Mouse.y()
end
return nil
end
#===============================================================================
# Private methods start here
# Do not call them directly.
# Edit them only if you know what you are doing.
#===============================================================================
#---------------------------------------------------------------------------
# Calculates mouse position inside the programms window.
#---------------------------------------------------------------------------
def Mouse.mousePos(catch_anywhere = false)
x, y = Mouse.screenToClient(*Mouse.getPos)
width, height = Mouse.clientSize()
if ((x == nil) || (y == nil))
return nil
end
if ((catch_anywhere) || ((x >= 0) && (y >= 0) && (x < width) && (y < height)))
return x, y
else
return nil
end
end
#---------------------------------------------------------------------------
# Gets mouse position from OS.
#---------------------------------------------------------------------------
def Mouse.getPos()
if !(@init)
Mouse.initSystem(nil)
end
pos = [0, 0].pack('ll')
if @getCursorPos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#---------------------------------------------------------------------------
# Transforms screen-coordinates in client-coordinates.
#---------------------------------------------------------------------------
def Mouse.screenToClient(x, y)
if !(@init)
self.initSystem(nil)
end
return nil unless x and y
pos = [x, y].pack('ll')
if @scr2cli.call(@handle, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#---------------------------------------------------------------------------
# Gets the client size from OS.
#---------------------------------------------------------------------------
def Mouse.clientSize()
if !(@init)
self.initSystem(nil)
end
rect = [0, 0, 0, 0].pack('l4')
@client_rect.call(@handle, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
#---------------------------------------------------------------------------
# Gets the windows handle from OS.
#---------------------------------------------------------------------------
def Mouse.getHandle()
if !(@init)
self.initSystem(nil)
end
gameName = "\0" * 256
@readini.call('Game', 'Title', '', gameName, 255, ".\\Game.ini")
gameName.delete!("\0")
if ($DEBUG)
# Only one RGSS Player should be open
result = @findwindow.call('RGSS Player', 0)
else
result = @findwindow.call('RGSS Player', gameName)
end
return result
end
end
Ich will es einfach mit Copy + Paste durch das alte ersetzen wollen und nicht das halbe Spiel umprogranmmieren müssen.
Belohnung:
Held im Spiel >Noch geheim<*
Creditseintrag
Der Held wird als besonderer Einheit - wie in Stracraft Jim Raynor - gewertet.
Es besitzt nähmlich ein Problem...
Nämlich benutze ich Karten, die größer als 20X15
Und dies ist das Problem:
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
Die vielen W´s ist die Karte.
Der bunte Berreich[Rot, Orange undGelb] ist die Sicht, die man gerade hat. Warum ich die jetzt bunt gemacht habe, weiß ich nicht mehr :eek:
Nun komm aber das besagte Problem.
Die obere und untere Karte ist die selbe.
Aber die Sicht ist jewals um ein W verschoben.
Trozdem haben die grüne und blaue W´s die gleichen Koordianten.
Und daher, wo man die Karte scrollen kann, kann ich dies nicht mit
Variable X => 123
Variable Y =< 185
bestimmen, sonst würde dies ja bei jeder Srollstellung gehen.
Genauer kann ich dies nicht erklären.
Das folgende Script soll so erweitert werden, dass die Koordianten sich nicht auf das Fenster sondern auf die Karte bestimmen:
#==============================================================================
#
# Mouse Script 1.0 created by: cybersam
# edited by: MagicMagor
#
#==============================================================================
#
# (got rid of cybersams explanation here, because it isn't true for this module)
# MagicMagor
#==============================================================================
#==============================================================================
# I have edited cybersams script, to fit my needs and my personal style of
# coding. I have also extended the script and got rid of several bugs.
# If you use this, give credit to cybersam and me.
#------------------------------------------------------------------------------
# MagicMagor
#==============================================================================
module Mouse
MOUSE_LEFT = 0x01 # left mouse button
MOUSE_RIGHT = 0x02 # right mouse button
attr_reader :MOUSE_LEFT, :MOUSE_RIGHT
# Flags
INIT_CURSOR = 0x01
INIT_SAVE = 0x02
INIT_TYPE = 0x03
CURSOR_PIC = 0x01
CURSOR_ROOT = 0x02
CURSOR_BITMAP = 0x03
attr_reader :INIT_CURSOR, :INIT_SAVE, :INIT_TYPE,
:CURSOR_PIC, :CURSOR_ROOT, :CURSOR_BITMAP
@getCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
@getWindowRect = Win32API.new('user32', 'GetWindowRect', ['p', 'p'], 'i')
@scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
@client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
@readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
@findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
@getKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
#---------------------------------------------------------------------------
# Initialize the mouse-system, with given arguments. Is automaticly called
# if needed.
#---------------------------------------------------------------------------
def Mouse.initSystem(*args)
@init = true
@handle = self.getHandle()
@cursor = Sprite.new()
if args.length >= 1
flags = args[0]
@showCursor = (flags & INIT_CURSOR)
@saveToGame = (flags & INIT_SAVE)
withType = (flags & INIT_TYPE)
if (@showCursor != 0)
@showCursor = true
else
@showCursor = false
end
if (@saveToGame != 0)
@saveToGame = true
else
@saveToGame = false
end
@cursor.visible = @showCursor
@originX = 0
@originY = 0
if (@saveToGame)
@gameX = args[-2]
@gameY = args[-1]
end
if (@showCursor)
if (withType)
self.setCursor(args[1], args[2])
else
self.setCursor(args[1])
end
end
end
return nil
end
#---------------------------------------------------------------------------
# Checks if key was pressed.
#---------------------------------------------------------------------------
def Mouse.pressed?(key)
return ((@getKeyState.call(key) & 0x01) == 1)
end
#---------------------------------------------------------------------------
# Returns true if saving mouse positions to game-variables is enabled
#---------------------------------------------------------------------------
def Mouse.saveToGame?()
if !(@init)
self.initSystem(nil)
end
return @saveToGame
end
#---------------------------------------------------------------------------
# Enables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.enableSaveToGame(game_x = nil, game_y = nil )
if !(@init)
self.initSystem(nil)
end
@saveToGame = true
if (game_x != nil)
@gameX = game_x
end
if (game_y != nil)
@gameY = game_y
end
return nil
end
#---------------------------------------------------------------------------
# Disables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.disableSaveToGame()
if !(@init)
self.initSystem(nil)
end
@saveToGame = false
return nil
end
#---------------------------------------------------------------------------
# Sets the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.setGameX(game_x)
if !(@init)
self.initSystem(nil)
end
@gameX = game_x
return nil
end
#---------------------------------------------------------------------------
# Sets the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.setGameY(game_y)
if !(@init)
self.initSystem(nil)
end
@gameY = game_y
return nil
end
#---------------------------------------------------------------------------
# Returns the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.gameX
return @gameX
end
#---------------------------------------------------------------------------
# Returns the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.gameY
return @gameY
end
#---------------------------------------------------------------------------
# Returns X-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.x()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return x
end
#---------------------------------------------------------------------------
# Returns Y-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.y()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return y
end
#---------------------------------------------------------------------------
# Returns TRUE when the mouse-cursor is shown.
#---------------------------------------------------------------------------
def Mouse.shown?()
if !(@init)
self.initSystem(nil)
end
return @showCursor
end
#---------------------------------------------------------------------------
# Enables showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.enableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = true
@cursor.visible = true
return nil
end
#---------------------------------------------------------------------------
# Disable showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.disableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = false
@cursor.visible = false
return nil
end
#---------------------------------------------------------------------------
# Sets a new bitmap for the cursor.
#---------------------------------------------------------------------------
def Mouse.setCursor(filename, type = CURSOR_PIC, originX = 0, originY = 0)
if !(@init)
self.initSystem(nil)
end
@originX = originX
@originY = originY
case type
when CURSOR_PIC
@cursor.bitmap = RPG::Cache.picture(filename)
@cursor.z = 999
return nil
when CURSOR_ROOT
@cursor.bitmap = Bitmap.new(filename)
@cursor.z = 999
return nil
when CURSOR_BITMAP
@cursor.bitmap = filename
@cursor.z = 999
return nil
end
end
#---------------------------------------------------------------------------
# Sets the x-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginX(originX)
if !(@init)
self.initSystem(nil)
end
@originX = originX
return nil
end
#---------------------------------------------------------------------------
# Sets the y-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginY(originY)
if !(@init)
self.initSystem(nil)
end
@originY = originY
return nil
end
#---------------------------------------------------------------------------
# Updates the position of the mouse-cursor on screen.
#---------------------------------------------------------------------------
def Mouse.update()
if !(@init)
self.initSystem(nil)
end
if (@showCursor)
if Mouse.x() != nil
@cursor.x = Mouse.x() - @originX
end
if Mouse.y() != nil
@cursor.y = Mouse.y() - @originY
end
end
if ((@saveToGame) && (@gameX != nil) && (@gameY != nil))
$game_variables[@gameX] = Mouse.x()
$game_variables[@gameY] = Mouse.y()
end
return nil
end
#===============================================================================
# Private methods start here
# Do not call them directly.
# Edit them only if you know what you are doing.
#===============================================================================
#---------------------------------------------------------------------------
# Calculates mouse position inside the programms window.
#---------------------------------------------------------------------------
def Mouse.mousePos(catch_anywhere = false)
x, y = Mouse.screenToClient(*Mouse.getPos)
width, height = Mouse.clientSize()
if ((x == nil) || (y == nil))
return nil
end
if ((catch_anywhere) || ((x >= 0) && (y >= 0) && (x < width) && (y < height)))
return x, y
else
return nil
end
end
#---------------------------------------------------------------------------
# Gets mouse position from OS.
#---------------------------------------------------------------------------
def Mouse.getPos()
if !(@init)
Mouse.initSystem(nil)
end
pos = [0, 0].pack('ll')
if @getCursorPos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#---------------------------------------------------------------------------
# Transforms screen-coordinates in client-coordinates.
#---------------------------------------------------------------------------
def Mouse.screenToClient(x, y)
if !(@init)
self.initSystem(nil)
end
return nil unless x and y
pos = [x, y].pack('ll')
if @scr2cli.call(@handle, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#---------------------------------------------------------------------------
# Gets the client size from OS.
#---------------------------------------------------------------------------
def Mouse.clientSize()
if !(@init)
self.initSystem(nil)
end
rect = [0, 0, 0, 0].pack('l4')
@client_rect.call(@handle, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
#---------------------------------------------------------------------------
# Gets the windows handle from OS.
#---------------------------------------------------------------------------
def Mouse.getHandle()
if !(@init)
self.initSystem(nil)
end
gameName = "\0" * 256
@readini.call('Game', 'Title', '', gameName, 255, ".\\Game.ini")
gameName.delete!("\0")
if ($DEBUG)
# Only one RGSS Player should be open
result = @findwindow.call('RGSS Player', 0)
else
result = @findwindow.call('RGSS Player', gameName)
end
return result
end
end
Ich will es einfach mit Copy + Paste durch das alte ersetzen wollen und nicht das halbe Spiel umprogranmmieren müssen.
Belohnung:
Held im Spiel >Noch geheim<*
Creditseintrag
Der Held wird als besonderer Einheit - wie in Stracraft Jim Raynor - gewertet.