Page 1 of 1

Getting a locked-on entity through Lua

Posted: Mon Jan 08, 2018 4:51 pm
by mrcluster
Figured I'd ask if there's a way to do this. I'm looking to access a unit's current lock-on target, and I don't know of any way. Does on exist, and if so what must be done?

Hmm, I found some interesting parts of the 1playerhud.hud file:
Hidden/Spoiler:
[code] PropagateAlpha(1)
Position(0.787504, 0.828324, 0.000000, "Viewport")
Alpha(0.500000)
FadeOutTime(1.000000)
EventEnable("player1.lockOnClassName")
EventDisable("player1.lockOnDisable")
Text("player1lockon.className")
{
TextBreak("Word")
TextAlignment("Center", "Top")
TextFont("gamefont_tiny")
TextStyle("Shadow")
EventText("player1.lockOnClassName")
Position(0.006355, 0.015880, 0.000000, "Viewport")
ZOrder(127)
EventEnable("initialize")
}

Text("player1lockon.name")
{
TextBreak("Word")
TextAlignment("Center", "Top")
TextFont("gamefont_tiny")
TextStyle("Shadow")
EventText("player1.lockOnName")
Position(0.007546, 0.057666, 0.000000, "Viewport")
ZOrder(127)
EventEnable("player1.lockOnName")
EventDisable("player1.lockOnDisable")
}

Text("player1lockon.distance")
{
TextBox(0.136719, 0.000000)
TextBreak("Word")
TextFont("gamefont_small")
TextStyle("Shadow")
TextAlignment("Center", "Top")
EventNumber("player1.lockOnDistance")
FloatFormat("%.0f")
Position(-0.059591, 0.082852, 0.000000, "Viewport")
ZOrder(127)
EventEnable("initialize")
}[/code]
What are these "events"? How can I access them? These could be very useful for potentially retrieving the entity through Lua.

Re: Getting a locked-on entity through Lua

Posted: Mon Jan 08, 2018 6:00 pm
by Marth8880
Pretty sure you can't.

HUD events are just callbacks sent by C++ to the game's HUD manager to tell it when to do certain things, such as when to bring up the minimap display.

Re: Getting a locked-on entity through Lua

Posted: Mon Jan 08, 2018 6:12 pm
by mrcluster
Marth8880 wrote:Pretty sure you can't.

HUD events are just callbacks sent by C++ to the game's HUD manager to tell it when to do certain things, such as when to bring up the minimap display.
Ah, a shame. My best idea would be a brute-force approach of hooking into the lock-on key through ScriptCB_SetFunctionIdForButtonId (if the function works how I think it does), then looping through a list of entity IDs and checking if the entity meets requirements that'd make it "locked-on", though that's extremely hacky.

Re: Getting a locked-on entity through Lua

Posted: Mon Jan 08, 2018 6:35 pm
by Marth8880
ScriptCB_SetFunctionIdForButtonId? Where have you seen that? :o

Re: Getting a locked-on entity through Lua

Posted: Mon Jan 08, 2018 7:46 pm
by Teancum
Marth8880 wrote:ScriptCB_SetFunctionIdForButtonId? Where have you seen that? :o
viewtopic.php?p=219713#p219713