• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

How can I get the focused hero of the player?

Status
Not open for further replies.
Level 23
Joined
Jun 26, 2020
Messages
1,781
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 23
Joined
Jun 26, 2020
Messages
1,781
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:
Level 20
Joined
Jul 10, 2009
Messages
458
Try this:
 
Level 23
Joined
Jun 26, 2020
Messages
1,781
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 23
Joined
Jun 26, 2020
Messages
1,781
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