Quantcast How can i get moob name? Lotro -Plugin - LoTROInterface
lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
 
Thread Tools Display Modes
  #1  
Unread 11-07-2013, 09:00 AM
Leoretorico Leoretorico is offline
The Wary
 
Join Date: Nov 2013
Posts: 2
How can i get monster name? Lotro -Plugin

Hello guys ,i'm from Brazil and new with Lua Development.
So, How can i get a monster name, to write on label.

I want to create a plugin with informations about monters when you click them.
i'll be so thankful if someone can help me

Last edited by Leoretorico : 11-07-2013 at 10:14 AM.
Reply With Quote
  #2  
Unread 11-07-2013, 12:08 PM
Garan's Avatar
Garan Garan is online now
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 270
There is an undocumented method of the Actor object, :GetTarget() which will return an Actor object for the specified Actor's current target. Note, as soon as the current target is out of range or the original Actor changes targets, the returned object is destroyed and will become nil so be sure to grab whatever information you plan to display into variables immediately.
There is also an undocumented event, TargetChanged() for which you can implement a handler to update the target info.

To get the name of the player's target, you would use:
Code:
localPlayer=Turbine.Gameplay.LocalPlayer.GetInstance();
playerTargetName="";
localPlayer.TargetChanged=function()
    local target=localPlayer:GetTarget()
    if target~=nil then
        playerTargetName=target:GetName()
    else
        playerTargetName=""
    end
end
Since these are undocumented, they are subject to changes without notice, but they still work in the live client at this time. Ideally you should use the AddCallback mechanism for the event handler and then remove it when your plugin unloads with RemoveCallback as show in EventHandling post of the thread
https://www.lotro.com/forums/showthr...gins-for-Noobs
Reply With Quote
  #3  
Unread 11-07-2013, 01:39 PM
Leoretorico Leoretorico is offline
The Wary
 
Join Date: Nov 2013
Posts: 2
Thanks

Thanks for your help!

i want to create a plugin like this: when you click on target a box opens with informations from books (JRR T)

example : name :
Type :
Region:
Description:
Reply With Quote
  #4  
Unread 11-07-2013, 04:40 PM
Garan's Avatar
Garan Garan is online now
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 270
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
level=target:GetLevel()
end

The second method is to test for the existance of the target.GetLevel function before calling it, ex:
if target.GetLevel ~= nil then
level=target:GetLevel()
end
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:
Code:
if target.IsA(Turbine.Gameplay.Player) then
    -- process any code specific to only players
    -- such as GetClass, GetRace, etc
end
if target.IsA(Turbine.Gameplay.Actor) then
    -- proces any code common to actors or players
    -- such as GetLevel, GetMorale, GetMaxMorale, etc.
end
if target.IsA(Turbine.Gameplay.Entity) then
    -- process any code common to entities, actors or players
    -- such as GetName
end
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
  #5  
Unread 02-27-2014, 07:10 AM
ProgMaster ProgMaster is offline
The Wary
 
Join Date: Feb 2014
Posts: 4
Code:
localPlayer.TargetChanged=function()
    local target=localPlayer:GetTarget()
    if target~=nil then
        playerTargetName=target:GetName()
    else
        playerTargetName=""
    end
end
Is that possible with TargetChanged event or party:GetMember():GetTarget() to retrieve the target object of player in your party (not yourself)?
Reply With Quote
  #6  
Unread 02-27-2014, 07:57 AM
Garan's Avatar
Garan Garan is online now
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 270
Quote:
Originally Posted by ProgMaster
Code:
localPlayer.TargetChanged=function()
    local target=localPlayer:GetTarget()
    if target~=nil then
        playerTargetName=target:GetName()
    else
        playerTargetName=""
    end
end
Is that possible with TargetChanged event or party:GetMember():GetTarget() to retrieve the target object of player in your party (not yourself)?
Well, for starters, you should be using the AddCallback method to assign event handlers. Additionally, since the TargetChanged event will pass the caller as its first parameter, you can use the same event handler for everybody.

Create a table of target names with the player's names as keys. Then create a function that sets the sender's target value and attach that event to all of the players.

for example:
Code:
targetName={}
targetChanged=function(sender)
  local tmpTarget=sender:GetTarget()
  if tmpTarget==nil then
    targetName[sender:GetName()]=""
  else
    targetName[sender:GetName()]=tmpTarget:GetName()
  end
end

party=localPlayer:GetParty()
if party~=nil then
  for index=1,party:GetMemberCount()-1 do
    AddCallback(party:GetMember(index),"TargetChanged",targetChanged)
  end
end
note, you will have to remove entries from the targetName table when
members are removed and attach handlers to new members as they are added, etc. but that's the basic idea.

See https://www.lotro.com/forums/showthr...gins-for-Noobs for more information on AddCallback

Last edited by Garan : 02-27-2014 at 08:08 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Official Lotro plugin manager daimon Lua Programming Help (L) 23 12-16-2011 02:24 AM
LoTRO Plugin review videos Dolby News 1 09-10-2010 08:59 AM


All times are GMT -5. The time now is 08:56 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui