设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1446|回复: 0
打印 上一主题 下一主题

[已经解决] 求大神解答关于鼠标脚本的问题,灰常急~

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
49 小时
注册时间
2013-5-3
帖子
18
跳转到指定楼层
1
发表于 2013-6-22 19:16:50 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
我添加了鼠标响应的脚本,可以实现。不需要人物跟着鼠标移动也纠正了。
可是有些地图里我不需要鼠标,希望鼠标可以消失并无效掉。这样可以实现吗???
RUBY 代码复制
  1. #==============================================================================
  2. # ■ 完整鼠标系统(四方向)
  3. #------------------------------------------------------------------------------
  4. #   By whbm
  5. #==============================================================================
  6. #
  7. #   ■本脚本已由Defanive修改,适合于魔塔样板3224
  8. #
  9. #   修改后:
  10. #   删除鼠标控制角色移动以及自动寻路,防止作弊
  11. #   删除点击开启事件,防止作弊
  12. #
  13. #==============================================================================
  14.  
  15. #==============================================================================
  16. # ● API调用
  17. #==============================================================================
  18. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  19. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  20. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  21. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  22. $Window_HWND = $GetActiveWindow.call
  23. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  24. module Mouse  
  25. LEFT = 0x01
  26. RIGHT = 0x02
  27.  
  28. def self.init(sprite = nil)
  29.    $ShowCursor.call(0)
  30.  
  31.    @show_cursor = false
  32.  
  33.    @mouse_sprite = Sprite.new
  34.    @mouse_sprite.z = 99999
  35.    @mouse_sprite.bitmap = Bitmap.new("Graphics/Icons/003-Weapon03")
  36.  
  37.    @left_press = false
  38.    @right_press = false
  39.    @left_trigger = false
  40.    @right_trigger = false
  41.    @left_repeat = false
  42.    @right_repeat = false
  43.    @click_lock = false
  44.  
  45.    update
  46. end
  47. def self.exit
  48.    @mouse_sprite.bitmap.dispose
  49.    @mouse_sprite.dispose
  50.    @show_cursor = true
  51.    $ShowCursor.call(1)
  52. end
  53. def self.mouse_debug
  54.    return @mouse_debug.bitmap
  55. end
  56. def self.update
  57.    left_down = $GetKeyState.call(0x01)
  58.    right_down = $GetKeyState.call(0x02)
  59.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  60.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  61.      @a = !@a
  62.    end
  63.    @click_lock = false
  64.    mouse_x, mouse_y = self.get_mouse_pos
  65.    if @mouse_sprite != nil
  66.      @mouse_sprite.x = mouse_x
  67.      @mouse_sprite.y = mouse_y
  68.    end
  69.    if left_down[7] == 1
  70.      @left_repeat = (not @left_repeat)
  71.      @left_trigger = (not @left_press)
  72.      @left_press = true
  73.    else
  74.      @left_press = false
  75.      @left_trigger = false
  76.      @left_repeat = false
  77.    end
  78.    if right_down[7] == 1
  79.      @right_repeat = (not @right_repeat)
  80.      @right_trigger = (not @right_press)
  81.      @right_press = true
  82.    else
  83.      @right_press = false
  84.      @right_trigger = false
  85.      @right_repeat = false
  86.    end
  87. end
  88. def self.get_mouse_pos
  89.    point_var = [0, 0].pack('ll')
  90.    if $GetCursorPos.call(point_var) != 0
  91.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  92.        x, y = point_var.unpack('ll')
  93.        if (x < 0) or (x > 10000) then x = 0 end
  94.        if (y < 0) or (y > 10000) then y = 0 end
  95.        if x > 640 then x = 640 end
  96.        if y > 480 then y = 480 end
  97.        return x, y
  98.      else
  99.        return 0, 0
  100.      end
  101.    else
  102.      return 0, 0
  103.    end
  104. end
  105. def self.press?(mouse_code)
  106.    if mouse_code == LEFT
  107.      if @click_lock
  108.        return false
  109.      else
  110.        return @left_press
  111.      end
  112.    elsif mouse_code == RIGHT
  113.      return @right_press
  114.    else
  115.      return false
  116.    end
  117. end
  118. def self.trigger?(mouse_code)
  119.    if mouse_code == LEFT
  120.      if @click_lock
  121.        return false
  122.      else
  123.        return @left_trigger
  124.      end
  125.    elsif mouse_code == RIGHT
  126.      return @right_trigger
  127.    else
  128.      return false
  129.    end
  130. end
  131. def self.repeat?(mouse_code)
  132.    if mouse_code == LEFT
  133.      if @click_lock
  134.        return false
  135.      else
  136.        return @left_repeat
  137.      end
  138.    elsif mouse_code == RIGHT
  139.      return @right_repeat
  140.    else
  141.      return false
  142.    end
  143. end
  144. def self.click_lock?
  145.    return @click_lock
  146. end
  147. def self.click_lock
  148.    @click_lock = true
  149. end
  150. def self.click_unlock
  151.    @click_lock = false
  152. end
  153. end
  154. module Input
  155. if @self_update == nil
  156.    @self_update = method('update')
  157.    @self_press = method('press?')
  158.    @self_trigger = method('trigger?')
  159.    @self_repeat = method('repeat?')
  160. end
  161. def self.update
  162.    @self_update.call
  163.    Mouse.update
  164. end
  165. def self.press?(key_code)
  166.    if @self_press.call(key_code)
  167.      return true
  168.    end
  169.    if key_code == C
  170.      return Mouse.press?(Mouse::LEFT)
  171.    elsif key_code == B
  172.      return Mouse.press?(Mouse::RIGHT)
  173.    else
  174.      return @self_press.call(key_code)
  175.    end
  176. end
  177. def self.trigger?(key_code)
  178.    if @self_trigger.call(key_code)
  179.      return true
  180.    end
  181.    if key_code == C
  182.      return Mouse.trigger?(Mouse::LEFT)
  183.    elsif key_code == B
  184.      return Mouse.trigger?(Mouse::RIGHT)
  185.    else
  186.      return @self_trigger.call(key_code)
  187.    end
  188. end
  189. def self.repeat?(key_code)
  190.    if @self_repeat.call(key_code)
  191.      return true
  192.    end
  193.    if key_code == C
  194.      return Mouse.repeat?(Mouse::LEFT)
  195.    elsif key_code == B
  196.      return Mouse.repeat?(Mouse::RIGHT)
  197.    else
  198.      return @self_repeat.call(key_code)
  199.    end
  200. end
  201. end
  202. class Window_Selectable
  203. if @self_alias == nil
  204.    alias self_update update
  205.    @self_alias = true
  206. end
  207. def update
  208.    self_update
  209.    if self.active and @item_max > 0
  210.      index_var = @index
  211.      tp_index = @index
  212.      mouse_x, mouse_y = Mouse.get_mouse_pos
  213.      mouse_not_in_rect = true
  214.      for i in 0...@item_max
  215.        @index = i
  216.        update_cursor_rect
  217.        top_x = self.cursor_rect.x + self.x + 16
  218.        top_y = self.cursor_rect.y + self.y + 16
  219.        bottom_x = top_x + self.cursor_rect.width
  220.        bottom_y = top_y + self.cursor_rect.height
  221.        if (mouse_x > top_x) and (mouse_y > top_y) and
  222.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  223.          mouse_not_in_rect = false
  224.          if tp_index != @index
  225.            tp_index = @index
  226.            $game_system.se_play($data_system.cursor_se)
  227.          end
  228.          break
  229.        end
  230.      end
  231.      if mouse_not_in_rect
  232.        @index = index_var
  233.        update_cursor_rect
  234.        Mouse.click_lock
  235.      else
  236.        Mouse.click_unlock               
  237.      end
  238.    end
  239. end
  240. end
  241. class Window_NameInput
  242. if @self_alias == nil
  243.    alias self_update update
  244.    @self_alias = true
  245. end
  246. def update
  247.    self_update
  248.    if self.active
  249.      index_var = @index
  250.      mouse_x, mouse_y = Mouse.get_mouse_pos
  251.      mouse_not_in_rect = true
  252.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  253.        @index = i
  254.        update_cursor_rect
  255.        top_x = self.cursor_rect.x + self.x + 16
  256.        top_y = self.cursor_rect.y + self.y + 16
  257.        bottom_x = top_x + self.cursor_rect.width
  258.        bottom_y = top_y + self.cursor_rect.height
  259.        if (mouse_x > top_x) and (mouse_y > top_y) and
  260.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  261.          mouse_not_in_rect = false
  262.          break
  263.        end
  264.      end
  265.      if mouse_not_in_rect
  266.        @index = index_var
  267.        update_cursor_rect
  268.        Mouse.click_lock
  269.      else
  270.        Mouse.click_unlock
  271.      end
  272.    end
  273. end
  274. end
  275. class Window_InputNumber
  276. if @self_alias == nil
  277.    alias self_update update
  278.    @self_alias = true
  279. end
  280. def update
  281.    self_update
  282.    mouse_x, mouse_y = Mouse.get_mouse_pos
  283.    if self.active and @digits_max > 0
  284.      index_var = @index
  285.      mouse_not_in_rect = true
  286.      for i in 0...@digits_max
  287.        @index = i
  288.        update_cursor_rect
  289.        top_x = self.cursor_rect.x + self.x + 16
  290.        bottom_x = top_x + self.cursor_rect.width
  291.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  292.          mouse_not_in_rect = false
  293.          break
  294.        end
  295.      end
  296.      if mouse_not_in_rect
  297.        @index = index_var
  298.        update_cursor_rect
  299.        Mouse.click_lock
  300.      else
  301.        Mouse.click_unlock
  302.      end
  303.    end
  304.    if @last_mouse_y == nil
  305.      @last_mouse_y = mouse_y
  306.    end
  307.    check_pos = (@last_mouse_y - mouse_y).abs
  308.    if check_pos > 10
  309.      $game_system.se_play($data_system.cursor_se)
  310.      place = 10 ** (@digits_max - 1 - @index)
  311.      n = @number / place % 10
  312.      @number -= n * place
  313.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  314.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  315.      @number += n * place
  316.      refresh
  317.      @last_mouse_y = mouse_y
  318.    end
  319. end
  320. end
  321. class Scene_File
  322. if @self_alias == nil
  323.    alias self_update update
  324.    @self_alias = true
  325. end
  326. def update
  327.    mouse_x, mouse_y = Mouse.get_mouse_pos
  328.    Mouse.click_lock
  329.    idx = 0
  330.    for i in @savefile_windows
  331.      top_x = i.x + 16
  332.      top_y = i.y + 16
  333.      bottom_x = top_x + i.width
  334.      bottom_y = top_y + i.height
  335.      if (mouse_x > top_x) and (mouse_y > top_y) and
  336.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  337.        i.selected = true
  338.        if @file_index != idx
  339.          @file_index = idx
  340.          $game_system.se_play($data_system.cursor_se)
  341.        end            
  342.        Mouse.click_unlock
  343.      else
  344.        i.selected = false
  345.      end
  346.      idx += 1
  347.    end
  348.    self_update
  349. end
  350. end
  351. Mouse.init
  352. END { Mouse.exit }


RUBY 代码复制
  1. class Game_Picture
  2.  
  3. def name=(str)
  4.    @name = str
  5. end
  6.  
  7. end
  8.  
  9. class Sprite_Picture
  10.  
  11. alias update_old update
  12. def update
  13.    update_old
  14.    return if @picture_name == "" or @picture_name[/cmd/].nil?
  15.    mx,my = Mouse.get_mouse_pos
  16.    lx = self.x - self.ox
  17.    rx = lx + self.bitmap.width
  18.    ty = self.y - self.oy
  19.    by = ty + self.bitmap.height
  20.    if mx < lx or mx > rx or my < ty or my > by or
  21.      self.bitmap.get_pixel(mx-lx,my-ty).alpha == 0
  22.      @picture.name = @picture.name.split(/_/)[0]+"_"+@picture.name.split(/_/)[1]
  23.      return
  24.    end
  25.    if @picture.name.split(/_/)[2].nil?
  26.      @picture.name = @picture.name + "_02"
  27.    end
  28.    if Input.trigger?(13)
  29.      @picture.name.split(/_/)[0].sub(/cmd([0-9]+)/,"")
  30.      $game_temp.common_event_id = $1.to_i
  31.    end
  32. end
  33.  
  34. end
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-15 04:24

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表