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

Project1

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

[已经解决] RMXP后台运行脚本

[复制链接]

Lv1.梦旅人

梦石
0
星屑
85
在线时间
210 小时
注册时间
2013-7-26
帖子
346
跳转到指定楼层
1
发表于 2014-9-2 17:17:12 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
在6R有真·后台运行脚本,但有BUG。鼠标在离开游戏窗口后 点击 游戏也会触发点击 ,打开其他软件 覆盖在游戏窗口上面 点击 也会影响到游戏。这个应该是要获取句柄吧?不懂,下面是鼠标脚本
  1. #==============================================================================
  2. # ■ 完整鼠标系统(八方向)
  3. #------------------------------------------------------------------------------
  4. #  使用时务必配合专用寻路算法
  5. #   By whbm
  6. #   不若怀念修改
  7. #==============================================================================
  8. #下面做一下介绍与使用说明:
  9. #    在屏幕上单击鼠标的时候,会自动进行寻路,这里为了速度更快并且为了进行迷
  10. #宫时的难度寻路被限定在当时的屏幕内部。(否则玩家直接点到终点,呵呵....知道
  11. #后果了吧)
  12. #    在角色移动过程中再次单击鼠标(即双击)并在单击第二次鼠标的时候不松手,
  13. #角色将会跟随鼠标方向移动。(这个应该好理解,不用多说吧)当角色贴着欲被启动
  14. #的事件的时候,单击NPC即可启动事件。若未贴着,将会产生自动寻路到NPC附近的某
  15. #点,那时在单击NPC即可。
  16. #    当鼠标停在某些事件上时候会发现有不同的图标,设置方法为:宝箱事件请在事
  17. #件的执行内容中添加 注释,注释内容为 Item 注意大小写。NPC事件请在事件的执行
  18. #内容中添加 注释注释内容为 NPC 注意大小写。若不箱改变某事件的图标,则不要写
  19. #那两个注释。
  20. #    当把脚本转到您工程的时候千万别忘了那个寻路用的脚本。
  21. #==============================================================================
  22. class Game_Event
  23.   attr_accessor :flag
  24. end

  25. #==============================================================================
  26. # ■ Game_Map
  27. #------------------------------------------------------------------------------
  28. #  处理地图的类。包含卷动以及可以通行的判断功能。
  29. # 本类的实例请参考 $game_map 。
  30. #==============================================================================

  31. class Game_Map
  32.   #--------------------------------------------------------------------------
  33.   # ● 检查鼠标处是否有自定义的事件并返回类型
  34.   #--------------------------------------------------------------------------
  35.   def check_event_custom(mouse_x, mouse_y)
  36.     for event in $game_map.events.values #循环所有事件检查
  37.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / $c3_每一步的帧数
  38.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 8
  39.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  40.         if event.list != nil
  41.         for i in 0...event.list.size
  42.           if event.list[i].parameters[0] == "Item"  #类型判断
  43.             event.flag = 1
  44.           elsif event.list[i].parameters[0] == "Npc" #类型判断
  45.             event.flag = 2
  46.           else
  47.             event.flag = 0 if $game_player.get_mouse_sta != 2 #无标志
  48.           end
  49.           return event.flag #返回事件类型标志
  50.         end
  51.         end
  52.       end
  53.     end
  54.     return 0 if $game_player.get_mouse_sta != 2 #如果不是在跟随鼠标状态,则返回无标志
  55.     return $mouse_icon_id #使鼠标图不变化
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # ● 检查鼠标处是否有事件可以开启
  59.   #--------------------------------------------------------------------------
  60.   def check_event_custom_start(mouse_x, mouse_y)
  61.     for event in $game_map.events.values #循环所有事件检查
  62.       #事件角色图片宽度、高度
  63.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / $c3_每一步的帧数
  64.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 8
  65.       #判断是否鼠标在事件上
  66.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  67.         way_x = $game_player.x - event.x
  68.         way_y = $game_player.y - event.y
  69.         if [1,0,-1].include?($game_player.x-event.x) and [1,0,-1].include?($game_player.y-event.y)
  70.           for i in 0...event.list.size
  71.             if ["Item","Npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  72.               #判断主角朝向
  73.               if way_x == -1
  74.                 p_direction = 3 if way_y == -1
  75.                 p_direction = 6 if way_y == 0
  76.                 p_direction = 9 if way_y == 1
  77.               elsif way_x == 0
  78.                 p_direction = 2 if way_y == -1
  79.                 p_direction = 8 if way_y == 1
  80.               else
  81.                 p_direction = 1 if way_y == -1
  82.                 p_direction = 4 if way_y == 0
  83.                 p_direction = 7 if way_y == 1
  84.               end
  85.               event.start #开启事件
  86.               return 1, p_direction #返回即将开启事件以及角色朝向
  87.             end
  88.           end
  89.         end
  90.       end
  91.     end
  92.     return 0, 5 #返回不会开启事件以及角色朝向不变
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  96.   #--------------------------------------------------------------------------
  97.   def check_event_custom_exist(mouse_x, mouse_y)
  98.     for event in $game_map.events.values #循环所有事件检查
  99.       #事件角色图片宽度、高度
  100.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / $c3_每一步的帧数
  101.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 8
  102.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  103.         for i in 0...event.list.size
  104.           return 1, event if ["Item", "Npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  105.         end
  106.       end
  107.     end
  108.     return 0, event #返回不存在自定义事件,以及事件体
  109.   end
  110. end
  111. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  112. $敌人选框扩大 = 20
  113. $角色选框扩大 = 30


  114. #==============================================================================
  115. # ● API调用
  116. #==============================================================================
  117. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  118. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  119. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  120. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  121. $Window_HWND = $GetActiveWindow.call
  122. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  123. module Mouse  
  124. LEFT = 0x01
  125. RIGHT = 0x02

  126. def self.init(sprite = nil)
  127.    $ShowCursor.call(0)
  128.    
  129.    @show_cursor = false
  130.    
  131.    @mouse_sprite = Sprite.new
  132.    @mouse_sprite.z = 99999
  133.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Weapon01.png')

  134.    @left_press = false
  135.    @right_press = false
  136.    @left_trigger = false
  137.    @right_trigger = false
  138.    @left_repeat = false
  139.    @right_repeat = false
  140.    @click_lock = false
  141.    @wait_count = 8#待机动画循环时间
  142.    @mosue_pic = 1#鼠标待机动画编号
  143.    #鼠标点击动画
  144.    @chick_animation = RPG::Sprite.new
  145.    @ani_x = @chick_animation.x
  146.    @ani_y = @chick_animation.y
  147.    #更新
  148.    update
  149. end
  150. #------------------------------------------------------------------------------
  151. # 设置鼠标点击动画
  152. #------------------------------------------------------------------------------
  153. def self.animation(animation,x,y)
  154.    @ani_x = x
  155.    @ani_y = y
  156.    x -= $game_map.display_x / 4
  157.    y -= $game_map.display_y / 4
  158.    if animation == nil
  159.      @chick_animation.animation(nil,0)
  160.    else
  161.      @chick_animation.x = x
  162.      @chick_animation.y = y
  163.      @chick_animation.animation(animation,0)
  164.    end
  165. end
  166. #------------------------------------------------------------------------------
  167. # 更新鼠标点击动画
  168. #------------------------------------------------------------------------------
  169. def self.update_animation
  170.     if $scene.is_a?(Scene_Map)
  171.       x = @ani_x
  172.       y = @ani_y
  173.       x -= $game_map.display_x / 4
  174.       y -= $game_map.display_y / 4
  175.       @chick_animation.x, @chick_animation.y = x, y
  176.     end
  177.     @chick_animation.update
  178. end
  179. def self.exit
  180.    @mouse_sprite.bitmap.dispose
  181.    @mouse_sprite.dispose
  182.    @chick_animation.animation(nil,0)
  183.    @chick_animation.dispose
  184.    @show_cursor = true
  185.    $ShowCursor.call(1)
  186. end
  187. def self.mouse_debug
  188.    return @mouse_debug.bitmap
  189. end

  190. def self.update
  191.    update_animation
  192.    left_down = $GetKeyState.call(0x01)
  193.    right_down = $GetKeyState.call(0x02)
  194.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  195.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  196.      @a = !@a
  197.    end
  198.    if $scene.is_a?(Scene_Map) == false
  199.      $mouse_icon_id = 0
  200.    end
  201.    if $mouse_icon_id != $mouse_icon_id_last
  202.      case $mouse_icon_id
  203.      when 1
  204.        if @a
  205.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem1')
  206.        else
  207.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem2')
  208.        end
  209.      when 2
  210.        if @a
  211.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo1')
  212.        else
  213.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo2')
  214.        end
  215.      when 11
  216.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_LEFT')
  217.      when 12
  218.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_DOWN')
  219.      when 13
  220.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_RIGHT')
  221.      when 14
  222.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LEFT')
  223.      when 16
  224.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_RIGHT')
  225.      when 17
  226.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_LEFT')
  227.      when 18
  228.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UP')
  229.      when 19
  230.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_RIGHT')
  231.      when 0
  232.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/木剑')
  233.      end
  234.      $mouse_icon_id_last = $mouse_icon_id
  235.    end
  236.    if $mouse_icon_id == 0
  237.       if @wait_count <= 0
  238.         @mouse_sprite.bitmap = RPG::Cache.icon("mouse#{@mosue_pic}")
  239.         @mosue_pic += 1
  240.         if @mosue_pic >= 12
  241.           @mosue_pic = 1
  242.         end
  243.         @wait_count = 8
  244.       else
  245.         @wait_count -= 1
  246.       end
  247.    end
  248.    @click_lock = false
  249.    mouse_x, mouse_y = self.get_mouse_pos
  250.    if @mouse_sprite != nil
  251.      @mouse_sprite.x = mouse_x
  252.      @mouse_sprite.y = mouse_y
  253.    end
  254.    if left_down[7] == 1
  255.      @left_repeat = (not @left_repeat)
  256.      @left_trigger = (not @left_press)
  257.      @left_press = true
  258.    else
  259.      @left_press = false
  260.      @left_trigger = false
  261.      @left_repeat = false
  262.    end
  263.    if right_down[7] == 1
  264.      @right_repeat = (not @right_repeat)
  265.      @right_trigger = (not @right_press)
  266.      @right_press = true
  267.    else
  268.      @right_press = false
  269.      @right_trigger = false
  270.      @right_repeat = false
  271.    end
  272. end
  273. def self.get_mouse_pos
  274.    point_var = [0, 0].pack('ll')
  275.    if $GetCursorPos.call(point_var) != 0
  276.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  277.        x, y = point_var.unpack('ll')
  278.        if (x < 0) or (x > 10000) then x = 0 end
  279.        if (y < 0) or (y > 10000) then y = 0 end
  280.        if x > 640 then x = 640 end
  281.        if y > 480 then y = 480 end
  282.        return x, y
  283.      else
  284.        return 0, 0
  285.      end
  286.    else
  287.      return 0, 0
  288.    end
  289. end
  290. def self.press?(mouse_code)
  291.    if mouse_code == LEFT
  292.      if @click_lock
  293.        return false
  294.      else
  295.        return @left_press
  296.      end
  297.    elsif mouse_code == RIGHT
  298.      return @right_press
  299.    else
  300.      return false
  301.    end
  302. end
  303. def self.trigger?(mouse_code)
  304.    if mouse_code == LEFT
  305.      if @click_lock
  306.        return false
  307.      else
  308.        return @left_trigger
  309.      end
  310.    elsif mouse_code == RIGHT
  311.      return @right_trigger
  312.    else
  313.      return false
  314.    end
  315. end
  316. def self.repeat?(mouse_code)
  317.    if mouse_code == LEFT
  318.      if @click_lock
  319.        return false
  320.      else
  321.        return @left_repeat
  322.      end
  323.    elsif mouse_code == RIGHT
  324.      return @right_repeat
  325.    else
  326.      return false
  327.    end
  328. end
  329. def self.click_lock?
  330.    return @click_lock
  331. end
  332. def self.click_lock
  333.    @click_lock = true
  334. end
  335. def self.click_unlock
  336.    @click_lock = false
  337. end
  338. end
  339. module Input
  340. if @self_update == nil
  341.    @self_update = method('update')
  342.    @self_press = method('press?')
  343.    @self_trigger = method('trigger?')
  344.    @self_repeat = method('repeat?')
  345. end
  346. def self.update
  347.    @self_update.call
  348.    Mouse.update
  349. end
  350. def self.press?(key_code)
  351.    if @self_press.call(key_code)
  352.      return true
  353.    end
  354.    if key_code == C
  355.      return Mouse.press?(Mouse::LEFT)
  356.    elsif key_code == B
  357.      return Mouse.press?(Mouse::RIGHT)
  358.    else
  359.      return @self_press.call(key_code)
  360.    end
  361. end
  362. def self.trigger?(key_code)
  363.    if @self_trigger.call(key_code)
  364.      return true
  365.    end
  366.    if key_code == C
  367.      return Mouse.trigger?(Mouse::LEFT)
  368.    elsif key_code == B
  369.       
  370.      return Mouse.trigger?(Mouse::RIGHT)
  371.    else
  372.      return @self_trigger.call(key_code)
  373.    end
  374. end
  375. def self.repeat?(key_code)
  376.    if @self_repeat.call(key_code)
  377.      return true
  378.    end
  379.    if key_code == C
  380.      return Mouse.repeat?(Mouse::LEFT)
  381.    elsif key_code == B
  382.      return Mouse.repeat?(Mouse::RIGHT)
  383.    else
  384.      return @self_repeat.call(key_code)
  385.    end
  386. end
  387. end
  388. class Window_Selectable
  389. if @self_alias == nil
  390.    alias self_update update
  391.    @self_alias = true
  392. end
  393. def update
  394.    self_update
  395.    if self.active and @item_max > 0
  396.      index_var = @index
  397.      tp_index = @index
  398.      mouse_x, mouse_y = Mouse.get_mouse_pos
  399.      mouse_not_in_rect = true
  400.      for i in 0...@item_max
  401.        @index = i
  402.        update_cursor_rect
  403.        top_x = self.cursor_rect.x + self.x + 16
  404.        top_y = self.cursor_rect.y + self.y + 16
  405.        bottom_x = top_x + self.cursor_rect.width
  406.        bottom_y = top_y + self.cursor_rect.height
  407.        if (mouse_x > top_x) and (mouse_y > top_y) and
  408.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  409.          mouse_not_in_rect = false
  410.          if tp_index != @index
  411.             $game_system.se_stop
  412.            tp_index = @index
  413.            if @index == 0
  414.              if $title == 1
  415.                Audio.se_play("Audio/SE/"+"轮回",100,100)
  416.              else
  417.                $game_system.se_play($data_system.cursor_se)
  418.              end
  419.            elsif @index ==1
  420.              if $title == 1
  421.                Audio.se_play("Audio/SE/"+"拔剑",100,100)
  422.              else
  423.                $game_system.se_play($data_system.cursor_se)
  424.              end
  425.            elsif @index ==2
  426.              if $title == 1
  427.                Audio.se_play("Audio/SE/"+"退出",100,100)
  428.              else
  429.                $game_system.se_play($data_system.cursor_se)
  430.              end
  431.            else
  432.              $game_system.se_play($data_system.cursor_se)
  433.            end
  434.          end
  435.          break
  436.        end
  437.      end
  438.      if mouse_not_in_rect
  439.        @index = index_var
  440.        update_cursor_rect
  441.        Mouse.click_lock
  442.      else
  443.        Mouse.click_unlock               
  444.      end
  445.    end
  446. end
  447. end
  448. class Window_NameInput
  449. if @self_alias == nil
  450.    alias self_update update
  451.    @self_alias = true
  452. end
  453. def update
  454.    self_update
  455.    if self.active
  456.      index_var = @index
  457.      mouse_x, mouse_y = Mouse.get_mouse_pos
  458.      mouse_not_in_rect = true
  459.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  460.        @index = i
  461.        update_cursor_rect
  462.        top_x = self.cursor_rect.x + self.x + 16
  463.        top_y = self.cursor_rect.y + self.y + 16
  464.        bottom_x = top_x + self.cursor_rect.width
  465.        bottom_y = top_y + self.cursor_rect.height
  466.        if (mouse_x > top_x) and (mouse_y > top_y) and
  467.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  468.          mouse_not_in_rect = false
  469.          break
  470.        end
  471.      end
  472.      if mouse_not_in_rect
  473.        @index = index_var
  474.        update_cursor_rect
  475.        Mouse.click_lock
  476.      else
  477.        Mouse.click_unlock
  478.      end
  479.    end
  480. end
  481. end
  482. class Window_InputNumber
  483. if @self_alias == nil
  484.    alias self_update update
  485.    @self_alias = true
  486. end
  487. def update
  488.    self_update
  489.    mouse_x, mouse_y = Mouse.get_mouse_pos
  490.    if self.active and @digits_max > 0
  491.      index_var = @index
  492.      mouse_not_in_rect = true
  493.      for i in 0...@digits_max
  494.        @index = i
  495.        update_cursor_rect
  496.        top_x = self.cursor_rect.x + self.x + 16
  497.        bottom_x = top_x + self.cursor_rect.width
  498.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  499.          mouse_not_in_rect = false
  500.          break
  501.        end
  502.      end
  503.      if mouse_not_in_rect
  504.        @index = index_var
  505.        update_cursor_rect
  506.        Mouse.click_lock
  507.      else
  508.        Mouse.click_unlock
  509.      end
  510.    end
  511.    if @last_mouse_y == nil
  512.      @last_mouse_y = mouse_y
  513.    end
  514.    check_pos = (@last_mouse_y - mouse_y).abs
  515.    if check_pos > 10
  516.      $game_system.se_play($data_system.cursor_se)
  517.      place = 10 ** (@digits_max - 1 - @index)
  518.      n = @number / place % 10
  519.      @number -= n * place
  520.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  521.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  522.      @number += n * place
  523.      refresh
  524.      @last_mouse_y = mouse_y
  525.    end
  526. end
  527. end
  528. class Scene_File
  529. if @self_alias == nil
  530.    alias self_update update
  531.    @self_alias = true
  532. end
  533. def update
  534.    mouse_x, mouse_y = Mouse.get_mouse_pos
  535.    Mouse.click_lock
  536.    idx = 0
  537.    for i in @savefile_windows
  538.      top_x = i.x + 16
  539.      top_y = i.y + 16
  540.      bottom_x = top_x + i.width
  541.      bottom_y = top_y + i.height
  542.      if (mouse_x > top_x) and (mouse_y > top_y) and
  543.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  544.        i.selected = true
  545.        if @file_index != idx
  546.          @file_index = idx
  547.          $game_system.se_play($data_system.cursor_se)
  548.        end            
  549.        Mouse.click_unlock
  550.      else
  551.        i.selected = false
  552.      end
  553.      idx += 1
  554.    end
  555.    self_update
  556. end
  557. end
  558. class Arrow_Enemy
  559. if @self_alias == nil
  560.    alias self_update update
  561.    @self_alias = true
  562. end
  563. def update
  564.    mouse_x, mouse_y = Mouse.get_mouse_pos
  565.    idx = 0
  566.    for i in $game_troop.enemies do
  567.      if i.exist?
  568.        top_x = i.screen_x - self.ox
  569.        top_y = i.screen_y - self.oy
  570.        bottom_x = top_x + self.src_rect.width
  571.        bottom_y = top_y + self.src_rect.height
  572.        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  573.           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  574.          if @index != idx
  575.            $game_system.se_play($data_system.cursor_se)
  576.            @index = idx
  577.          end
  578.        end
  579.      end
  580.      idx += 1
  581.    end
  582.    self_update
  583. end
  584. end
  585. class Arrow_Actor
  586. if @self_alias == nil
  587.    alias self_update update
  588.    @self_alias = true
  589. end
  590. def update
  591.    mouse_x, mouse_y = Mouse.get_mouse_pos
  592.    idx = 0
  593.    for i in $game_party.actors do
  594.      if i.esc?
  595.        top_x = i.screen_x - self.ox
  596.        top_y = i.screen_y - self.oy
  597.        bottom_x = top_x + self.src_rect.width
  598.        bottom_y = top_y + self.src_rect.height
  599.        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  600.           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  601.          if @index != idx
  602.            $game_system.se_play($data_system.cursor_se)
  603.            @index = idx
  604.          end
  605.        end
  606.      end
  607.      idx += 1
  608.    end
  609.    self_update
  610. end
  611. end
  612. #==============================================================================
  613. # ■ Game_Player
  614. #------------------------------------------------------------------------------
  615. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  616. # 本类的实例请参考 $game_player。
  617. #   鼠标控制角色的主程序
  618. #==============================================================================
  619. class Game_Player
  620. if @self_alias == nil
  621.    alias self_update update
  622.    @self_alias = true
  623. end
  624. #--------------------------------------------------------------------------
  625. # ● 得到鼠标的状态
  626. #--------------------------------------------------------------------------
  627. def get_mouse_sta
  628.    return @mouse_sta
  629. end
  630. #--------------------------------------------------------------------------
  631. # ● 完整鼠标系统
  632. #--------------------------------------------------------------------------
  633. def update
  634.    mouse_x, mouse_y = Mouse.get_mouse_pos
  635.    @mtp_x = mouse_x
  636.    @mtp_y = mouse_y
  637.    unless $game_system.map_interpreter.running? and @mouse_sta == 2 #鼠标状态不为跟随状态
  638.      #得到鼠标图标方向
  639.      $mouse_icon_id = $game_map.check_event_custom(mouse_x,mouse_y)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
  640.    else
  641.      #令鼠标图标为正常
  642.      $mouse_icon_id = 0 if @mouse_sta != 2
  643.    end
  644.    
  645.    #单击鼠标时进行判断寻路或跟随
  646.    if Mouse.trigger?(Mouse::LEFT) #当点击鼠标时
  647.      unless $game_system.map_interpreter.running? or
  648.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  649.        #初始化
  650.        @mouse_sta = 1
  651.        p_direction = 5
  652.        #检查鼠标处能否开启事件
  653.        event_start,p_direction = $game_map.check_event_custom_start(mouse_x, mouse_y)
  654.        #若在移动中再次点击鼠标左键(即双击左键),则改鼠标状态为跟随状态
  655.        @mouse_sta = 2 if @paths_id != nil and @paths_id != @paths.size
  656.        if @mouse_sta != 2
  657.          #鼠标状态不为跟随状态则取数据并初始化路径
  658.          trg_x = (mouse_x + $game_map.display_x / 4) / 32
  659.          trg_y = (mouse_y + $game_map.display_y / 4) / 32
  660.          @paths = []
  661.          @paths_id = 0
  662.          if event_start == 0 #若不能开启事件
  663.            if trg_x != $game_player.x or trg_y != $game_player.y #若目标不为自身则开始寻路
  664.             #点中了宝宝
  665.             if mouse_x> 389 and mouse_x< 430 and mouse_y> 0 and mouse_y< 41
  666.               $scene = Scene_Baby.new
  667.             #点中了人物
  668.             elsif mouse_x> 510 and mouse_x< 564 and mouse_y> 0 and mouse_y< 53
  669.               common_event_id = 17
  670.               common_event = $data_common_events[common_event_id]
  671.               $game_system.map_interpreter.setup(common_event.list, 0)
  672.             #选中了道具
  673.             elsif mouse_x> 16 and mouse_x< 41 and mouse_y> 80 and mouse_y< 112
  674.               $scene = Scene_Item.new
  675.             #选中了任务
  676.             elsif mouse_x> 48 and mouse_x< 73 and mouse_y> 80 and mouse_y< 112
  677.               $scene = Scene_Task.new
  678.             #选中了系统
  679.             elsif mouse_x> 80 and mouse_x< 105 and mouse_y> 80 and mouse_y< 112
  680.               $scene = Scene_Menu.new
  681.             #选中了BB血槽
  682.             elsif mouse_x> 433 and mouse_x< 505 and mouse_y> 0 and mouse_y< 13
  683.               if $game_party.actors[0].baby != 0
  684.                 baby = $game_actors[$game_party.actors[0].baby]
  685.                 item_id = [2,11,16,17,18,19,20,21,22,23,34,35]
  686.                 if baby.hp < baby.maxhp
  687.                   for i in item_id
  688.                     if $game_party.item_number(i) > 0
  689.                       item = $data_items[i]
  690.                       num = [(baby.maxhp - baby.hp) / item.recover_hp + 1,$game_party.item_number(i)].min
  691.                       for n in 0...num
  692.                         if baby.hp == 0
  693.                           baby.hp = 1
  694.                         end
  695.                         baby.item_effect(item)
  696.                       end
  697.                       $game_party.lose_item(i, num)
  698.                       $game_system.se_play(item.menu_se)
  699.                       $scene.update_head
  700.                       break
  701.                     end
  702.                   end
  703.                 end
  704.               end
  705.             #选中了BB法槽
  706.             elsif mouse_x> 433 and mouse_x< 505 and mouse_y> 15 and mouse_y< 29
  707.               if $game_party.actors[0].baby != 0
  708.                 baby = $game_actors[$game_party.actors[0].baby]
  709.                 item_id = [12,24,25,26,27,28,29,30,31,32,33]
  710.                 if baby.sp < baby.maxsp
  711.                   for i in item_id
  712.                     if $game_party.item_number(i) > 0
  713.                       item = $data_items[i]
  714.                       num = [(baby.maxsp - baby.sp) / item.recover_sp + 1,$game_party.item_number(i)].min
  715.                       for n in 0...num
  716.                         if baby.hp == 0
  717.                           baby.hp = 1
  718.                         end
  719.                         baby.item_effect(item)
  720.                       end
  721.                       $game_party.lose_item(i, num)
  722.                       $game_system.se_play(item.menu_se)
  723.                       $scene.update_head
  724.                       break
  725.                     end
  726.                   end
  727.                 end
  728.               end
  729.             #选中了人物血槽
  730.             elsif mouse_x> 563 and mouse_x< 636 and mouse_y> 0 and mouse_y< 15
  731.                 baby = $game_party.actors[0]
  732.                 item_id = [2,11,16,17,18,19,20,21,22,23,34,35]
  733.                 if baby.hp < baby.maxhp
  734.                   for i in item_id
  735.                     if $game_party.item_number(i) > 0
  736.                       item = $data_items[i]
  737.                       num = [(baby.maxhp - baby.hp) / item.recover_hp + 1,$game_party.item_number(i)].min
  738.                       for n in 0...num
  739.                         if baby.hp == 0
  740.                           baby.hp = 1
  741.                         end
  742.                         baby.item_effect(item)
  743.                       end
  744.                       $game_party.lose_item(i, num)
  745.                       $game_system.se_play(item.menu_se)
  746.                       $scene.update_head
  747.                       break
  748.                     end
  749.                   end
  750.                 end
  751.             #选中了人物法曹
  752.             elsif mouse_x> 563 and mouse_x< 637 and mouse_y> 15 and mouse_y< 29
  753.                 baby = $game_party.actors[0]
  754.                 item_id = [12,24,25,26,27,28,29,30,31,32,33]
  755.                 if baby.sp < baby.maxsp
  756.                   for i in item_id
  757.                     if $game_party.item_number(i) > 0
  758.                       item = $data_items[i]
  759.                       num = [(baby.maxsp - baby.sp) / item.recover_sp + 1,$game_party.item_number(i)].min
  760.                       for n in 0...num
  761.                         if baby.hp == 0
  762.                           baby.hp = 1
  763.                         end
  764.                         baby.item_effect(item)
  765.                       end
  766.                       $game_party.lose_item(i, num)
  767.                       $game_system.se_play(item.menu_se)
  768.                       $scene.update_head
  769.                       break
  770.                     end
  771.                   end
  772.                 end
  773.             else
  774.               if $scene.is_a?(Scene_Map)
  775.                 Mouse.animation($data_animations[138],mouse_x + 14 + $game_map.display_x / 4, mouse_y + 10 + $game_map.display_y / 4)
  776.               end
  777.              find_path = Find_Path.new
  778.              @paths = find_path.find_player_short_path(trg_x, trg_y, @mtp_x, @mtp_y)
  779.             end
  780.           end
  781.          else #若能开启事件则改变角色朝向
  782.            @direction = p_direction
  783.          end
  784.        end
  785.      end
  786.    elsif Mouse.trigger?(Mouse::RIGHT)
  787.      unless $game_system.map_interpreter.running? or
  788.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  789.         if @mtp_x > self.screen_x
  790.            if @mtp_y - self.screen_y > - 0.4 * ( @mtp_x - self.screen_x ) and
  791.               @mtp_y - self.screen_y < 0.4 * ( @mtp_x - self.screen_x )
  792.              @direction = 6
  793.            end
  794.            if @mtp_y - self.screen_y > 0.4 * ( @mtp_x - self.screen_x ) and
  795.              @mtp_y - self.screen_y < 2.4 * ( @mtp_x - self.screen_x )
  796.              @direction = 3
  797.            end
  798.            if @mtp_y - self.screen_y < - 0.4 * ( @mtp_x - self.screen_x ) and
  799.              @mtp_y - self.screen_y > - 2.4 * ( @mtp_x - self.screen_x )
  800.              @direction = 9
  801.            end
  802.            if @mtp_y - self.screen_y > 2.4 * ( @mtp_x - self.screen_x )
  803.              @direction = 2
  804.            end
  805.            if @mtp_y - self.screen_y < - 2.4 * ( @mtp_x - self.screen_x )
  806.              @direction = 8
  807.            end
  808.          end
  809.        if @mtp_x < self.screen_x
  810.          if @mtp_y - self.screen_y > - 0.4 * ( self.screen_x - @mtp_x ) and
  811.             @mtp_y - self.screen_y < 0.4 * ( self.screen_x - @mtp_x )
  812.            @direction = 4
  813.          end
  814.          if @mtp_y - self.screen_y > 0.4 * ( self.screen_x - @mtp_x ) and
  815.            @mtp_y - self.screen_y < 2.4 * ( self.screen_x - @mtp_x )
  816.            @direction = 1
  817.          end
  818.          if @mtp_y - self.screen_y < - 0.4 * ( self.screen_x - @mtp_x ) and
  819.            @mtp_y - self.screen_y > - 2.4 * ( self.screen_x - @mtp_x )
  820.            @direction = 7
  821.          end
  822.          if @mtp_y - self.screen_y > 2.4 * ( self.screen_x - @mtp_x )
  823.            @direction = 2
  824.          end
  825.          if @mtp_y - self.screen_y < - 2.4 * ( self.screen_x - @mtp_x )
  826.            @direction = 8
  827.          end
  828.        end   
  829.      end
  830.    end

  831.    #开始移动
  832.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  833.      unless moving? or $game_system.map_interpreter.running? or
  834.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  835.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  836.          case @paths[@paths_id] #判断路径
  837.          when 6
  838.            @last_move_x = true
  839.            move_right
  840.            @paths_id += 1
  841.            @direction = 6
  842.          when 4
  843.            @last_move_x = true
  844.            move_left
  845.            @paths_id += 1
  846.            @direction = 4
  847.          when 2
  848.            @last_move_x = false
  849.            move_down
  850.            @direction = 2
  851.            @paths_id += 1
  852.          when 8
  853.            @last_move_x = false
  854.            move_up
  855.            @direction = 8
  856.            @paths_id += 1
  857.          #斜四方向
  858.          when 1
  859.            @last_move_x = false
  860.            move_lower_left
  861.            @direction = 1
  862.            @paths_id += 1
  863.          when 3
  864.            @last_move_x = false
  865.            move_lower_right
  866.            @direction = 3
  867.            @paths_id += 1
  868.          when 7
  869.            @last_move_x = false
  870.            move_upper_left
  871.            @direction = 7
  872.            @paths_id += 1
  873.          when 9
  874.            @last_move_x = false
  875.            move_upper_right
  876.            @direction = 9
  877.            @paths_id += 1
  878.          end
  879.        end
  880.      end
  881.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  882.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  883.        unless moving? or $game_system.map_interpreter.running? or
  884.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  885.          #跟随方向判断并跟随
  886.          if @mtp_x > self.screen_x
  887.            if @mtp_y - self.screen_y > - 0.4 * ( @mtp_x - self.screen_x ) and
  888.               @mtp_y - self.screen_y < 0.4 * ( @mtp_x - self.screen_x )
  889.              move_right
  890.              $mouse_icon_id = 16
  891.              @direction = 6
  892.            end
  893.            if @mtp_y - self.screen_y > 0.4 * ( @mtp_x - self.screen_x ) and
  894.              @mtp_y - self.screen_y < 2.4 * ( @mtp_x - self.screen_x )
  895.              move_lower_right
  896.              $mouse_icon_id = 13
  897.              @direction = 3
  898.            end
  899.            if @mtp_y - self.screen_y < - 0.4 * ( @mtp_x - self.screen_x ) and
  900.              @mtp_y - self.screen_y > - 2.4 * ( @mtp_x - self.screen_x )
  901.              move_upper_right
  902.              $mouse_icon_id = 19
  903.              @direction = 9
  904.            end
  905.            if @mtp_y - self.screen_y > 2.4 * ( @mtp_x - self.screen_x )
  906.              move_down
  907.              $mouse_icon_id = 12
  908.              @direction = 2
  909.            end
  910.            if @mtp_y - self.screen_y < - 2.4 * ( @mtp_x - self.screen_x )
  911.              move_up
  912.              $mouse_icon_id = 18
  913.              @direction = 8
  914.            end
  915.          end
  916.        if @mtp_x < self.screen_x
  917.          if @mtp_y - self.screen_y > - 0.4 * ( self.screen_x - @mtp_x ) and
  918.             @mtp_y - self.screen_y < 0.4 * ( self.screen_x - @mtp_x )
  919.            move_left
  920.            $mouse_icon_id = 14
  921.            @direction = 4
  922.          end
  923.          if @mtp_y - self.screen_y > 0.4 * ( self.screen_x - @mtp_x ) and
  924.            @mtp_y - self.screen_y < 2.4 * ( self.screen_x - @mtp_x )
  925.            move_lower_left
  926.            $mouse_icon_id = 11
  927.            @direction = 1
  928.          end
  929.          if @mtp_y - self.screen_y < - 0.4 * ( self.screen_x - @mtp_x ) and
  930.            @mtp_y - self.screen_y > - 2.4 * ( self.screen_x - @mtp_x )
  931.            move_upper_left
  932.            $mouse_icon_id = 17
  933.            @direction = 7
  934.          end
  935.          if @mtp_y - self.screen_y > 2.4 * ( self.screen_x - @mtp_x )
  936.            move_down
  937.            $mouse_icon_id = 12
  938.            @direction = 2
  939.          end
  940.          if @mtp_y - self.screen_y < - 2.4 * ( self.screen_x - @mtp_x )
  941.            move_up
  942.            $mouse_icon_id = 18
  943.            @direction = 8
  944.          end
  945.        end
  946.      end
  947.    else #没状态的情况
  948.      $mouse_icon_id = 0
  949.      @mouse_sta = 0
  950.      @paths_id = @paths.size #终止寻路移动
  951.    end
  952. end
  953. self_update
  954. end
  955. end
  956. Mouse.init
  957. END { Mouse.exit }
复制代码

Lv1.梦旅人

派大星

梦石
0
星屑
195
在线时间
2133 小时
注册时间
2011-9-18
帖子
2652
2
发表于 2014-9-2 23:53:48 | 只看该作者
本帖最后由 无双sxa 于 2014-9-3 00:15 编辑


进行研究并测试了一段时间,终于解决了
RUBY 代码复制
  1. def self.update
  2.    left_down = $GetKeyState.call(0x01)
  3.    right_down = $GetKeyState.call(0x02)
  4.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  5.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  6.      @a = !@a
  7.    end


找到鼠标脚本中的以上代码,把上面的部分
换成

RUBY 代码复制
  1. def self.update
  2.   if $_OnFocus.call != 0
  3. left_down = $GetKeyState.call(0x01)
  4. right_down = $GetKeyState.call(0x02)
  5. else
  6. left_down = 0
  7. right_down = 0
  8. end

其实解决办法来自这位前辈,不过因为各种报错,还是研究了一阵,囧
https://rpg.blue/thread-333516-1-1.html
顺便附上范例,虽然明显偷懒的,囧。 Project1.rar (517.86 KB, 下载次数: 88)

点评

我解决了,我用事件做了小地图。。  发表于 2014-9-4 12:50
我是渣渣水平啦,个人能力有限,更多问题需要楼主努力了,加油:)  发表于 2014-9-3 21:26
事件啊,只要不是一下搞几十上百个复杂的事件,咱还是很信赖RM的,有位前辈做了个游戏《惩罚者杰克》纯事件来着,很强大。  发表于 2014-9-3 21:25
事件可以做到,但会不会卡呢? 太多并行处理。对了 事件用等待多少帧会不会影响游戏的流畅?  发表于 2014-9-3 21:21
使用脚本前先考虑事件能否做到吧,不一定非要用脚本的,如果事件已经可以做到的话会方便很多。  发表于 2014-9-3 20:39

评分

参与人数 1梦石 +1 收起 理由
RyanBern + 1 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-22 00:59

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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