9
23
2010
1

RM通用:搞瞎你的眼睛

是的,乃没看错,这个脚本是用来搞瞎你的眼睛的,加入任意工程执行即可。

 

def calc(x,y)
  a = 0
  a += 2 if 3 * x + 8 * y > 3600
  a += 1 if 3 * x - 2 * y > 600
  case a
  when 0
    return 7 if 3 * x - 8 * y > -1200
    return 4
  when 3
    return 6 if 3 * x - 8 * y > -1200
    return 3
  when 1
    return 9 if 3 * x + 2 * y > 1800
    return 8
  when 2
    return 2 if 3 * x + 2 * y > 1800
    return 1
  end
end

h = {
1 => Color.new(255,0,0),
2 => Color.new(0,255,0),
3 => Color.new(0,0,255),
4 => Color.new(255,255,0),
6 => Color.new(255,0,255),
7 => Color.new(255,255,255),
8 => Color.new(0,255,255),
9 => Color.new(0,0,0)
}
Graphics.frame_rate = 120
s = Sprite.new
s.bitmap = Bitmap.new(640,480)
for i in 0..640
  for j in 0..480
    c = h[calc(i,j)]
    c.alpha = 255 - (i - 400).abs * (j - 300).abs * 255 / (200 * 480)
    s.bitmap.set_pixel(i,j,c)
  end
    Graphics.update
end  
s.ox = s.x = 320
s.oy = s.y = 240
loop do
  for i in 0..20
    s.zoom_x += 0.1
    s.zoom_y += 0.02
    s.opacity -= 10
    Graphics.update
  end
  for i in 0..20
    s.zoom_x -= 0.1
    s.zoom_y -= 0.02
    s.opacity += 10
    Graphics.update
  end
end
exit
Category: RM | Tags: XP VX
9
23
2010
2

RM通用:鼠标定位脚本。

这个脚本用于随时按下Shift定位鼠标位置。

 

module Stop
  @@bitmap = Bitmap.new(640 * 2 + 1,480 * 2 + 1)
  @@bitmap.fill_rect(640,0,1,960,Color.new(255,0,0))
  @@bitmap.fill_rect(0,480,1280,1,Color.new(255,0,0))
  @@viewport = Viewport.new(0,0,640,480)
  @@viewport.z = 2000
  @@sprite = Sprite.new(@@viewport)
  @@sprite.bitmap = @@bitmap
  @@sprite.visible = false
  @@help_bitmap = Bitmap.new(200,48)
  @@help_bitmap.font.color = Color.new(255,255,0)
  @@help_sprite = Sprite.new(@@viewport)
  @@help_sprite.bitmap = @@help_bitmap
  @@help_sprite.visible = false
  def self.main
    @@sprite.visible = true
    @@help_sprite.visible = true
    @@sprite.x = -320
    @@sprite.y = -240
    begin
      Graphics.update
      Mouse.update
      a = Mouse.pixels
      @@sprite.x = a[0] - 640
      @@sprite.y = a[1] - 480
      @@help_bitmap.clear
      @@help_bitmap.draw_text(0,0,200,48,"[#{a[0].to_s},#{a[1].to_s}]")
    end until Mouse.press?(3) or Mouse.press?(2) or Mouse.press?(1)
    @@sprite.visible = false 
    @@help_sprite.visible = false
  end
end

class <<Input
  alias stop_update_add update unless method_defined?("stop_update_add")
  def update
    stop_update_add
    if Input.trigger?(Input::SHIFT)
      Stop.main
    end
  end
end

需要一个鼠标脚本。如下:

 

#==============================================================================
# ** 鼠标输入模块
#------------------------------------------------------------------------------
#   微调 by zh99998
#   版本 1.2a
#   06-30-2010
#   修复press判定
#   基于沉影的鼠标系统修改版alpha
#------------------------------------------------------------------------------
#   by DerVVulfman
#   版本 1.2
#   08-18-2007
#------------------------------------------------------------------------------
#   建立在鼠标输入模块...
#
#   by Near Fantastica
#------------------------------------------------------------------------------
#   Set_Pos feature by
#   Freakboy
#------------------------------------------------------------------------------
#
#   CALLS: 
#
#   Mouse.click?
#   判断鼠标是否真的按下(Ture/False).
#   这个值控制您按下的是左/右键,还是中键

#
#   Mouse.press?
#   判断鼠标是否真的按下/保持按下状态
#   这个值控制您按下的是左/右键,还是中键
#   Mouse.pixels
#   Mouse.pixels
#   这个值返回鼠标所在的坐标(640*480大小),如果鼠标超出游戏画面,这个值为空
#
#   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
  #--------------------------------------------------------------------------
  # ## 常量
  #--------------------------------------------------------------------------
  GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  GetKeyState = Win32API.new("user32","GetKeyState",['i'],'i')
  
  ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
  
  GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
  
  #--------------------------------------------------------------------------
  # * Mouse Click
  #     button      : button
  #--------------------------------------------------------------------------
  def Mouse.click?(button)
    return false if button == 1 and !$click_abled
    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 GetAsyncKeyState.call(1) & 0X01 == 1
    @keys.push(2)   if GetAsyncKeyState.call(2) & 0X01 == 1
    @keys.push(3)   if GetAsyncKeyState.call(4) & 0X01 == 1
    @press.push(1)  if GetKeyState.call(1) > 1
    @press.push(2)  if GetKeyState.call(2) > 1
    @press.push(3)  if GetKeyState.call(4) > 1
    ## 鼠标双击
    @wait ||= 0
    @wait += 1 if @key != nil
    (@key = nil; @wait = 0) if @wait > 30 # 双击时间
  end  
  #--------------------------------------------------------------------------
  # * Automatic functions below 
  #--------------------------------------------------------------------------
  #
  #--------------------------------------------------------------------------
  # * Obtain Mouse position in screen
  #--------------------------------------------------------------------------
  def Mouse.global_pos
    pos = [0, 0].pack('ll')
    if GetCursorPos.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 ScreenToClient.call(HWND, pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #--------------------------------------------------------------------------
  # * Get Game Window Size
  #--------------------------------------------------------------------------
  def Mouse.client_size
    rect = [0, 0, 0, 0].pack('l4')
    GetClientRect.call(HWND, rect)
    right, bottom = rect.unpack('l4')[2..3]
    return right, bottom
  end
  #--------------------------------------------------------------------------
  # * Get Window Position
  #--------------------------------------------------------------------------
  def Mouse.client_pos
    rect = [0, 0, 0, 0].pack('l4')
    ## 用户区
    GetClientRect.call(HWND, rect)
    left, upper = rect.unpack('l4')[0..1]
    return left, upper
  end
  #--------------------------------------------------------------------------
  # ## 句柄
  #--------------------------------------------------------------------------
  def Mouse.get_hwnd
    game_name = "\0" * 256
    Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l').call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return Win32API.new('user32', 'FindWindowA', 'pp', 'l').call('RGSS Player',game_name)
  end
  #--------------------------------------------------------------------------
  # ## 双击
  #--------------------------------------------------------------------------
  def self.double_click?(key)
    if @keys.include?(key)
      @key !=key ? (@key = key; return false) : (@key = nil; return true)
    end
  end
  ## 句柄常量
  HWND = Mouse.get_hwnd
  
  ###############
  GetMessage = Win32API.new('user32','GetMessage','plll','l')
  
  Point = Struct.new(:x, :y)
  Message = Struct.new(:message, :wparam, :lparam, :pt)
  Param = Struct.new(:x, :y, :scroll)
  
  def self.scroll
    msg = "\0"*32
    GetMessage.call(msg,0,0,0)
    r = wmcallback(unpack_msg(msg))
    return r unless r.nil?
  end
  
  def wmcallback(msg)
    return unless msg.message == Scroll
    param = Param.new
    param.x = word2signed_short(loword(msg.lparam))
    param.y = word2signed_short(hiword(msg.lparam))
    param.scroll = word2signed_short(hiword(msg.wparam))
    return [param.x,param.y,param.scroll]
  end
  
  def hiword(dword)
    ###return ((dword&0xffff0000)>>16)&0x0000ffff
    return (dword & 0xffff0000) / 0x10000
  end
  
  def loword(dword)
    return dword&0x0000ffff
  end
end
Category: RM | Tags: VX XP
6
26
2010
69

RMXP:地图链接重置

这个脚本用于自动重建RMXP地图链表。

 

data = load_data("Data/MapInfos.rxdata")
files = Dir["Data/Map???.r?data"]
names = []
for i in data.keys
  names.push sprintf("Data/Map%03d.rxdata",i)
end
files -= names
for i in files
  i.gsub!(/Data\/Map(.+?).rxdata/) { "" }
  id = $1.to_i
  data[id] = RPG::MapInfo.new
  data[id].name = sprintf("地图 %03d",id)
end
save_data(data,"Data/MapInfos.rxdata")
Category: RM | Tags: XP

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com