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

Project1

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

[已经过期] 鼠标脚本老是出错……、

[复制链接]

Lv1.梦旅人

梦石
0
星屑
48
在线时间
773 小时
注册时间
2012-4-5
帖子
223
跳转到指定楼层
1
发表于 2012-6-11 21:06:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. class Game_Event
  2.   attr_accessor :flag
  3. end

  4. class Game_Map
  5.   def check_event_custom(x, y)
  6.     for event in $game_map.events.values
  7.       if event.screen_x/32 == x and event.screen_y/32-1 == y
  8.         for i in 0...event.list.size
  9.           if event.list[i].parameters[0] == "enemy"
  10.             event.flag = 1
  11.           elsif event.list[i].parameters[0] == "npc"
  12.             event.flag = 2
  13.           elsif event.list[i].parameters[0] == "chest"
  14.             event.flag = 3
  15.           else
  16.             event.flag = 0
  17.           end
  18.           return event.flag
  19.         end
  20.       end
  21.     end
  22.   end
  23. end
  24. #==============================================================================
  25. # 初始鼠标图案在35行和64行改,变换的鼠标图案在62行改
  26. # 这个脚本的思路是判断鼠标所在位置是否有事件,所以响应的情况只有一种。
  27. # 如果想有多种响应的话,思路复杂,比如拆分事件名称等,做出来的东西将繁琐。
  28. #                                                         
  29. #==============================================================================
  30. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  31. $敌人选框扩大 = 20
  32. $角色选框扩大 = 30
  33. #==============================================================================
  34. # API调用
  35. #==============================================================================
  36. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  37. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  38. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  39. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  40. $Window_HWND = $GetActiveWindow.call
  41. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  42. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  43. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  44. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  45. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  46. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  47. module Mouse  
  48.   LEFT = 0x01
  49.   RIGHT = 0x02

  50.   def self.init(sprite = nil)
  51. #   $HookStart.call($Window_HWND)
  52.     $ShowCursor.call(0)
  53.    
  54.     @show_cursor = false
  55.    
  56.     @mouse_sprite = Sprite.new
  57.     @mouse_sprite.z = 99999
  58.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Mouse/鼠标.PNG')
  59.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))

  60.     @left_press = false
  61.     @right_press = false
  62.     @left_trigger = false
  63.     @right_trigger = false
  64.     @left_repeat = false
  65.     @right_repeat = false
  66.     @click_lock = false
  67.     if @a == nil
  68.       @a = true
  69.       @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  70.     end
  71.     update
  72.   end
  73.   def self.exit
  74.     @mouse_sprite.bitmap.dispose
  75.     @mouse_sprite.dispose
  76.     @show_cursor = true
  77. #    $HookEnd.call
  78.     $ShowCursor.call(1)
  79.   end
  80.   def self.mouse_debug
  81.     return @mouse_debug.bitmap
  82.   end
  83.   def self.refresh
  84.   end
  85.   def self.update
  86.     left_down = $GetKeyState.call(0x01)
  87.     right_down = $GetKeyState.call(0x02)
  88.     if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  89.       @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  90.       @a = !@a
  91.     end
  92.     case $pop
  93.     when 1
  94.       if @a
  95.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/1.png')
  96.       else
  97.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/11.png')
  98.       end
  99.     when 2
  100.       if @a
  101.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/2.png')
  102.       else
  103.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/22.png')
  104.       end
  105.     when 3
  106.       if @a
  107.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/3.png')
  108.       else
  109.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/33.png')
  110.       end
  111.     else
  112.       @mouse_sprite.bitmap = Bitmap.new('Graphics/Mouse/鼠标.PNG')
  113.     end
  114.     @click_lock = false
  115.     mouse_x, mouse_y = self.get_mouse_pos
  116.     if @mouse_sprite != nil
  117.       @mouse_sprite.x = mouse_x
  118.       @mouse_sprite.y = mouse_y
  119.     end
  120.     if left_down[7] == 1
  121.       @left_repeat = (not @left_repeat)
  122.       @left_trigger = (not @left_press)
  123.       @left_press = false
  124.     else
  125.       @left_press = false
  126.       @left_trigger = false
  127.       @left_repeat = false
  128.     end
  129.     if right_down[7] == 1
  130.       @right_repeat = (not @right_repeat)
  131.       @right_trigger = (not @right_press)
  132.       @right_press = false
  133.     else
  134.       @right_press = false
  135.       @right_trigger = false
  136.       @right_repeat = false
  137.     end
  138.   end
  139.   def self.get_mouse_pos
  140.     point_var = [0, 0].pack('ll')
  141.     if $GetCursorPos.call(point_var) != 0
  142.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  143.         x, y = point_var.unpack('ll')
  144.         if (x < 0) or (x > 10000) then x = 0 end
  145.         if (y < 0) or (y > 10000) then y = 0 end
  146.         if x > 640 then x = 640 end
  147.         if y > 480 then y = 480 end
  148.         return x, y
  149.       else
  150.         return 0, 0
  151.       end
  152.     else
  153.       return 0, 0
  154.     end
  155.   end
  156.   def self.press?(mouse_code)
  157.     if mouse_code == LEFT
  158.       if @click_lock
  159.         return false
  160.       else
  161.         return @left_press
  162.       end
  163.     elsif mouse_code == RIGHT
  164.       return @right_press
  165.     else
  166.       return false
  167.     end
  168.   end
  169.   def self.trigger?(mouse_code)
  170.     if mouse_code == LEFT
  171.       if @click_lock
  172.         return false
  173.       else
  174.         return @left_trigger
  175.       end
  176.     elsif mouse_code == RIGHT
  177.       return @right_trigger
  178.     else
  179.       return false
  180.     end
  181.   end
  182.   def self.repeat?(mouse_code)
  183.     if mouse_code == LEFT
  184.       if @click_lock
  185.         return false
  186.       else
  187.         return @left_repeat
  188.       end
  189.     elsif mouse_code == RIGHT
  190.       return @right_repeat
  191.     else
  192.       return false
  193.     end
  194.   end
  195.   def self.click_lock?
  196.     return @click_lock
  197.   end
  198.   def self.click_lock
  199.     @click_lock = true
  200.   end
  201.   def self.click_unlock
  202.     @click_lock = false
  203.   end
  204. end
  205. module Input
  206.   if @self_update == nil
  207.     @self_update = method('update')
  208.     @self_press = method('press?')
  209.     @self_trigger = method('trigger?')
  210.     @self_repeat = method('repeat?')
  211.   end
  212.   def self.update
  213.     @self_update.call
  214.     Mouse.update
  215.   end
  216.   def self.press?(key_code)
  217.     if @self_press.call(key_code)
  218.       return true
  219.     end
  220.     if key_code == C
  221.       return Mouse.press?(Mouse::LEFT)
  222.     elsif key_code == B
  223.       return Mouse.press?(Mouse::RIGHT)
  224.     else
  225.       return @self_press.call(key_code)
  226.     end
  227.   end
  228.   def self.trigger?(key_code)
  229.     if @self_trigger.call(key_code)
  230.       return true
  231.     end
  232.     if key_code == C
  233.       return Mouse.trigger?(Mouse::LEFT)
  234.     elsif key_code == B
  235.       return Mouse.trigger?(Mouse::RIGHT)
  236.     else
  237.       return @self_trigger.call(key_code)
  238.     end
  239.   end
  240.   def self.repeat?(key_code)
  241.     if @self_repeat.call(key_code)
  242.       return true
  243.     end
  244.     if key_code == C
  245.       return Mouse.repeat?(Mouse::LEFT)
  246.     elsif key_code == B
  247.       return Mouse.repeat?(Mouse::RIGHT)
  248.     else
  249.       return @self_repeat.call(key_code)
  250.     end
  251.   end
  252. end
  253. class Window_Selectable
  254.   if @self_alias == nil
  255.     alias self_update update
  256.     @self_alias = true
  257.   end
  258.   def update
  259.     #self.cursor_rect.empty
  260.     self_update
  261.     if self.active and @item_max > 0
  262.       index_var = @index
  263.       tp_index = @index
  264.       mouse_x, mouse_y = Mouse.get_mouse_pos
  265.       mouse_not_in_rect = true
  266.       for i in 0...@item_max
  267.         @index = i
  268.         update_cursor_rect
  269.         top_x = self.cursor_rect.x + self.x + 16
  270.         top_y = self.cursor_rect.y + self.y + 16
  271.         bottom_x = top_x + self.cursor_rect.width
  272.         bottom_y = top_y + self.cursor_rect.height
  273.         if (mouse_x > top_x) and (mouse_y > top_y) and
  274.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  275.           mouse_not_in_rect = false
  276.           if tp_index != @index
  277.             tp_index = @index
  278.             $game_system.se_play($data_system.cursor_se)
  279.           end
  280.           break
  281.         end
  282.       end
  283.       if mouse_not_in_rect
  284.         @index = index_var
  285.         update_cursor_rect
  286.         Mouse.click_lock
  287.       else
  288.         Mouse.click_unlock               
  289.       end
  290.     end
  291.   end
  292. end
  293. class Window_NameInput
  294.   if @self_alias == nil
  295.     alias self_update update
  296.     @self_alias = true
  297.   end
  298.   def update
  299.     #self.cursor_rect.empty
  300.     self_update
  301.     if self.active
  302.       index_var = @index
  303.       mouse_x, mouse_y = Mouse.get_mouse_pos
  304.       mouse_not_in_rect = true
  305.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  306.         @index = i
  307.         update_cursor_rect
  308.         top_x = self.cursor_rect.x + self.x + 16
  309.         top_y = self.cursor_rect.y + self.y + 16
  310.         bottom_x = top_x + self.cursor_rect.width
  311.         bottom_y = top_y + self.cursor_rect.height
  312.         #
  313.         if (mouse_x > top_x) and (mouse_y > top_y) and
  314.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  315.           mouse_not_in_rect = false
  316.           break
  317.         end
  318.       end
  319.       if mouse_not_in_rect
  320.         @index = index_var
  321.         update_cursor_rect
  322.         Mouse.click_lock
  323.       else
  324.         Mouse.click_unlock
  325.       end
  326.     end
  327.   end
  328. end
  329. class Window_InputNumber
  330.   if @self_alias == nil
  331.     alias self_update update
  332.     @self_alias = true
  333.   end
  334.   def update
  335.     #self.cursor_rect.empty
  336.     self_update
  337.     mouse_x, mouse_y = Mouse.get_mouse_pos
  338.     if self.active and @digits_max > 0
  339.       index_var = @index
  340.       mouse_not_in_rect = true
  341.       for i in 0...@digits_max
  342.         @index = i
  343.         update_cursor_rect
  344.         top_x = self.cursor_rect.x + self.x + 16
  345.         bottom_x = top_x + self.cursor_rect.width
  346.         #
  347.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  348.           mouse_not_in_rect = false
  349.           break
  350.         end
  351.       end
  352.       if mouse_not_in_rect
  353.         @index = index_var
  354.         update_cursor_rect
  355.         Mouse.click_lock
  356.       else
  357.         Mouse.click_unlock
  358.       end
  359.     end
  360.     if @last_mouse_y == nil
  361.       @last_mouse_y = mouse_y
  362.     end
  363.     check_pos = (@last_mouse_y - mouse_y).abs
  364.     if check_pos > 10
  365.       $game_system.se_play($data_system.cursor_se)
  366.       place = 10 ** (@digits_max - 1 - @index)
  367.       n = @number / place % 10
  368.       @number -= n * place
  369.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  370.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  371.       @number += n * place
  372.       refresh
  373.       @last_mouse_y = mouse_y
  374.     end
  375.   end
  376. end
  377. class Scene_File
  378.   if @self_alias == nil
  379.     alias self_update update
  380.     @self_alias = true
  381.   end
  382.   def update
  383.     mouse_x, mouse_y = Mouse.get_mouse_pos
  384.     Mouse.click_lock
  385.     idx = 0
  386.     for i in @savefile_windows
  387.       top_x = i.x + 16
  388.       top_y = i.y + 16
  389.       bottom_x = top_x + i.width
  390.       bottom_y = top_y + i.height
  391.       if (mouse_x > top_x) and (mouse_y > top_y) and
  392.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  393.         i.selected = true
  394.         if @file_index != idx
  395.           @file_index = idx
  396.           $game_system.se_play($data_system.cursor_se)
  397.         end            
  398.         Mouse.click_unlock
  399.       else
  400.         i.selected = false
  401.       end
  402.       idx += 1
  403.     end
  404.     self_update
  405.   end
  406. end
  407. class Arrow_Enemy
  408.   if @self_alias == nil
  409.     alias self_update update
  410.     @self_alias = true
  411.   end
  412.   def update
  413.     mouse_x, mouse_y = Mouse.get_mouse_pos
  414.     idx = 0
  415.     for i in $game_troop.enemies do
  416.       if i.exist?
  417.         top_x = i.screen_x - self.ox
  418.         top_y = i.screen_y - self.oy
  419.         bottom_x = top_x + self.src_rect.width
  420.         bottom_y = top_y + self.src_rect.height
  421.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  422.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  423.           if @index != idx
  424.             $game_system.se_play($data_system.cursor_se)
  425.             @index = idx
  426.           end
  427.         end
  428.       end
  429.       idx += 1
  430.     end
  431.     self_update
  432.   end
  433. end
  434. class Arrow_Actor
  435.   if @self_alias == nil
  436.     alias self_update update
  437.     @self_alias = true
  438.   end
  439.   def update
  440.     mouse_x, mouse_y = Mouse.get_mouse_pos
  441.     idx = 0
  442.     for i in $game_party.actors do
  443.       if i.exist?
  444.         top_x = i.screen_x - self.ox
  445.         top_y = i.screen_y - self.oy
  446.         bottom_x = top_x + self.src_rect.width
  447.         bottom_y = top_y + self.src_rect.height
  448.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  449.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  450.           if @index != idx
  451.             $game_system.se_play($data_system.cursor_se)
  452.             @index = idx
  453.           end
  454.         end
  455.       end
  456.       idx += 1
  457.     end
  458.     self_update
  459.   end
  460. end
  461. class Game_Player
  462.   if @self_alias == nil
  463.     alias self_update update
  464.     @self_alias = true
  465.   end
  466.   def update
  467.     mouse_x, mouse_y = Mouse.get_mouse_pos
  468.     unless $game_system.map_interpreter.running?
  469.       $pop = $game_map.check_event_custom(mouse_x/32,mouse_y/32)
  470.     else
  471.       $pop = 0
  472.     end
  473.     if @last_move_x == nil
  474.       @last_move_x = false
  475.     end
  476.     if Mouse.press?(Mouse::LEFT)
  477.       last_moving = moving?
  478.       last_direction = @direction
  479.       unless moving? or $game_system.map_interpreter.running? or
  480.              @move_route_forcing or $game_temp.message_window_showing
  481.         last_x = @x
  482.         if @last_move_x
  483.           @last_move_x = false
  484.         elsif mouse_x > screen_x + 16
  485.           if mouse_y<screen_y-32
  486.             move_upper_right
  487.           elsif mouse_y>screen_y
  488.             move_lower_right
  489.             else
  490.           move_right
  491.           end
  492.         elsif mouse_x < screen_x - 16
  493.                     if mouse_y<screen_y-32
  494.             move_upper_left
  495.           elsif mouse_y>screen_y
  496.             move_lower_left
  497.             else
  498.           move_left
  499.           end
  500.         end
  501.         last_y = @y
  502.         if last_x != @x
  503.           @last_move_x = true
  504.         elsif mouse_y > screen_y
  505.                               if mouse_x<screen_x-16
  506.             move_lower_left
  507.           elsif mouse_x>screen_x+16
  508.             move_lower_right
  509.             else
  510.           move_down
  511.           end
  512.         elsif mouse_y < screen_y - 32
  513.                               if mouse_x<screen_x-16
  514.             move_upper_left
  515.           elsif mouse_x>screen_x+16
  516.             move_upper_right
  517.             else
  518.           move_up
  519.           end
  520.         end

  521.           if last_y != @y
  522.           @last_move_x = false
  523.         elsif not @last_move_x
  524.           case last_direction
  525.           when 2
  526.             turn_down
  527.           when 4
  528.             turn_left
  529.           when 6
  530.             turn_right
  531.           when 8
  532.             turn_up
  533.           end
  534.         end
  535.       end
  536.     end
  537.     self_update
  538.   end
  539. end
  540. Mouse.init
  541. END { Mouse.exit }
复制代码
走着走着就这样:脚本 '鼠标' 的 9 行 发生了 NoMethodError。

undefined method `size' for nil:NilClass

Lv2.观梦者

梦石
0
星屑
681
在线时间
791 小时
注册时间
2011-10-20
帖子
2394

开拓者

2
发表于 2012-6-11 21:10:14 | 只看该作者
list没定义,=nil你脚本好像不完整

点评

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊  发表于 2012-6-11 21:19
event.list这玩意没?还是没公开  发表于 2012-6-11 21:19
我师傅帮我做的、所以不清楚呢、 那么你知道哪里不完整么…………、  发表于 2012-6-11 21:13
欢迎点此进入我的egames.wink.ws,有RMQQ堂等

[url=http://rpg.blue/thread-317273-1-1.html]短篇八-赶选

http://yun.baidu.com/share/link?shareid=2158225779&uk=169642147&third=0


历险ARPG赢回你的疆域新的战斗模式?…………点击这里:[宋乱贼狂 for QQ堂]
http://rpg.blue/group-368-1.html
programing ....?
[url=http://rpg.blue/thrd-234658-1-1.html]
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
48
在线时间
773 小时
注册时间
2012-4-5
帖子
223
3
 楼主| 发表于 2012-6-11 21:41:17 | 只看该作者
end55rpg 发表于 2012-6-11 21:10
list没定义,=nil你脚本好像不完整

不知道……脚本盲……师傅现在也不在……、
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
123 小时
注册时间
2012-6-5
帖子
109
4
发表于 2012-6-12 13:12:36 | 只看该作者
我是脚本盲,看不懂
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-4 11:32

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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