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

Project1

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

[转载发布] 超级简单鼠标脚本系统 ——作者:Shaz,可适用于Joiplay

[复制链接]

Lv2.观梦者

梦石
0
星屑
439
在线时间
31 小时
注册时间
2020-6-4
帖子
52
跳转到指定楼层
1
发表于 2023-10-1 18:01:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
VX ACE能很好支持鼠标脚本,更多介绍参考:https://forums.rpgmakerweb.com/i ... stem-for-ace.17829/

脚本代码链接:https://pastebin.com/raw/TxKQa3WK

RPG编辑器新建脚本,放入代码保存即可

个人对他的代码作了一些修改,使Joiplay不报错运行,但有些小缺陷,不如MV自带的鼠标系统好用:
RUBY 代码复制
  1. #============================================================================
  2. # SUPER SIMPLE MOUSE SCRIPT
  3. # v1.10 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This is a conversion of the XP Mouse script by Near Fantastica and
  6. # SephirothSpawn modified by Amaranth Games, to run under VX Ace.
  7. #----------------------------------------------------------------------------
  8. # To Install:
  9. # Copy and paste into a new slot in materials, below all other scripts
  10. #----------------------------------------------------------------------------
  11. # To Customize:
  12. # Add keyword icon index pairs to the ICON hash (below this documentation).  
  13. # Each of the keywords can be used in an event comment to make the mouse
  14. # cursor change into that icon when hovering over the event.
  15. #----------------------------------------------------------------------------
  16. # To Use:
  17. # Add the following comment to an event page:
  18. #   <mouse icon [x y] [name]>
  19. #   where icon is the keyword from the ICON hash below
  20. #   x and y are the offsets to override player movement (optional)
  21. #   name is the text to display next to the icon when hovering over the event (optional)
  22. #
  23. # Examples:
  24. # <mouse fight>
  25. #   will change the cursor into the 'fight' icon when over the event
  26. # <mouse touch 0 1>
  27. #   will change the cursor into the 'touch' icon when over the event, and
  28. #   make the player walk to the tile below the event when the mouse button is
  29. #   clicked
  30. # <mouse talk Gloria>
  31. #   will change the cursor into the 'talk' icon and display the name Gloria
  32. # <mouse talk 0 2 Henry Smith>
  33. #   will change the cursor into the 'talk' icon and display the name Henry Smith,
  34. #   and when the mouse button is clicked, the player will walk to the tile
  35. #   two below the event (good to use for shops where there's a counter in between)
  36. #
  37. # To force pathfinding on the player or an event, simply add a move route with
  38. # the player or event as the subject, with a Script command, and call
  39. # find_path(x, y) where x and y are the coordinates of the tile you want to move to
  40. # Examples:
  41. # Set Move Route (Player): Script: find_path(5, 8)
  42. #   will make the player find a path to tile 5, 8
  43. # Set Move Route (This Event): Script: find_path(10, 5)
  44. #   will make the event find a path to tile 10, 5
  45. #
  46. # NOTE: The path will be ATTEMPTED.  If there is no path TO that exact tile,
  47. # a path to an adjacent tile will be attempted.  If no path is found there
  48. # either, no movement will occur.
  49. # If a route is found, the player or event will begin moving towards it.  But
  50. # if their path is blocked while they are moving, movement will be cancelled.
  51. #----------------------------------------------------------------------------
  52. # Author's Notes:
  53. # This script should work with any RTP script.
  54. # I do not guarantee that it will work with ANY other script (especially anything
  55. # that overrides player or event movement, such as pixel movement scripts, or
  56. # custom window scripts).
  57. #
  58. # Script OVERWRITES the following methods:
  59. # Game_Map.setup_starting_map_event
  60. # Game_Map.setup_autorun_common_event
  61. #
  62. # If you have other scripts that ALIAS these methods, this mouse script should
  63. # be placed above them.
  64. #----------------------------------------------------------------------------
  65. # Terms:
  66. # Use in free and commercial games
  67. # Credit: Near Fantastica, SephirothSpawn, Amaranth Games, Shaz
  68. #----------------------------------------------------------------------------
  69. # Versions:
  70. # 1.0  -  6 Sept 2013 - initial release
  71. # 1.02 -  7 Sept 2013 - fixed crash when loading games saved prior to adding script
  72. #                     - fixed player gets stuck on impassable area on world map
  73. #                       when clicking while leaving air ship
  74. # 1.03 -  8 Sept 2013 - fixed actor moving to diagonal tile instead of adjacent
  75. # 1.04 - 10 Sept 2013 - fixed vehicle pathfinding on world map
  76. #                     - fixed event trigger when no path found
  77. # 1.05 - 14 Sept 2013 - tweaked accessing of tilemap offset
  78. # 1.06 -  3 Nov  2013 - disabled mouse movement when waiting for NPC move route
  79. #                     - fixed events not triggering after player finishes walking
  80. # 1.07 -  6 Nov  2013 - slow down mouse scrolling, and don't loop save files
  81. # 1.08 - 24 Nov  2013 - cater for YEA Core large resolution with too-small maps
  82. #                     - fixed early event activation bug introduced in 1.06
  83. #                     - replaced calc of Windows_Selectable boundaries with item_rect
  84. #                     - added ability to completely disable mouse
  85. # 1.09 - 21 Dec  2013 - fixed mouse re-enable when calling common events
  86. # 1.10 -  6 Apr  2014 - add interaction for top part of > 32pixel high event
  87. #                     - activate an event without walking up to it
  88. #                       (add <autoactivate> comment at top of event page)
  89. #                     - arrow keys override mouse movement when pathfinding
  90. #                     - ignore mouse in menus when using keyboard
  91. #                     - make player walk to counter opposite shopkeepers
  92. #============================================================================
  93.  
  94.  
  95.  
  96. #============================================================================
  97. # SUPER SIMPLE MOUSE SCRIPT
  98. # Mouse Sprite
  99. #============================================================================
  100.  
  101. # Add/remove/change icon names here.  The icon name is what will be used in the
  102. # event <mouse ...> command to show a different mouse icon when hovering over
  103. # the event.  These MUST be in lower case here!
  104. ICON = {'arrow' => 386, 'talk' => 4, 'look' => 3, 'fight' => 116,
  105.         'touch' => 491, 'exit' => 121}
  106. DEFAULT_ICON = 'arrow'
  107. # 在此处添加/删除/更改图标名称。图标名称是 # 事件  命令中使用的名称,用于在将鼠标悬停在 # 事件上时显示不同的鼠标图标。这些在这里必须是小写的!图标 = {'箭头' => 386, '谈话' => 4, '看' => 3, '战斗' => 116, '触摸' => 491, '退出' => 121} DEFAULT_ICON = '箭头'
  108. class Sprite_Mouse < Sprite
  109.   #--------------------------------------------------------------------------
  110.   # * Initialization
  111.   #--------------------------------------------------------------------------
  112.   def initialize
  113.     super
  114.     self.z = 10100
  115.     self.ox = 4
  116.     update
  117.     @dummy = Bitmap.new(32, 32)
  118.     self.bitmap = Bitmap.new(32, 32)
  119.     @enabled = true
  120.     @ignored = false
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Frame Update
  124.   #--------------------------------------------------------------------------
  125.   def update
  126.     return if !@enabled
  127.     super
  128.     if !SceneManager.scene.nil?
  129.       if !Mouse.position.nil?
  130.         mx, my = *Mouse.position
  131.         if @cursor == DEFAULT_ICON
  132.           self.x = mx unless mx.nil?
  133.         else
  134.           self.x = [mx, Graphics.width - self.bitmap.width].min unless mx.nil?
  135.         end
  136.         self.y = my unless my.nil?
  137.       end
  138.       if @scene != SceneManager.scene.class || Mouse.trigger?
  139.         @scene = SceneManager.scene.class
  140.         set_bitmap
  141.       end
  142.     end
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Set Bitmap
  146.   #--------------------------------------------------------------------------
  147.   def set_bitmap(cursor = DEFAULT_ICON, text = nil)
  148.     if @ignored
  149.       cursor = DEFAULT_ICON
  150.       text = nil
  151.     end
  152.  
  153.     if @cursor != cursor || @text != text
  154.       @cursor = cursor
  155.       @text = text
  156.       item_cursor = ICON[cursor]
  157.       rect = Rect.new(item_cursor % 16 * 24, item_cursor / 16 * 24, 24, 24)
  158.       if @text.nil?
  159.         self.bitmap = Bitmap.new(24, 32)
  160.         self.bitmap.blt(0, 0, Cache.system('Iconset'), rect)
  161.       else
  162.         w = @dummy.text_size(@text).width
  163.         h = @dummy.font.size
  164.         bitmap = Bitmap.new(26 + w, [32, h+2].max)
  165.         bitmap.font.size = @dummy.font.size
  166.         bitmap.font.shadow = true
  167.         if self.x + 26 + w > Graphics.width
  168.           bitmap.draw_text(0, 0, w, h, @text)
  169.           bitmap.blt(w, 0, Cache.system('Iconset'), rect)
  170.         else
  171.           bitmap.blt(0, 0, Cache.system('Iconset'), rect)
  172.           bitmap.draw_text(26, 0, w, h, @text)
  173.         end
  174.         self.bitmap = bitmap
  175.       end
  176.     end
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # * Update Event Cursors
  180.   #--------------------------------------------------------------------------
  181.   def update_event_cursors
  182.     # Remove mouse icon and text if we're off the grid
  183.     if Mouse.grid.nil?
  184.       set_bitmap
  185.       return
  186.     end
  187.     # Set cursor and text according to event
  188.     x, y = *Mouse.grid
  189.     event = $game_map.lowest_mouse_event_xy(x, y)
  190.     unless event.nil? && y < 410
  191.       if !event.mouse_icon.nil? || !event.mouse_text.nil?
  192.         set_bitmap(event.mouse_icon, event.mouse_text)
  193.         return
  194.       end
  195.     end
  196.     # default bitmap if not over an event
  197.     set_bitmap
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # * Enable Mouse
  201.   #--------------------------------------------------------------------------
  202.   def enabled=(value)
  203.     @enabled = value
  204.     self.visible = value
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # * Mouse Enabled?
  208.   #--------------------------------------------------------------------------
  209.   def enabled?
  210.     @enabled
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Ignore Mouse
  214.   #--------------------------------------------------------------------------
  215.   def ignored=(value)
  216.     @ignored = value
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # * Mouse Ignored?
  220.   #--------------------------------------------------------------------------
  221.   def ignored?
  222.     @ignored
  223.   end
  224. end
  225. $mouse = Sprite_Mouse.new
  226.  
  227.  
  228.  
  229. #============================================================================
  230. # SUPER SIMPLE MOUSE SCRIPT
  231. # Mouse Module
  232. #============================================================================
  233.  
  234. #==============================================================================
  235. # ** Mouse Module
  236. #------------------------------------------------------------------------------
  237. #  by Near Fantastica and SephirothSpawn
  238. #  adapted and converted to VX Ace by Shaz
  239. #==============================================================================
  240. module Mouse
  241.   #--------------------------------------------------------------------------
  242.   # * Mouse to Input Triggers
  243.   #   key => Input::KeyCONSTANT (key: 0 - left, 1 - middle, 2 - right)
  244.   #--------------------------------------------------------------------------
  245.   Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
  246.   #--------------------------------------------------------------------------
  247.   # * API Declarations
  248.   #--------------------------------------------------------------------------
  249.   GAKS = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  250.   GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
  251.   Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  252.   Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  253.   Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  254.   Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  255.   Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  256.   ShowCursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
  257.   #--------------------------------------------------------------------------
  258.   # * Module Variables
  259.   #--------------------------------------------------------------------------
  260.   @triggers = [[0, 1], [0, 2], [0, 4]]
  261.   @old_pos = 0
  262.   @pos_i = 0
  263.   @sys_cursor_visible = false
  264.   #--------------------------------------------------------------------------
  265.   # * Mouse Grid Position
  266.   #--------------------------------------------------------------------------
  267.   def self.grid
  268.     return nil if @pos.nil?
  269.     mx, my = SceneManager.scene.instance_variable_get(:@spriteset).tilemap_offset
  270.     x = (@pos[0] + mx) / 32
  271.     y = (@pos[1] + my) / 32
  272.     return [x, y]
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # * Mouse Position
  276.   #--------------------------------------------------------------------------
  277.   def self.position
  278.     return @pos.nil? ? [0, 0] : @pos
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * Mouse Global Position
  282.   #--------------------------------------------------------------------------
  283.   def self.global_pos
  284.     pos = [0, 0].pack('ll')
  285.     return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # * Screen to Client
  289.   #--------------------------------------------------------------------------
  290.   def self.screen_to_client(x=0, y=0)
  291.     pos = [x, y].pack('ll')
  292.     return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # * Mouse Position
  296.   #--------------------------------------------------------------------------
  297.   def self.pos
  298.     gx, gy = global_pos
  299.     x, y = screen_to_client(gx, gy)
  300.  
  301.     # Test boundaries
  302.     begin
  303.       if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
  304.         return x, y
  305.       else
  306.         return -20, -20
  307.       end
  308.     rescue
  309.       return 0, 0
  310.     end
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # * Update Mouse Position
  314.   #--------------------------------------------------------------------------
  315.   def self.update
  316.     old_pos = @pos
  317.     @pos = self.pos
  318.  
  319.     # Has mouse been moved?
  320.     if old_pos != @pos
  321.       Input.method = :mouse
  322.     end
  323.  
  324.     # Which mouse to show - custom, or system?
  325.     if $mouse.enabled? == @sys_cursor_visible
  326.       @sys_cursor_visible = !@sys_cursor_visible
  327.       ShowCursor.call(@sys_cursor_visible ? 1 : 0)
  328.     end
  329.  
  330.     return if !$mouse.enabled?
  331.  
  332.     # Leaving / Entering Range?
  333.     if old_pos != [-20, -20] && @pos == [-20, -20] # leaving range
  334.       ShowCursor.call(1)
  335.     elsif old_pos == [-20, -20] && @pos != [-20, -20] # entering range
  336.       ShowCursor.call(0)
  337.     end
  338.  
  339.     # Update Triggers
  340.     for i in @triggers
  341.       n = GAKS.call(i[1])
  342.       if [0, 1].include?(n)
  343.         i[0] = (i[0] > 0 ? i[0] * -1 : 0)
  344.       else
  345.         i[0] = (i[0] > 0 ? i[0] + 1 : 1)
  346.       end
  347.     end
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Trigger?
  351.   #   id : 0:Left, 1:Right, 2:Center
  352.   #--------------------------------------------------------------------------
  353.   def self.trigger?(id = 0)
  354.     if pos != [-20, -20]
  355.       return @triggers[id][0] == 1
  356.     end
  357.     return false
  358.   end
  359.   #--------------------------------------------------------------------------
  360.   # * Repeat?
  361.   #   id : 0:Left, 1:Right, 2:Center
  362.   #--------------------------------------------------------------------------
  363.   def self.repeat?(id = 0)
  364.     return @triggers[id][0] > 0 && @triggers[id][0] % 5 == 1
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # * Hwnd
  368.   #--------------------------------------------------------------------------
  369.   def self.hwnd
  370.     if @hwnd.nil?
  371.       title = "\0" * 256
  372.       Readini.call('Game', 'Title', '', title, 255, '.\\Game.ini')
  373.  
  374.       @hwnd = Findwindow.call('RGSS Player', title)
  375.       ShowCursor.call(0)
  376.     end
  377.     return @hwnd
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * Client Size
  381.   #--------------------------------------------------------------------------
  382.   def self.client_size
  383.     rect = [0, 0, 0, 0].pack('l4')
  384.     Client_rect.call(self.hwnd, rect)
  385.     return rect.unpack('l4')[2..3]
  386.   end
  387. end
  388.  
  389.  
  390.  
  391. #============================================================================
  392. # SUPER SIMPLE MOUSE SCRIPT
  393. # Input
  394. #============================================================================
  395.  
  396. class << Input
  397.   #--------------------------------------------------------------------------
  398.   # * Public Instance Variables
  399.   #--------------------------------------------------------------------------
  400.   attr_accessor :method
  401.   #--------------------------------------------------------------------------
  402.   # * Alias Listings
  403.   #--------------------------------------------------------------------------
  404.   alias :seph_mouse_input_update :update
  405.   alias :seph_mouse_input_trigger? :trigger?
  406.   alias :seph_mouse_input_repeat? :repeat?
  407.   #--------------------------------------------------------------------------
  408.   # * Frame Update
  409.   #--------------------------------------------------------------------------
  410.   def update
  411.     $mouse.update
  412.     Mouse.update
  413.     seph_mouse_input_update
  414.     # Are we using the mouse or the keyboard?
  415.     @method = :keyboard if dir4 != 0 || dir8 != 0
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # * Trigger? Test
  419.   #--------------------------------------------------------------------------
  420.   def trigger?(constant)
  421.     return true if seph_mouse_input_trigger?(constant)
  422.     if $mouse.enabled? && !Mouse.pos.nil?
  423.       if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
  424.         return true if Mouse.trigger?(Mouse::Mouse_to_Input_Triggers.index(constant))
  425.       end
  426.     end
  427.     return false
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # * Repeat? Test
  431.   #--------------------------------------------------------------------------
  432.   def repeat?(constant)
  433.     return true if seph_mouse_input_repeat?(constant)
  434.     if $mouse.enabled? && !Mouse.pos.nil?
  435.       if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
  436.         return true if Mouse.repeat?(Mouse::Mouse_to_Input_Triggers.index(constant))
  437.       end
  438.     end
  439.     return false
  440.   end
  441. end
  442.  
  443.  
  444.  
  445. #============================================================================
  446. # SUPER SIMPLE MOUSE SCRIPT
  447. # Map
  448. #============================================================================
  449.  
  450. class Spriteset_Map
  451.   #--------------------------------------------------------------------------
  452.   # * Tilemap Offset
  453.   #--------------------------------------------------------------------------
  454.   def tilemap_offset
  455.     if $imported && $imported["YEA-CoreEngine"]
  456.       [@tilemap.ox - @viewport1.rect.x, @tilemap.oy - @viewport1.rect.y]
  457.     else
  458.       [@tilemap.ox, @tilemap.oy]
  459.     end
  460.   end
  461. end
  462. class Game_Map
  463.   #--------------------------------------------------------------------------
  464.   # * Detect/Set Up Starting Map Event
  465.   #--------------------------------------------------------------------------
  466.   def setup_starting_map_event
  467.     event = @events.values.find {|event| event.starting }
  468.     event.clear_starting_flag if event
  469.     @interpreter.setup(event.list, event.id, event.trigger_in?([0,1,2,3])) if event
  470.     event
  471.   end
  472.   #--------------------------------------------------------------------------
  473.   # * Detect/Set Up Autorun Common Event
  474.   #--------------------------------------------------------------------------
  475.   def setup_autorun_common_event
  476.     event = $data_common_events.find do |event|
  477.       event && event.autorun? && $game_switches[event.switch_id]
  478.     end
  479.     @interpreter.setup(event.list, 0, true) if event
  480.     event
  481.   end
  482.   #--------------------------------------------------------------------------
  483.   # * Get ID of Lowest Mouse-enabled Event at Designated Coordinates
  484.   #--------------------------------------------------------------------------
  485.   def lowest_mouse_event_xy(x, y)
  486.     list = events_xy(x, y) + events_xy(x, y+1)
  487.     list.sort! {|a, b| b.y - a.y}
  488.     evt = nil
  489.     list.each do |event|
  490.       if (event.pos?(x, y) || (event.pos?(x, y+1) && event.height > 32)) &&
  491.         (evt.nil? || event.y > evt.y)
  492.         evt = event
  493.         break
  494.       end
  495.     end
  496.     return evt
  497.   end
  498. end
  499. class Scene_Map
  500.   #--------------------------------------------------------------------------
  501.   # * Frame Update
  502.   #--------------------------------------------------------------------------
  503.   alias shaz_mouse_scene_map_update update
  504.   def update
  505.     $mouse.update_event_cursors
  506.     shaz_mouse_scene_map_update
  507.   end
  508. end
  509.  
  510.  
  511.  
  512. #============================================================================
  513. # SUPER SIMPLE MOUSE SCRIPT
  514. # Event
  515. #============================================================================
  516.  
  517. module RPG
  518.   class Event
  519.     class Page
  520.       #--------------------------------------------------------------------
  521.       # * Public Instance Variables
  522.       #--------------------------------------------------------------------
  523.       attr_reader :mouse_icon
  524.       attr_reader :mouse_text
  525.       attr_reader :mouse_position
  526.       attr_reader :mouse_autoactivate
  527.       #--------------------------------------------------------------------
  528.       # * Build Stats
  529.       #--------------------------------------------------------------------
  530.       def build_stats
  531.         # Mouse icons (icon mandatory, others optional)
  532.         # <mouse icon destx desty name>
  533.         @mouse_icon = nil
  534.         @mouse_text = nil
  535.         @mouse_position = [0, 0]
  536.         @mouse_autoactivate = false
  537.         # look for mouse instructions
  538.         list.each do |command|
  539.           if [108, 408].include?(command.code)
  540.             comment = command.parameters[0]
  541.               case comment
  542.               when /<mouse/i
  543.                 params = /<mouse (.*)>/i.match(comment)[1].split(' ')
  544.                 @mouse_icon = params.shift
  545.                 if params.size > 1 && params[0] =~ /\d+/ && params[1] =~ /\d+/
  546.                   @mouse_position = [params.shift.to_i, params.shift.to_i]
  547.                 end
  548.                 if params.size > 0
  549.                   @mouse_text = params.join(' ')
  550.                 end
  551.               when /<autoactivate>/
  552.                 @mouse_autoactivate = true
  553.               end
  554.           end #if
  555.         end #do
  556.       end #def
  557.     end
  558.   end
  559. end
  560. class Game_Event < Game_Character
  561.   #--------------------------------------------------------------------------
  562.   # * Public Instance Variables
  563.   #--------------------------------------------------------------------------
  564.   attr_reader   :mouse_icon
  565.   attr_reader   :mouse_text
  566.   attr_reader   :mouse_position
  567.   attr_reader   :mouse_autoactivate
  568.   #--------------------------------------------------------------------------
  569.   # * Start Event
  570.   #--------------------------------------------------------------------------
  571.   alias shaz_mouse_game_event_start start
  572.   def start
  573.     $game_player.start_event(@id) if !empty?
  574.     shaz_mouse_game_event_start
  575.   end
  576.   #--------------------------------------------------------------------------
  577.   # * Clear Event Page Settings
  578.   #--------------------------------------------------------------------------
  579.   alias shaz_mouse_game_event_clear_page_settings clear_page_settings
  580.   def clear_page_settings
  581.     shaz_mouse_game_event_clear_page_settings
  582.     @mouse_icon = nil
  583.     @mouse_text = nil
  584.     @mouse_position = [0, 0]
  585.     @mouse_autoactivate = false
  586.     @height = 0
  587.   end
  588.   #--------------------------------------------------------------------------
  589.   # * Set Up Event Page Settings
  590.   #--------------------------------------------------------------------------
  591.   alias shaz_mouse_game_event_setup_page_settings setup_page_settings
  592.   def setup_page_settings
  593.     shaz_mouse_game_event_setup_page_settings
  594.     @page.build_stats
  595.     @mouse_icon         = @page.mouse_icon
  596.     @mouse_text         = @page.mouse_text
  597.     @mouse_position     = @page.mouse_position
  598.     @mouse_autoactivate = @page.mouse_autoactivate
  599.     set_size
  600.   end
  601. end
  602.  
  603.  
  604.  
  605. #============================================================================
  606. # SUPER SIMPLE MOUSE SCRIPT
  607. # Character
  608. #============================================================================
  609.  
  610. class Game_CharacterBase
  611.   attr_reader :height                            # Height of character bitmap
  612.   #--------------------------------------------------------------------------
  613.   # * Initialize Public Member Variables
  614.   #--------------------------------------------------------------------------
  615.   alias shaz_mouse_game_characterbase_init_public_members init_public_members
  616.   def init_public_members
  617.     shaz_mouse_game_characterbase_init_public_members
  618.     @height = 0
  619.   end
  620.   #--------------------------------------------------------------------------
  621.   # * Change Graphics
  622.   #     character_name  : new character graphic filename
  623.   #     character_index : new character graphic index
  624.   #--------------------------------------------------------------------------
  625.   alias shaz_mouse_game_characterbase_set_graphic set_graphic
  626.   def set_graphic(character_name, character_index)
  627.     shaz_mouse_game_characterbase_set_graphic(character_name, character_index)
  628.     set_size
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # * Set character width/height size
  632.   #--------------------------------------------------------------------------
  633.   def set_size
  634.     bw = Cache.character(@character_name).width
  635.     bh = Cache.character(@character_name).height
  636.     sign = @character_name[/^[\!\$]./]
  637.     if sign && sign.include?('$')
  638.       @width = bw / 3
  639.       @height = bh / 4
  640.     else
  641.       @width = bw / 12
  642.       @height = bh / 8
  643.     end
  644.   end
  645.   #--------------------------------------------------------------------------
  646.   # * Detect Collision with Event
  647.   #--------------------------------------------------------------------------
  648.   def collide_with_events?(x, y)
  649.     $game_map.events_xy_nt(x, y).any? do |event|
  650.       self != event && (event.normal_priority? || self.is_a?(Game_Event))
  651.     end
  652.   end
  653.   #--------------------------------------------------------------------------
  654.   # * Detect Collision with Vehicle
  655.   #--------------------------------------------------------------------------
  656.   def collide_with_vehicles?(x, y)
  657.     !self.is_a?(Game_Player) && ($game_map.boat.pos_nt?(x, y) || $game_map.ship.pos_nt?(x, y))
  658.   end
  659.   #--------------------------------------------------------------------------
  660.   # * Frame Update
  661.   #--------------------------------------------------------------------------
  662.   alias shaz_mouse_game_characterbase_update update
  663.   def update
  664.     run_path if @runpath
  665.     shaz_mouse_game_characterbase_update
  666.   end
  667.   #--------------------------------------------------------------------------
  668.   # * Run Path
  669.   #--------------------------------------------------------------------------
  670.   def run_path
  671.     return if moving?
  672.     @step = @map.nil? || @map[@x, @y].nil? ? 0 : @map[@x, @y] - 1
  673.     if @step < 1
  674.       clear_path
  675.     else
  676.       x, y = @x, @y
  677.       dirs = []
  678.       dirs.push(6) if @map[@x+1, @y] == @step && passable?(@x, @y, 6)
  679.       dirs.push(2) if @map[@x, @y+1] == @step && passable?(@x, @y, 2)
  680.       dirs.push(4) if @map[@x-1, @y] == @step && passable?(@x, @y, 4)
  681.       dirs.push(8) if @map[@x, @y-1] == @step && passable?(@x, @y, 8)
  682.       while dirs.size > 0
  683.         dir = dirs.delete_at(rand(dirs.size))
  684.         move_straight(dir)
  685.         break if x != @x || y != @y
  686.       end
  687.       # clear the path if we couldn't move
  688.       clear_path if x == @x && y == @y
  689.     end
  690.   end
  691.   #--------------------------------------------------------------------------
  692.   # * Find Path
  693.   #--------------------------------------------------------------------------
  694.   def find_path(x, y)
  695.     sx, sy = @x, @y
  696.     @tx, @ty = x, y
  697.     result = setup_map(sx, sy)
  698.     @runpath = result[0]
  699.     @map = result[1]
  700.     @map[sx, sy] = result[2] if result[2] != nil
  701.   end
  702.   #--------------------------------------------------------------------------
  703.   # * Clear Path
  704.   #--------------------------------------------------------------------------
  705.   def clear_path
  706.     @map = nil
  707.     @runpath = false
  708.   end
  709.   #--------------------------------------------------------------------------
  710.   # * Setup Map
  711.   #--------------------------------------------------------------------------
  712.   def setup_map(sx, sy)
  713.     map = Table.new($game_map.width, $game_map.height)
  714.     update_counter = 0
  715.     map[@tx, @ty] = 1
  716.     old_positions = [[@tx, @ty]]
  717.     new_positions = []
  718.  
  719.     # if tile is impassable, but CAN move to adjacent tiles, use the adjacent tiles instead
  720.     if (!passable?(@tx, @ty, 2) && !passable?(@tx, @ty, 4) &&
  721.       !passable?(@tx, @ty, 6) && !passable?(@tx, @ty, 8)) ||
  722.       $game_map.events_xy_nt(@tx, @ty).any? { |evt| evt.normal_priority? && evt != self }
  723.       old_positions = []
  724.  
  725.       # Can we move from the destination tile in any direction?
  726.       if map_passable?(@tx, @ty, 2)
  727.         map[@tx, @ty+1] = 1
  728.         old_positions.push([@tx, @ty+1])
  729.       end
  730.       if map_passable?(@tx, @ty, 8)
  731.         map[@tx, @ty-1] = 1
  732.         old_positions.push([@tx, @ty-1])
  733.       end
  734.       if map_passable?(@tx, @ty, 4)
  735.         map[@tx-1, @ty] = 1
  736.         old_positions.push([@tx-1, @ty])
  737.       end
  738.       if map_passable?(@tx, @ty, 6)
  739.         map[@tx+1, @ty] = 1
  740.         old_positions.push([@tx+1, @ty])
  741.       end
  742.  
  743.       # If not, can we at least move up to the destination tile?
  744.       if old_positions.size == 0
  745.         if map_passable?(@tx-1,@ty,6)
  746.           map[@tx-1,@ty] = 1
  747.           old_positions.push([@tx-1,@ty])
  748.         end
  749.         if map_passable?(@tx+1,@ty,4)
  750.           map[@tx+1,@ty] = 1
  751.           old_positions.push([@tx+1,@ty])
  752.         end
  753.         if map_passable?(@tx,@ty-1,2)
  754.           map[@tx,@ty-1] = 1
  755.           old_positions.push([@tx,@ty-1])
  756.         end
  757.         if map_passable?(@tx,@ty+1,8)
  758.           map[@tx,@ty+1] = 1
  759.           old_positions.push([@tx,@ty+1])
  760.         end
  761.       end
  762.     end
  763.  
  764.     # If there are any counters, can we move to the tile on the other side?
  765.     if map_passable?(@tx-2,@ty,6) && $game_map.counter?(@tx-1,@ty)
  766.       map[@tx-2,@ty] = 1
  767.       old_positions.push([@tx-2,@ty])
  768.     end
  769.     if map_passable?(@tx+2,@ty,4) && $game_map.counter?(@tx+1,@ty)
  770.       map[@tx+2,@ty] = 1
  771.       old_positions.push([@tx+2,@ty])
  772.     end
  773.     if map_passable?(@tx,@ty-2,2) && $game_map.counter?(@tx,@ty-1)
  774.       map[@tx,@ty-2] = 1
  775.       old_positions.push([@tx,@ty-2])
  776.     end
  777.     if map_passable?(@tx,@ty+2,2) && $game_map.counter?(@tx,@ty+1)
  778.       map[@tx,@ty+2] = 1
  779.       old_positions.push([@tx,@ty+2])
  780.     end
  781.  
  782.  
  783.     depth = 2
  784.     depth.upto(100) { |step|
  785.       break if old_positions[0].nil?
  786.       @step = step
  787.       loop do
  788.         break if old_positions[0].nil?
  789.         x, y = old_positions.shift
  790.         return [true, map, @step-1] if x == sx && y == sy
  791.         if map[x, y + 1] == 0 && passable?(x, y, 2)
  792.           map[x, y + 1] = @step
  793.           new_positions.push([x, y + 1])
  794.         end
  795.         if map[x - 1, y] == 0 && passable?(x, y, 4)
  796.           map[x - 1, y] = @step
  797.           new_positions.push([x - 1, y])
  798.         end
  799.         if map[x + 1, y] == 0 && passable?(x, y, 6)
  800.           map[x + 1, y] = @step
  801.           new_positions.push([x + 1, y])
  802.         end
  803.         if map[x, y - 1] == 0 && passable?(x, y, 8)
  804.           map[x, y - 1] = @step
  805.           new_positions.push([x, y - 1])
  806.         end
  807.         # Update graphics? (to reduce lag)
  808.         update_counter += 1
  809.         if update_counter > 50
  810.           Graphics.update
  811.           update_counter = 0
  812.         end
  813.       end
  814.       old_positions = new_positions
  815.       new_positions = []
  816.     }
  817.     return [false, nil, nil]
  818.   end
  819. end   
  820. class Game_Character < Game_CharacterBase
  821.   #--------------------------------------------------------------------------
  822.   # * Force Move Route
  823.   #--------------------------------------------------------------------------
  824.   alias shaz_mouse_game_character_force_move_route force_move_route
  825.   def force_move_route(move_route)
  826.     clear_path
  827.     shaz_mouse_game_character_force_move_route(move_route)
  828.   end
  829. end
  830.  
  831.  
  832.  
  833. #============================================================================
  834. # SUPER SIMPLE MOUSE SCRIPT
  835. # Player
  836. #============================================================================
  837.  
  838. class Game_Player < Game_Character
  839.   #--------------------------------------------------------------------------
  840.   # * Trigger Map Event
  841.   #     triggers : Trigger array
  842.   #     normal   : Is priority set to [Same as Characters] ?
  843.   #--------------------------------------------------------------------------
  844.   alias shaz_mouse_game_player_start_map_event start_map_event
  845.   def start_map_event(x, y, triggers, normal)
  846.     @started_events = []
  847.     shaz_mouse_game_player_start_map_event(x, y, triggers, normal)
  848.   end
  849.   #--------------------------------------------------------------------------
  850.   # * Start Event
  851.   #--------------------------------------------------------------------------
  852.   def start_event(event_id)
  853.     @started_events = [] if @started_events.nil?
  854.     @started_events.push(event_id)
  855.   end
  856.   #--------------------------------------------------------------------------
  857.   # * Processing of Movement via Input from Directional Buttons
  858.   #--------------------------------------------------------------------------
  859.   alias shaz_mouse_game_player_move_by_input move_by_input
  860.   def move_by_input
  861.     if Input.dir4 > 0
  862.       clear_path
  863.       shaz_mouse_game_player_move_by_input
  864.     else
  865.       # Move by mouse input
  866.       if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&
  867.         !@vehicle_getting_on && !@vehicle_getting_off &&
  868.         Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored?
  869.         mx, my = *Mouse.grid
  870.         # turn in direction
  871.         if (@x - mx).abs >= (@y - my).abs
  872.           set_direction(@x > mx ? 4 : 6)
  873.         else
  874.           set_direction(@y > my ? 8 : 2)
  875.         end
  876.         # find path
  877.         @event = $game_map.lowest_mouse_event_xy(mx, my)
  878.         if @event.nil?
  879.           find_path(mx, my)
  880.         elsif @event.mouse_autoactivate
  881.           @event.start
  882.           @started_events = []
  883.           clear_path
  884.  
  885.         end
  886.       end
  887.     end
  888.   end
  889.   #--------------------------------------------------------------------------
  890.   # * Frame Update
  891.   #--------------------------------------------------------------------------
  892.   alias shaz_mouse_game_player_update update
  893.   def update
  894.     shaz_mouse_game_player_update
  895.     update_pathfinding if !@event.nil? && !moving?
  896.   end
  897.   #--------------------------------------------------------------------------
  898.   # * Check event after pathfinding
  899.   #--------------------------------------------------------------------------
  900.   def update_pathfinding
  901.     if @map.nil? || @map[@x, @y] <= 1
  902.       dir = @x < @event.x ? 6 : @x > @event.x ? 4 : @y < @event.y ? 2 : @y > @event.y ? 8 : 0
  903.       # Face event and trigger it (only if not triggered by start_map_event)
  904.       turn_toward_character(@event) if !@event.pos?(@x, @y)
  905.       if !@started_events.include?(@event.id) && !@map.nil? && !in_airship?
  906.         @event.start
  907.         @started_events = []
  908.       end
  909.       clear_path
  910.     end
  911.   end
  912.   #--------------------------------------------------------------------------
  913.   # * Clear Path
  914.   #--------------------------------------------------------------------------
  915.   def clear_path
  916.     @event = nil
  917.     super
  918.   end
  919. end
  920.  
  921.  
  922.  
  923. #============================================================================
  924. # SUPER SIMPLE MOUSE SCRIPT
  925. # Interpreter
  926. #============================================================================
  927.  
  928. class Game_Interpreter
  929.   #--------------------------------------------------------------------------
  930.   # * Event Setup
  931.   #--------------------------------------------------------------------------
  932.   alias shaz_mouse_game_interpreter_setup setup
  933.   def setup(list, event_id = 0, lock_player = false)
  934.     shaz_mouse_game_interpreter_setup(list, event_id)
  935.     @lock_player = lock_player
  936.   end
  937.   #--------------------------------------------------------------------------
  938.   # * Execute
  939.   #--------------------------------------------------------------------------
  940.   alias shaz_mouse_game_interpreter_run run
  941.   def run
  942.     $mouse.ignored = true if @lock_player
  943.     shaz_mouse_game_interpreter_run
  944.     $mouse.ignored = false if @lock_player
  945.   end
  946. end
  947.  
  948.  
  949.  
  950. #============================================================================
  951. # SUPER SIMPLE MOUSE SCRIPT
  952. # Windows
  953. #============================================================================
  954.  
  955. class Window_Selectable < Window_Base
  956.   #--------------------------------------------------------------------------
  957.   # * Frame Update
  958.   #--------------------------------------------------------------------------
  959.   alias shaz_mouse_window_selectable_update update
  960.   def update
  961.     shaz_mouse_window_selectable_update
  962.     process_mouse_handling if Input.method == :mouse
  963.   end
  964.   #--------------------------------------------------------------------------
  965.   # * Mouse Movement Processing
  966.   #--------------------------------------------------------------------------
  967.   def process_mouse_handling
  968.     return unless $mouse.enabled? && cursor_movable?
  969.     # Add a delay to prevent too-fast scrolling
  970.     @delay = @delay ? @delay + 1 : 0
  971.     return if @delay % 3 > 0
  972.  
  973.     mx, my = *Mouse.position
  974.     vx = self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x
  975.     vy = self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y
  976.     if mx.between?(vx, vx + self.width) &&
  977.       my.between?(vy, vy + self.height)
  978.       mx -= vx
  979.       mx -= padding
  980.       my -= vy
  981.       my -= padding
  982.       my += oy
  983.       for i in 0 ... item_max
  984.         rect = item_rect(i)
  985.         if mx.between?(rect.x, rect.x + rect.width) &&
  986.           my.between?(rect.y, rect.y + rect.height)
  987.           last_index = @index
  988.           select(i)
  989.           if @index != last_index
  990.             Sound.play_cursor
  991.           end
  992.           break
  993.         end
  994.       end
  995.     end
  996.   end
  997. end   
  998. class Window_NameInput < Window_Selectable
  999.   #--------------------------------------------------------------------------
  1000.   # * Mouse Movement Processing
  1001.   #--------------------------------------------------------------------------
  1002.   def process_mouse_handling
  1003.     return unless $mouse.enabled?
  1004.     # Add a delay to prevent too-fast scrolling
  1005.     @delay = @delay ? @delay + 1 : 0
  1006.     return if @delay % 3 > 0
  1007.  
  1008.     mx, my = *Mouse.position
  1009.     vx = (self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x) + padding
  1010.     vy = (self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y) + padding
  1011.     if mx.between?(vx, vx + self.width - padding * 2) &&
  1012.       my.between?(vy, vy + self.height - padding * 2)
  1013.       mx -= vx
  1014.       my -= vy
  1015.       x = (mx > 5*32+16 ? mx-16 : mx) / 32
  1016.       y = my / line_height
  1017.       last_index = @index
  1018.       @index = y * 10 + x
  1019.       Sound.play_cursor if @index != last_index
  1020.     end
  1021.   end
  1022. end
  1023. class Scene_File < Scene_MenuBase
  1024.   #--------------------------------------------------------------------------
  1025.   # * Update Cursor
  1026.   #--------------------------------------------------------------------------
  1027.   alias shaz_mouse_scene_file_update_cursor update_cursor
  1028.   def update_cursor
  1029.     shaz_mouse_scene_file_update_cursor
  1030.     process_mouse_handling if Input.method == :mouse
  1031.   end
  1032.   #--------------------------------------------------------------------------
  1033.   # * Mouse Movement Processing
  1034.   #--------------------------------------------------------------------------
  1035.   def process_mouse_handling
  1036.     return unless $mouse.enabled?
  1037.     # Add a delay to prevent too-fast scrolling
  1038.     @delay = @delay ? @delay + 1 : 0
  1039.     return if @delay % 3 > 0
  1040.  
  1041.     mx, my = *Mouse.position
  1042.     vx = @savefile_viewport.ox + mx
  1043.     vy = @savefile_viewport.oy + my
  1044.     last_index = @index
  1045.     new_index = vy / savefile_height
  1046.     if @index != new_index
  1047.       if new_index > @index
  1048.         cursor_down(false)
  1049.       else
  1050.         cursor_up(false)
  1051.       end
  1052.       Sound.play_cursor
  1053.       @savefile_windows[last_index].selected = false
  1054.       @savefile_windows[@index].selected = true
  1055.     end
  1056.   end
  1057. end

Lv4.逐梦者

梦石
0
星屑
14585
在线时间
2149 小时
注册时间
2016-9-20
帖子
859
2
发表于 2023-10-1 19:47:50 | 只看该作者
楼主想問一下, 以前用过別的鼠标腳本, 但似乎不能使用 在joiplay里坐标总是(0,0) , 不知道这个可不可以
我发的贴子大多未经整理是草稿抱歉
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
439
在线时间
31 小时
注册时间
2020-6-4
帖子
52
3
 楼主| 发表于 2023-10-2 21:09:09 | 只看该作者
ppspssss 发表于 2023-10-1 19:47
楼主想問一下, 以前用过別的鼠标腳本, 但似乎不能使用 在joiplay里坐标总是(0,0) , 不知道这个可不可 ...

你学习Ruby,自己写一个脚本,总比我给的脚本好使

我只是游玩者,非开发者。。。
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2636
在线时间
184 小时
注册时间
2022-12-13
帖子
34
4
发表于 2024-1-18 12:29:55 | 只看该作者
这个怎么使用,可以使用鼠标,但是图标名字怎么设置,图片放哪
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
439
在线时间
31 小时
注册时间
2020-6-4
帖子
52
5
 楼主| 发表于 2024-2-16 20:19:06 | 只看该作者
sadhu4231 发表于 2024-1-18 12:29
这个怎么使用,可以使用鼠标,但是图标名字怎么设置,图片放哪

VX ACE RPG编辑器菜单的工具->脚本编辑->main上方新建一个脚本,然后放入代码保存



少数游戏无法使用

鼠标图片在哪,我不晓得

论坛有个帖子用鼠标图片的,你找找看

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2636
在线时间
184 小时
注册时间
2022-12-13
帖子
34
6
发表于 2024-2-19 12:16:04 | 只看该作者
allrobot 发表于 2024-2-16 20:19
VX ACE RPG编辑器菜单的工具->脚本编辑->main上方新建一个脚本,然后放入代码保存

好的,谢谢
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-14 17:03

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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