Quantcast LoTROInterface - View Single Post - How can i get moob name? Lotro -Plugin
View Single Post
Unread 11-07-2013, 04:40 PM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
Join Date: Oct 2010
Posts: 269
I actually oversimplified the GetTarget() method. It will return an Entity, Actor or Player object depending on what is targeted. The difference is in which methods the object will support. Since Entity only supports IsA() and GetName(), if you try to call :GetLevel() you will get an error. There are three ways to handle this, the first is to use the IsA() method to determine whether the object is an Entity, Actor or Player, ex:
if target:IsA(Turbine.Gameplay.Actor) then

The second method is to test for the existance of the target.GetLevel function before calling it, ex:
if target.GetLevel ~= nil then
The third method is a bit more complicated and uses the Lua pcall function to call the function and test for errors.

I would recommend the first method. Note, since Turbine.Gameplay.Player is derived from Turbine.Gameplay.Actor, you can use:
if target.IsA(Turbine.Gameplay.Player) then
    -- process any code specific to only players
    -- such as GetClass, GetRace, etc
if target.IsA(Turbine.Gameplay.Actor) then
    -- proces any code common to actors or players
    -- such as GetLevel, GetMorale, GetMaxMorale, etc.
if target.IsA(Turbine.Gameplay.Entity) then
    -- process any code common to entities, actors or players
    -- such as GetName
since the IsA function will return true if the object is of the class being compared or is derived from the class being compared you can neatly organize the three possible results that you are interested in (theoretically you could also get a Turbine.Object from GetTarget() but I don't recall ever targetting anything that returned such a basic object).

Unfortunately, the API documentation is woefully out-dated so you might want to check out the debug window included in AltInventory, MoorMap or most of my other plugins. For instance, load AltInventory and then use the chat command "/AltInventory debug on" to display the window. Then use the tree control at the bottom to explore _G.Turbine.Gameplay.Actor, _G.Turbine.Gameplay.Entity and _G.Turbine.Gameplay.Player to see all of the available methods of each object (you will have to drill down through multiple levels of __index for each object as that is how Turbine simulated inheritance in their internal objects). Just be sure to use "/altinventory debug off" when you are done or it will display the debug window every time it is loaded.

Much of the interesting information you might want to display (such as mob resistances/mitigations) is not exposed to Lua so you would have to keep a database of that information (a massive task in itself) and look up the info by name which is fairly inefficient, especially if you try to support multiple client languages (EN/DE/FR/RU) and will lead to problems when Turbine changes any underlying info, particularly names.

Last edited by Garan : 11-07-2013 at 05:06 PM.
Reply With Quote