How can I get the focused hero of the player?

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,928
Hello, I better explain it with a picture:
1659028894384.png
 
Maybe someone has a better, simpler solution, but all that comes to my mind is registering when the TAB key is pressed with:

call BlzTriggerRegisterPlayerKeyEvent( yourTrigger , yourPlayer , OSKEY_TAB , 0 , true ).

You have to know the order of the units in the UI, then each time the trigger registers the TAB key being pressed, you know it's gone to the next unit in the list.
 
Level 24
Joined
Jun 26, 2020
Messages
1,928
Yes, it would be very hard, I think I could follow your advices, but I have to consider all the cases: when I select the hero(s) and when I press tab (but the mouse buttons can also do that), the thing is the units selected is very inconsistent, because have a unit selected and in other moment you don't have it selected for W3 don't necessarly means that you "deselected" that unit.

Other thing, I could have a non-hero selected, so I was focusing a possible unit group.
 
Last edited:
Try this:
 
Level 24
Joined
Jun 26, 2020
Messages
1,928
Try this:
It could be, but it says is desyncronized and I need it syncronized, how can I do it? Because until I know I can only syncronize strings.

Maybe I could use the JASS "hacked" typecast, I cast the unit to integer, then cast to string, then sync, then cast the string to integer and then to unit, could work?
 
Level 24
Joined
Jun 26, 2020
Messages
1,928
This what I did to syncronize it:
Lua:
local Data = InitHashtable()

function Int2Unit(id)
    SaveFogStateHandle(Data, 0, 0, ConvertFogState(id))
    return LoadUnitHandle(Data, 0, 0)
end

local focused = nil ---@type unit
OnSyncString(function ()
    focused = Int2Unit(tonumber(BlzGetTriggerSyncData()))
end)

-- returns the current main selected unit of the player.
function GetMainSelectedUnitExSync(p)
    if p == GetLocalPlayer() then
        SyncString(tostring(GetHandleId(GetMainSelectedUnit(GetSelectedUnitIndex()))))
    end
    return focused
end
It worked, but the problem is that the SyncString creates another thread, so its like having a 0 delay, so the "focused" value is not set immediatly, how can I fix it?
 
Status
Not open for further replies.
Top