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

Project1

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

[已经解决] 请教如何让鼠标也能选择到战斗不能状态的角色

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
200 小时
注册时间
2008-3-1
帖子
360
跳转到指定楼层
1
发表于 2012-7-16 13:21:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我用的鼠标脚本,发现在战斗时当有角色阵亡,要使用滋补剂之类复活的物品时,无法用鼠标选择到战斗不能状态的角色,而只能用键盘来选,请教如何让鼠标也能选择到战斗不能状态的角色
  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #==============================================================================

  4. #=================以下两个用来调整战斗时的手感问题,可以自己试试。

  5. #鼠标是否移动
  6. $mouse_move

  7. $敌人选框扩大 = 20
  8. $角色选框扩大 = 30


  9. #==============================================================================
  10. # API调用
  11. #==============================================================================
  12. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  13. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  14. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  15. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  16. $Window_HWND = $GetActiveWindow.call
  17. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')

  18. $FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  19. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  20. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  21. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  22. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  23. module Mouse  
  24.   LEFT = 0x01
  25.   RIGHT = 0x02

  26.   def self.init(sprite = nil)
  27. #   $HookStart.call($Window_HWND)
  28.     $ShowCursor.call(0)
  29.    
  30.     @show_cursor = false
  31.    
  32.     @mouse_sprite = Sprite.new
  33.     @mouse_sprite.z = 99999
  34.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Weapon01.png')
  35.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))

  36.     @left_press = false
  37.     @right_press = false
  38.     @left_trigger = false
  39.     @right_trigger = false
  40.     @left_repeat = false
  41.     @right_repeat = false
  42.     @click_lock = false
  43.    
  44.     update
  45.   end
  46.   def self.exit
  47.     @mouse_sprite.bitmap.dispose
  48.     @mouse_sprite.dispose
  49.     @show_cursor = true
  50. #    $HookEnd.call
  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.    
  60.     @click_lock = false
  61.     mouse_x, mouse_y = self.get_mouse_pos
  62.     if @mouse_sprite != nil
  63.       @mouse_sprite.x = mouse_x
  64.       @mouse_sprite.y = mouse_y
  65.     end
  66.     if left_down[7] == 1
  67.       @left_repeat = (not @left_repeat)
  68.       @left_trigger = (not @left_press)
  69.       @left_press = true
  70.     else
  71.       @left_press = false
  72.       @left_trigger = false
  73.       @left_repeat = false
  74.     end
  75.     if right_down[7] == 1
  76.       @right_repeat = (not @right_repeat)
  77.       @right_trigger = (not @right_press)
  78.       @right_press = true
  79.     else
  80.       @right_press = false
  81.       @right_trigger = false
  82.       @right_repeat = false
  83.     end
  84.    
  85.   if @mouse_sprite != nil
  86.      if @old_x != @mouse_sprite.x or @old_y != @mouse_sprite.y or
  87.        Mouse.press?(Mouse::LEFT) or
  88.        Mouse.press?(Mouse::RIGHT)
  89.        @waittime = 80
  90.        @mouse_sprite.opacity = 255
  91.        ###########
  92.        $mouse_move = true
  93.        ###########
  94.      end
  95.      @waittime -= 1 if @waittime != 0
  96.      @mouse_sprite.opacity -= 8 if @waittime == 0 and @mouse_sprite.opacity > 0
  97.      @old_x = @mouse_sprite.x
  98.      @old_y = @mouse_sprite.y
  99.       ###########
  100.       if @mouse_sprite.opacity < 100 or @waittime < 40
  101.         $mouse_move = false
  102.       end
  103.       ###########
  104.     end
  105.    
  106.   end
  107.   def self.get_mouse_pos
  108.     point_var = [0, 0].pack('ll')
  109.     if $GetCursorPos.call(point_var) != 0
  110.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  111.         x, y = point_var.unpack('ll')
  112.         if (x < 0) or (x > 10000) then x = 0 end
  113.         if (y < 0) or (y > 10000) then y = 0 end
  114.         if x > 640 then x = 640 end
  115.         if y > 480 then y = 480 end
  116.         return x, y
  117.       else
  118.         return 0, 0
  119.       end
  120.     else
  121.       return 0, 0
  122.     end
  123.   end
  124.   def self.press?(mouse_code)
  125.     if mouse_code == LEFT
  126.       if @click_lock
  127.         return false
  128.       else
  129.         return @left_press
  130.       end
  131.     elsif mouse_code == RIGHT
  132.       return @right_press
  133.     else
  134.       return false
  135.     end
  136.   end
  137.   def self.trigger?(mouse_code)
  138.     if mouse_code == LEFT
  139.       if @click_lock
  140.         return false
  141.       else
  142.         return @left_trigger
  143.       end
  144.     elsif mouse_code == RIGHT
  145.       return @right_trigger
  146.     else
  147.       return false
  148.     end
  149.   end
  150.   def self.repeat?(mouse_code)
  151.     if mouse_code == LEFT
  152.       if @click_lock
  153.         return false
  154.       else
  155.         return @left_repeat
  156.       end
  157.     elsif mouse_code == RIGHT
  158.       return @right_repeat
  159.     else
  160.       return false
  161.     end
  162.   end
  163.   def self.click_lock?
  164.     return @click_lock
  165.   end
  166.   def self.click_lock
  167.     @click_lock = true
  168.   end
  169.   def self.click_unlock
  170.     @click_lock = false
  171.   end
  172. end
  173. module Input
  174.   if @self_update == nil
  175.     @self_update = method('update')
  176.     @self_press = method('press?')
  177.     @self_trigger = method('trigger?')
  178.     @self_repeat = method('repeat?')
  179.   end
  180.   def self.update
  181.     @self_update.call
  182.     Mouse.update
  183.   end
  184.   def self.press?(key_code)
  185.     if @self_press.call(key_code)
  186.       return true
  187.     end
  188.     if key_code == C
  189.       return Mouse.press?(Mouse::LEFT)
  190.     elsif key_code == B
  191.       return Mouse.press?(Mouse::RIGHT)
  192.     else
  193.       return @self_press.call(key_code)
  194.     end
  195.   end
  196.   def self.trigger?(key_code)
  197.     if @self_trigger.call(key_code)
  198.       return true
  199.     end
  200.     if key_code == C
  201.       return Mouse.trigger?(Mouse::LEFT)
  202.     elsif key_code == B
  203.       return Mouse.trigger?(Mouse::RIGHT)
  204.     else
  205.       return @self_trigger.call(key_code)
  206.     end
  207.   end
  208.   def self.repeat?(key_code)
  209.     if @self_repeat.call(key_code)
  210.       return true
  211.     end
  212.     if key_code == C
  213.       return Mouse.repeat?(Mouse::LEFT)
  214.     elsif key_code == B
  215.       return Mouse.repeat?(Mouse::RIGHT)
  216.     else
  217.       return @self_repeat.call(key_code)
  218.     end
  219.   end
  220. end
  221. class Window_Selectable
  222. if @self_alias == nil
  223.    alias self_update update
  224.    @self_alias = true
  225. end
  226. def update
  227.    self_update
  228.    if self.active and @item_max > 0
  229.      index_var = @index
  230.      tp_index = @index
  231.      mouse_x, mouse_y = Mouse.get_mouse_pos
  232.      mouse_not_in_rect = true
  233.      for i in 0...@item_max
  234.        @index = i
  235.        update_cursor_rect if $mouse_move#####
  236.        top_x = self.cursor_rect.x + self.x + 16
  237.        top_y = self.cursor_rect.y + self.y + 16
  238.        bottom_x = top_x + self.cursor_rect.width
  239.        bottom_y = top_y + self.cursor_rect.height
  240.        if (mouse_x > top_x) and (mouse_y > top_y) and
  241.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  242.          mouse_not_in_rect = false if $mouse_move#####
  243.          if tp_index != @index
  244.            tp_index = @index if $mouse_move#####
  245.            $game_system.se_play($data_system.cursor_se)
  246.          end
  247.          break
  248.        end
  249.      end
  250.      if mouse_not_in_rect
  251.        @index = index_var
  252.        update_cursor_rect if $mouse_move#####
  253.        Mouse.click_lock
  254.      else
  255.        Mouse.click_unlock               
  256.      end
  257.    end
  258. end
  259. end

  260. class Window_NameInput
  261. if @self_alias == nil
  262.    alias self_update update
  263.    @self_alias = true
  264. end
  265. def update
  266.    self_update
  267.    if self.active
  268.      index_var = @index
  269.      mouse_x, mouse_y = Mouse.get_mouse_pos
  270.      mouse_not_in_rect = true
  271.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  272.        @index = i
  273.        update_cursor_rect if $mouse_move#####
  274.        top_x = self.cursor_rect.x + self.x + 16
  275.        top_y = self.cursor_rect.y + self.y + 16
  276.        bottom_x = top_x + self.cursor_rect.width
  277.        bottom_y = top_y + self.cursor_rect.height
  278.        if (mouse_x > top_x) and (mouse_y > top_y) and
  279.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  280.          mouse_not_in_rect = false if $mouse_move#####
  281.          break
  282.        end
  283.      end
  284.      if mouse_not_in_rect
  285.        @index = index_var
  286.        update_cursor_rect if $mouse_move#####
  287.        Mouse.click_lock
  288.      else
  289.        Mouse.click_unlock
  290.      end
  291.    end
  292. end
  293. end
  294. class Window_InputNumber
  295. if @self_alias == nil
  296.    alias self_update update
  297.    @self_alias = true
  298. end
  299. def update
  300.    self_update
  301.    mouse_x, mouse_y = Mouse.get_mouse_pos
  302.    if self.active and @digits_max > 0
  303.      index_var = @index
  304.      mouse_not_in_rect = true
  305.      for i in 0...@digits_max
  306.        @index = i
  307.        update_cursor_rect if $mouse_move#####
  308.        top_x = self.cursor_rect.x + self.x + 16
  309.        bottom_x = top_x + self.cursor_rect.width
  310.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  311.          mouse_not_in_rect = false if $mouse_move#####
  312.          break
  313.        end
  314.      end
  315.      if mouse_not_in_rect
  316.        @index = index_var
  317.        update_cursor_rect if $mouse_move#####
  318.        Mouse.click_lock
  319.      else
  320.        Mouse.click_unlock
  321.      end
  322.    end
  323.    if @last_mouse_y == nil
  324.      @last_mouse_y = mouse_y
  325.    end
  326.    check_pos = (@last_mouse_y - mouse_y).abs
  327.    if check_pos > 10
  328.      $game_system.se_play($data_system.cursor_se)
  329.      place = 10 ** (@digits_max - 1 - @index)
  330.      n = @number / place % 10
  331.      @number -= n * place
  332.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  333.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  334.      @number += n * place
  335.      refresh
  336.      @last_mouse_y = mouse_y
  337.    end
  338. end
  339. end
  340. class Scene_File
  341.   if @self_alias == nil
  342.     alias self_update update
  343.     @self_alias = true
  344.   end
  345.   def update
  346.     mouse_x, mouse_y = Mouse.get_mouse_pos
  347.     Mouse.click_lock
  348.     idx = 0
  349.     for i in @savefile_windows
  350.       top_x = i.x + 16
  351.       top_y = i.y + 16
  352.       bottom_x = top_x + i.width
  353.       bottom_y = top_y + i.height
  354.       if (mouse_x > top_x) and (mouse_y > top_y) and
  355.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  356.         i.selected = true
  357.         if @file_index != idx
  358.           @file_index = idx
  359.           $game_system.se_play($data_system.cursor_se)
  360.         end            
  361.         Mouse.click_unlock
  362.       else
  363.         i.selected = false
  364.       end
  365.       idx += 1
  366.     end
  367.     self_update
  368.   end
  369. end
  370. class Arrow_Enemy
  371.   if @self_alias == nil
  372.     alias self_update update
  373.     @self_alias = true
  374.   end
  375.   def update
  376.     mouse_x, mouse_y = Mouse.get_mouse_pos
  377.     idx = 0
  378.     for i in $game_troop.enemies do
  379.       if i.exist?
  380.         top_x = i.screen_x - self.ox
  381.         top_y = i.screen_y - self.oy
  382.         bottom_x = top_x + self.src_rect.width
  383.         bottom_y = top_y + self.src_rect.height
  384.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  385.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  386.           if @index != idx
  387.             $game_system.se_play($data_system.cursor_se)
  388.             @index = idx
  389.           end
  390.         end
  391.       end
  392.       idx += 1
  393.     end
  394.     self_update
  395.   end
  396. end
  397. class Arrow_Actor
  398.   if @self_alias == nil
  399.     alias self_update update
  400.     @self_alias = true
  401.   end
  402.   def update
  403.     mouse_x, mouse_y = Mouse.get_mouse_pos
  404.     idx = 0
  405.     for i in $game_party.actors do
  406.       if i.exist?
  407.         top_x = i.screen_x - self.ox
  408.         top_y = i.screen_y - self.oy
  409.         bottom_x = top_x + self.src_rect.width
  410.         bottom_y = top_y + self.src_rect.height
  411.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  412.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  413.           if @index != idx
  414.             $game_system.se_play($data_system.cursor_se)
  415.             @index = idx
  416.           end
  417.         end
  418.       end
  419.       idx += 1
  420.     end
  421.     self_update
  422.   end
  423. end
  424. class Game_Player
  425.   if @self_alias == nil
  426.     alias self_update update
  427.     @self_alias = true
  428.   end
  429.   def update
  430.     mouse_x, mouse_y = Mouse.get_mouse_pos

  431.     if @last_move_x == nil
  432.       @last_move_x = false
  433.     end
  434.     if Mouse.press?(Mouse::LEFT)
  435.       last_moving = moving?
  436.       last_direction = @direction
  437.       unless moving? or $game_system.map_interpreter.running? or
  438.              @move_route_forcing or $game_temp.message_window_showing
  439.         last_x = @x
  440.         if @last_move_x
  441.           @last_move_x = false
  442.         elsif mouse_x > screen_x + 16
  443.           move_right
  444.         elsif mouse_x < screen_x - 16
  445.           move_left
  446.         end
  447.         last_y = @y
  448.         if last_x != @x
  449.           @last_move_x = true
  450.         elsif mouse_y > screen_y
  451.           move_down
  452.         elsif mouse_y < screen_y - 32
  453.           move_up
  454.         end
  455.         if last_y != @y
  456.           @last_move_x = false
  457.         elsif not @last_move_x
  458.           case last_direction
  459.           when 2
  460.             turn_down
  461.           when 4
  462.             turn_left
  463.           when 6
  464.             turn_right
  465.           when 8
  466.             turn_up
  467.           end
  468.         end
  469.       end
  470.     end
  471.     self_update
  472.   end
  473. end
  474. Mouse.init
  475. END { Mouse.exit }
复制代码

Lv1.梦旅人

路人党员

梦石
0
星屑
52
在线时间
2276 小时
注册时间
2010-12-30
帖子
3225
2
发表于 2012-7-16 14:43:51 | 只看该作者
注释389和401

点评

应该是注释掉416和428行吧  发表于 2012-7-16 15:12
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
200 小时
注册时间
2008-3-1
帖子
360
3
 楼主| 发表于 2012-7-16 14:59:19 | 只看该作者
英顺的马甲 发表于 2012-7-16 14:43
注释389和401

我已经注释掉了,但在战斗中还是不能通过移动鼠标来选中阵亡的角色啊

点评

抱歉,我看成选择敌人了,注释掉416和428行吧==  发表于 2012-7-16 16:04
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-9-23 15:25

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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