查看: 2082|回复: 1

[已经解决] 鼠标系统BUG,不能直接和主角侧面的NPC对话

[复制链接]
梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

发表于 2015-12-17 23:37:27 | 显示全部楼层 |阅读模式

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

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

×
这个鼠标脚本点击NPC后可以对话,不过只能和正面的NPC对话。
假设NPC在侧面,主角不会转身,必须走出去再走回来把脸对准NPC才能对话



鼠标脚本
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================

  4. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  5. $敌人选框扩大 = 20
  6. $角色选框扩大 = 30


  7. #==============================================================================
  8. # API调用
  9. #==============================================================================
  10. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  11. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  12. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  13. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  14. $Window_HWND = $GetActiveWindow.call
  15. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  16. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  17. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  18. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  19. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  20. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  21. module Mouse  
  22.   LEFT = 0x01
  23.   RIGHT = 0x02

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

  34.     @left_press = false
  35.     @right_press = false
  36.     @left_trigger = false
  37.     @right_trigger = false
  38.     @left_repeat = false
  39.     @right_repeat = false
  40.     @click_lock = false
  41.    
  42.     update
  43.   end
  44.   def self.exit
  45.     @mouse_sprite.bitmap.dispose
  46.     @mouse_sprite.dispose
  47.     @show_cursor = true
  48. #    $HookEnd.call
  49.     $ShowCursor.call(1)
  50.   end
  51.   def self.mouse_debug
  52.     return @mouse_debug.bitmap
  53.   end
  54.   def self.update
  55.     @mouse_sprite.visible = $xiaolv20
  56.    
  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.   end
  85.   def self.get_mouse_pos
  86.     return 0,0 unless $xiaolv20
  87.     point_var = [0, 0].pack('ll')
  88.     if $GetCursorPos.call(point_var) != 0
  89.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  90.         x, y = point_var.unpack('ll')
  91.         if (x < 0) or (x > 10000) then x = 0 end
  92.         if (y < 0) or (y > 10000) then y = 0 end
  93.         if x > 640 then x = 640 end
  94.         if y > 480 then y = 480 end
  95.         return x, y
  96.       else
  97.         return 0, 0
  98.       end
  99.     else
  100.       return 0, 0
  101.     end
  102.   end
  103.   def self.press?(mouse_code)
  104.     return false unless $xiaolv20
  105.     if mouse_code == LEFT
  106.       if @click_lock
  107.         return false
  108.       else
  109.         return @left_press
  110.       end
  111.     elsif mouse_code == RIGHT
  112.       return @right_press
  113.     else
  114.       return false
  115.     end
  116.   end
  117.   def self.trigger?(mouse_code)
  118.     return false unless $xiaolv20
  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.     return false unless $xiaolv20
  133.     if mouse_code == LEFT
  134.       if @click_lock
  135.         return false
  136.       else
  137.         return @left_repeat
  138.       end
  139.     elsif mouse_code == RIGHT
  140.       return @right_repeat
  141.     else
  142.       return false
  143.     end
  144.   end
  145.   def self.click_lock?
  146.     return @click_lock
  147.   end
  148.   def self.click_lock
  149.     @click_lock = true
  150.   end
  151.   def self.click_unlock
  152.     @click_lock = false
  153.   end
  154. end
  155. $xiaolv20 = true
  156. module Input
  157.   if @self_update == nil
  158.     @self_update = method('update')
  159.     @self_press = method('press?')
  160.     @self_trigger = method('trigger?')
  161.     @self_repeat = method('repeat?')
  162.   end
  163.   def self.update
  164.     @self_update.call
  165.     Mouse.update
  166.   end
  167.   def self.press?(key_code)
  168.     if @self_press.call(key_code)
  169.       return true
  170.     end
  171.     if key_code == C
  172.       return Mouse.press?(Mouse::LEFT)
  173.     elsif key_code == B
  174.       return Mouse.press?(Mouse::RIGHT)
  175.     else
  176.       return @self_press.call(key_code)
  177.     end
  178.   end
  179.   def self.trigger?(key_code)
  180.     if @self_trigger.call(key_code)
  181.       return true
  182.     end
  183.     if key_code == C
  184.       return Mouse.trigger?(Mouse::LEFT)
  185.     elsif key_code == B
  186.       return Mouse.trigger?(Mouse::RIGHT)
  187.     else
  188.       return @self_trigger.call(key_code)
  189.     end
  190.   end
  191.   def self.repeat?(key_code)
  192.     if @self_repeat.call(key_code)
  193.       return true
  194.     end
  195.     if key_code == C
  196.       return Mouse.repeat?(Mouse::LEFT)
  197.     elsif key_code == B
  198.       return Mouse.repeat?(Mouse::RIGHT)
  199.     else
  200.       return @self_repeat.call(key_code)
  201.     end
  202.   end
  203. end
  204. class Window_Selectable
  205.   if @self_alias == nil
  206.     alias self_update update
  207.     @self_alias = true
  208.   end
  209.   def update
  210.     #self.cursor_rect.empty
  211.     self_update
  212.     if self.active and @item_max > 0
  213.       index_var = @index
  214.       tp_index = @index
  215.       mouse_x, mouse_y = Mouse.get_mouse_pos
  216.       mouse_not_in_rect = true
  217.       for i in 0...@item_max
  218.         @index = i
  219.         update_cursor_rect
  220.         top_x = self.cursor_rect.x + self.x + 16
  221.         top_y = self.cursor_rect.y + self.y + 16
  222.         bottom_x = top_x + self.cursor_rect.width
  223.         bottom_y = top_y + self.cursor_rect.height
  224.         if (mouse_x > top_x) and (mouse_y > top_y) and
  225.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  226.           mouse_not_in_rect = false
  227.           if tp_index != @index
  228.             tp_index = @index
  229.             $game_system.se_play($data_system.cursor_se)
  230.           end
  231.           break
  232.         end
  233.       end
  234.       if mouse_not_in_rect
  235.         @index = index_var
  236.         update_cursor_rect
  237.         Mouse.click_lock
  238.       else
  239.         Mouse.click_unlock               
  240.       end
  241.     end
  242.   end
  243. end
  244. class Window_NameInput
  245.   if @self_alias == nil
  246.     alias self_update update
  247.     @self_alias = true
  248.   end
  249.   def update
  250.     #self.cursor_rect.empty
  251.     self_update
  252.     if self.active
  253.       index_var = @index
  254.       mouse_x, mouse_y = Mouse.get_mouse_pos
  255.       mouse_not_in_rect = true
  256.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  257.         @index = i
  258.         update_cursor_rect
  259.         top_x = self.cursor_rect.x + self.x + 16
  260.         top_y = self.cursor_rect.y + self.y + 16
  261.         bottom_x = top_x + self.cursor_rect.width
  262.         bottom_y = top_y + self.cursor_rect.height
  263.         #
  264.         if (mouse_x > top_x) and (mouse_y > top_y) and
  265.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  266.           mouse_not_in_rect = false
  267.           break
  268.         end
  269.       end
  270.       if mouse_not_in_rect
  271.         @index = index_var
  272.         update_cursor_rect
  273.         Mouse.click_lock
  274.       else
  275.         Mouse.click_unlock
  276.       end
  277.     end
  278.   end
  279. end
  280. class Window_InputNumber
  281.   if @self_alias == nil
  282.     alias self_update update
  283.     @self_alias = true
  284.   end
  285.   def update
  286.     #self.cursor_rect.empty
  287.     self_update
  288.     mouse_x, mouse_y = Mouse.get_mouse_pos
  289.     if self.active and @digits_max > 0
  290.       index_var = @index
  291.       mouse_not_in_rect = true
  292.       for i in 0...@digits_max
  293.         @index = i
  294.         update_cursor_rect
  295.         top_x = self.cursor_rect.x + self.x + 16
  296.         bottom_x = top_x + self.cursor_rect.width
  297.         #
  298.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  299.           mouse_not_in_rect = false
  300.           break
  301.         end
  302.       end
  303.       if mouse_not_in_rect
  304.         @index = index_var
  305.         update_cursor_rect
  306.         Mouse.click_lock
  307.       else
  308.         Mouse.click_unlock
  309.       end
  310.     end
  311.     if @last_mouse_y == nil
  312.       @last_mouse_y = mouse_y
  313.     end
  314.     check_pos = (@last_mouse_y - mouse_y).abs
  315.     if check_pos > 10
  316.       $game_system.se_play($data_system.cursor_se)
  317.       place = 10 ** (@digits_max - 1 - @index)
  318.       n = @number / place % 10
  319.       @number -= n * place
  320.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  321.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  322.       @number += n * place
  323.       refresh
  324.       @last_mouse_y = mouse_y
  325.     end
  326.   end
  327. end
  328. class Scene_File
  329.   if @self_alias == nil
  330.     alias self_update update
  331.     @self_alias = true
  332.   end
  333.   def update
  334.     mouse_x, mouse_y = Mouse.get_mouse_pos
  335.     Mouse.click_lock
  336.     idx = 0
  337.     for i in @savefile_windows
  338.       top_x = i.x + 16
  339.       top_y = i.y + 16
  340.       bottom_x = top_x + i.width
  341.       bottom_y = top_y + i.height
  342.       if (mouse_x > top_x) and (mouse_y > top_y) and
  343.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  344.         i.selected = true
  345.         if @file_index != idx
  346.           @file_index = idx
  347.           $game_system.se_play($data_system.cursor_se)
  348.         end            
  349.         Mouse.click_unlock
  350.       else
  351.         i.selected = false
  352.       end
  353.       idx += 1
  354.     end
  355.     self_update
  356.   end
  357. end
  358. class Arrow_Enemy
  359.   if @self_alias == nil
  360.     alias self_update update
  361.     @self_alias = true
  362.   end
  363.   def update
  364.     mouse_x, mouse_y = Mouse.get_mouse_pos
  365.     idx = 0
  366.     for i in $game_troop.enemies do
  367.       if i.exist?
  368.         top_x = i.screen_x - self.ox
  369.         top_y = i.screen_y - self.oy
  370.         bottom_x = top_x + self.src_rect.width
  371.         bottom_y = top_y + self.src_rect.height
  372.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  373.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  374.           if @index != idx
  375.             $game_system.se_play($data_system.cursor_se)
  376.             @index = idx
  377.           end
  378.         end
  379.       end
  380.       idx += 1
  381.     end
  382.     self_update
  383.   end
  384. end
  385. class Arrow_Actor
  386.   if @self_alias == nil
  387.     alias self_update update
  388.     @self_alias = true
  389.   end
  390.   def update
  391.     mouse_x, mouse_y = Mouse.get_mouse_pos
  392.     idx = 0
  393.     for i in $game_party.actors do
  394.       if i.exist?
  395.         top_x = i.screen_x - self.ox
  396.         top_y = i.screen_y - self.oy
  397.         bottom_x = top_x + self.src_rect.width
  398.         bottom_y = top_y + self.src_rect.height
  399.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  400.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  401.           if @index != idx
  402.             $game_system.se_play($data_system.cursor_se)
  403.             @index = idx
  404.           end
  405.         end
  406.       end
  407.       idx += 1
  408.     end
  409.     self_update
  410.   end
  411. end
  412. class Game_Player
  413.   if @self_alias == nil
  414.     alias self_update update
  415.     @self_alias = true
  416.   end
  417.   def update
  418.     mouse_x, mouse_y = Mouse.get_mouse_pos

  419.     if @last_move_x == nil
  420.       @last_move_x = false
  421.     end
  422.     if Mouse.press?(Mouse::LEFT)
  423.       last_moving = moving?
  424.       last_direction = @direction
  425.       unless moving? or $game_system.map_interpreter.running? or
  426.              @move_route_forcing or $game_temp.message_window_showing
  427.         last_x = @x
  428.         if @last_move_x
  429.           @last_move_x = false
  430.           #右上
  431.           elsif mouse_x > screen_x + 16 and mouse_y < screen_y - 32
  432.           move_right
  433.           move_up
  434.           #右下
  435.           elsif mouse_x > screen_x + 16 and mouse_y > screen_y
  436.             move_right
  437.             move_down
  438.           #右
  439.         elsif mouse_x > screen_x + 16
  440.           move_right
  441.           #左上
  442.           elsif mouse_x < screen_x - 16 and mouse_y < screen_y - 32
  443.             move_left
  444.             move_up
  445.             #左下
  446.             elsif mouse_x < screen_x - 16 and mouse_y > screen_y
  447.               move_left
  448.               move_down
  449.           #左
  450.         elsif mouse_x < screen_x - 16
  451.           move_left
  452.         end
  453.         last_y = @y
  454.         if last_x != @x
  455.           @last_move_x = true
  456.                     #右上
  457.           elsif mouse_x > screen_x + 16 and mouse_y < screen_y - 32
  458.           move_right
  459.           move_up

  460.                     #右下
  461.           elsif mouse_x > screen_x + 16 and mouse_y > screen_y
  462.             move_right
  463.             move_down

  464.           #下
  465.         elsif mouse_y > screen_y
  466.           move_down
  467.                     #左上
  468.           elsif mouse_x < screen_x - 16 and mouse_y < screen_y - 32
  469.             move_left
  470.             move_up

  471.                     #右上
  472.           elsif mouse_x > screen_x + 16 and mouse_y < screen_y - 32
  473.           move_right
  474.           move_up

  475.           #上
  476.         elsif mouse_y < screen_y - 32
  477.           move_up
  478.         end
  479.         if last_y != @y
  480.           @last_move_x = false
  481.         elsif not @last_move_x
  482.           case last_direction
  483.           when 2
  484.             turn_down
  485.           when 4
  486.             turn_left
  487.           when 6
  488.             turn_right
  489.           when 8
  490.             turn_up
  491.           end
  492.         end
  493.       end
  494.     end
  495.     self_update
  496.   end
  497. end
  498. Mouse.init
  499. END { Mouse.exit }




  500. #==============================================================================
  501. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  502. #============================================================================
复制代码
梦石
0
星屑
50
在线时间
168 小时
注册时间
2007-7-26
回帖
427
发表于 2015-12-20 12:49:50 | 显示全部楼层
站上有好多鼠标响应的范例,还有远距离点击NPC的范例。

点评

已经解决了啊  发表于 2015-12-20 12:53
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部