查看: 3158|回复: 5

[已经解决] 关于鼠标操作的脚本!!!!!

[复制链接]
梦石
0
星屑
55
在线时间
960 小时
注册时间
2011-7-13
回帖
260
发表于 2017-1-20 20:31:36 | 显示全部楼层 |阅读模式

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

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

×
向各位前辈求助,我想要一个“不用控制主角行动,可以直接点击事件的鼠标脚本”。
本站的鼠标脚本我都下载、测试过了,RMXP图书馆也找过了,没有我想要的鼠标脚本。
请各位前辈务必帮忙。
梦石
0
星屑
125
在线时间
171 小时
注册时间
2014-4-14
回帖
135
发表于 2017-1-21 00:54:54 | 显示全部楼层
rmxp版的dnf地下城与勇士单机版有这个功能,但用的鼠标脚本只是一般的鼠标脚本,应该还修改了其他的脚本或和其他脚本配合用,但我找不出来。你自己下载个dnf范例研究研究吧。https://pan.baidu.com/s/1nuUuXOt

点评

那应该可以除以一格的32可以得出是在第几格  发表于 2017-1-21 16:47
这我知道,我一开始就尝试用全局变量获取鼠标坐标,然后修改game_player的事件启动。可是发现鼠标的坐标居然是一个点的位置就是1,而不是一格是1。  发表于 2017-1-21 11:10
应该是获取鼠标点击的坐标,然后启动那个坐标上的事件  发表于 2017-1-21 09:36
Vanyogin
回复

使用道具 举报

梦石
0
星屑
125
在线时间
171 小时
注册时间
2014-4-14
回帖
135
发表于 2017-1-21 12:10:11 | 显示全部楼层
本帖最后由 2357691704 于 2017-1-21 17:48 编辑

终于弄好了!

首先要修改Game_player(如图1)。
鼠标脚本

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




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


  18. module Mouse
  19. LEFT = 0x01
  20. RIGHT = 0x02


  21. def self.init(sprite = nil)
  22. # $HookStart.call($Window_HWND)
  23. $ShowCursor.call(0)

  24. @show_cursor = false

  25. @mouse_sprite = Sprite.new
  26. @mouse_sprite.z = 99999
  27. @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse.png')
  28. #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))


  29. @left_press = false
  30. @right_press = false
  31. @left_trigger = false
  32. @right_trigger = false
  33. @left_repeat = false
  34. @right_repeat = false
  35. @click_lock = false

  36. update
  37. end
  38. def self.exit
  39. @mouse_sprite.bitmap.dispose
  40. @mouse_sprite.dispose
  41. @show_cursor = true
  42. # $HookEnd.call
  43. $ShowCursor.call(1)
  44. end
  45. def self.mouse_debug
  46. return @mouse_debug.bitmap
  47. end
  48. def self.update
  49. left_down = $GetKeyState.call(0x01)
  50. right_down = $GetKeyState.call(0x02)

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

评分

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

查看全部评分

Vanyogin
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部