LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Lua Programming Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=50)
-   -   That pesky EntityControl! May I please get some guidance? (https://www.lotrointerface.com/forums/showthread.php?t=3700)

Grimmerthan 06-14-2018 03:20 PM

That pesky EntityControl! May I please get some guidance?
Hi folks,

I'm working on a plugin to help monitor boss debuffs (like frost/fire-lore). I'm basing it off a re-build of the m_vitals plugin, a plugin which I think is pretty awesome. The plugin is intended to create multiple target trackers, with each tracker observing morale/power, corruptions, and specific debuffs.

The issue I'm hitting is that the last EntityControl for tracking targets no longer connects to what should be its target, when my LocalUser changes targets. For example, when I create 4 trackers, the first 3 work correctly, and the 4th does not.

I've tried multiple ways of structuring code (and broken things horribly several times!), based on other plugins and Lua guides, and the problem persists across all of them. I feel like there's a basic concept or syntax that I'm missing.

May I please get some guidance or advice or correction? The code is at

At this time, a good chunk of the code is commented out, with enough left in to demonstrate the issue. Also, I haven't done much programming or scripting in the last few years other than some ugly python scripts, so please be kind :D

Thanks in advance

Garan 06-14-2018 05:01 PM

It's been a long time since I played with targets, but as I recall the implementation of Lua targets is intended to only track the current target of an Actor. If the Actor changes targets then the targetChanged event fires for that Actor and all references to the prior target become nil and eventually get garbage collected. You are supposed to implement an event handler for the targetChanged event and update your control to the new target. So, the target control is meant to track the current target of a player or mob, not stay on a specific actor. There may be a number of reasons why the devs implemented it this way but I suspect it was simply the easiest way to hook into the underlying targeting mechanism - basically the same thing raid target assists do (they probably piggy-back off that same code).

So, for your plugin to work, you would need distinct actors staying targeted on the mobs you are interested in tracking and not changing targets. I suspect that would not be desirable for your plugin.

It seems you are trying to create trackers that work much like the windows the game creates when you press "H" - a small window that stays targeted on the item or mob you have target at that moment. I wish the Lua implementation worked that way, it would have been far more useful :(

Grimmerthan 06-14-2018 05:38 PM

Thanks Garan for your comments. I think this fits with what I'm seeing. It seems that only the last created EntityControl maintains the connection to LocalUser.

The guy who did m_vitals was able to make that plugin work the way that I'd like to see. I will dig back into his code and see if I can figure it out. Worse comes to worse, maybe I could embed a 2nd EntityControl to shield the first.

Grimmerthan 06-14-2018 11:30 PM

Ok, I isolated the behaviour and stripped it down to one line of code.

The EntityControl will maintain a target as expected, if :GetTarget() is called again, prior to LocalPlayer changing target.

The EntityControl loses the connection to the target the next time LocalPlayer changes target, with this call order:

        local Target = LocalUser:GetTarget()
        self.TargetSelection:SetEntity( Target )

It will maintain a connection, when this is done:

        self.TargetSelection:SetEntity( LocalUser:GetTarget() )
        local Target = LocalUser:GetTarget()

Neat :D

All times are GMT -5. The time now is 07:23 PM.

vBulletin® - Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.