• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Hovering Mouse over a unit

Status
Not open for further replies.
Level 3
Joined
Jan 20, 2020
Messages
48
Hey savvy mappers and scripters-

when you hover your mouse over an enemy unit, the cursor turns red. Is there any way to retrieve this unit (preferably using GUI or an easy custom action) so that it can be stored into a global variable for further use? Think of it like a targeting system - I need to retrieve the unit that the mouse is hovering on without actually clicking it. Thanks!
 
Level 5
Joined
Jun 12, 2018
Messages
148
I think you could use the new native frames functions introduces in 1.31 patch to get the main frame, register a MOUSE_HOVER event and then do your tracking very easily.

I don't see any other way to achieve this ^^
 
Level 3
Joined
Jan 20, 2020
Messages
48
I think you could use the new native frames functions introduces in 1.31 patch to get the main frame, register a MOUSE_HOVER event and then do your tracking very easily.

I don't see any other way to achieve this ^^
i would need somebody to ELI5 because i have no idea how that stuff works other than hiding all of the UI. Blizz should have just made that stuff GUI
 
No, need for frame natives. Blizzard added a native that returns the unit you want.
This native returns the unit under the cursor working outside of any event, beaware that it is async. If you use it right away to deal damage or anything the multiplayer game desyncs.
JASS:
native BlzGetMouseFocusUnit takes nothing returns unit

Hence before using it for an action that alters the gamestate you have to share it. This native could be used to share the handleId of the unit. Inside the SyncData listener trigger that handleId is then converted to an unit and from that point on you can use your actions.
JASS:
native BlzSendSyncData takes string prefix, string data returns boolean
call BlzSendSyncData("attack", I2S(GetHandleId(BlzGetMouseFocusUnit())))
For the converting one can use a hashtable typecast trick in that link look in tab modern Typecasting or have an unitindexer that converts handleId to unit.
 
Level 18
Joined
Jan 1, 2018
Messages
728
native BlzGetMouseFocusUnit takes nothing returns unit
If you want to use this in a multiplayer map, you have to sync the value manually.
 
Level 3
Joined
Jan 20, 2020
Messages
48
No, need for frame natives. Blizzard added a native that returns the unit you want.
This native returns the unit under the cursor working outside of any event, beaware that it is async. If you use it right away to deal damage or anything the multiplayer game desyncs.
JASS:
native BlzGetMouseFocusUnit takes nothing returns unit

Hence before using it for an action that alters the gamestate you have to share it. This native could be used to share the handleId of the unit. Inside the SyncData listener trigger that handleId is then converted to an unit and from that point on you can use your actions.
JASS:
native BlzSendSyncData takes string prefix, string data returns boolean
call BlzSendSyncData("attack", I2S(GetHandleId(BlzGetMouseFocusUnit())))
For the converting one can use a hashtable typecast trick in that link look in tab modern Typecasting or have an unitindexer that converts handleId to unit.
you're a god - that's a lot for me to digest, thank you for sharing
 
Status
Not open for further replies.
Top