WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Adding TRP3 'full names' to UI target frame (https://www.wowinterface.com/forums/showthread.php?t=55852)

Joker119 11-15-17 06:25 AM

Adding TRP3 'full names' to UI target frame
 
Title says it all, I want to add TRP3's last names (when applicable) to my target frame's name, however, I'm not entierly sure how to do this.

I started by simply trying to replace the default name with the one supplied by the TRP chatframe functions, but it just shows blank, no errors, just no name either.

lua Code:
  1. oUF.Tags.Methods["diablo:name"] = function(unit)
  2.     local color = oUF.Tags.Methods["diablo:color"](unit)
  3.     if IsAddOnLoaded("Totalrp3") then
  4.         local UnitID = TRP3_API.utils.str.getUnitID(unit)
  5.         local name = TRP3_API.chat.getFullnameForUnitUsingChatMethod(UnitID)
  6.     else
  7.         local name = UnitName(unit)
  8.     end
  9.     return "|cff"..color..(name or "").."|r"
  10. end
I've based the UnitID local off what I've gathered going through trp's code. for example: the chatframe.lua never generates the UnitID, but uses it, thus it must come from a global function.
Looking in register_main.lua I fine the mouseover function for tooltips:
lua Code:
  1. local function onMouseOver(...)
  2.     local unitID, unitRealm = getUnitID("mouseover");
  3.     if unitID and isUnitIDKnown(unitID) then
  4.         local _, race = UnitRace("mouseover");
  5.         local _, class, _ = UnitClass("mouseover");
  6.         local englishFaction = UnitFactionGroup("mouseover");
  7.         saveCharacterInformation(unitID, race, class, UnitSex("mouseover"), englishFaction, time(), buildZoneText(), GetGuildInfo("mouseover"));
  8.     end
  9. end
which tells me UnitID comes from 'getUnitID', which is a local import of 'utils.str.getUnidID', the utils are globally declared as "TRP3_API.utils" in the utils.lua file, which also has this function in it:
lua Code:
  1. function Utils.str.getUnitID(unit)
  2.     local playerName, realm = UnitFullName(unit);
  3.     if not playerName or playerName:len() == 0 or playerName == UNKNOWNOBJECT then
  4.         return nil;
  5.     end
  6.     if not realm then
  7.         realm = Globals.player_realm_id;
  8.     end
  9.     return playerName .. "-" .. realm;
  10. end

From this, I can gather feeding a unit into "TRP3_API.utils.str.getUnitID()" should get me the UnitID I require for the next function "TRP3_API.chat.getFullnameForUnitUsingChatMethod(UnitID)"

However, upon doing this, I get no character name.
I also get no errors, so I know i'm calling the right functions with the right information, I'm just not getting back anything.

I found another function aswell
lua Code:
  1. function TRP3_API.register.getUnitRPName(targetType)
  2.     local unitName = UnitName(targetType);
  3.     local unitID = getUnitID(targetType);
  4.     return getUnitRPNameWithID(unitID, unitName);
  5. end
  6.  
  7. TRP3_API.r.name = TRP3_API.register.getUnitRPName;
However setting name = TRP3_API.r.name or TRP3_API.register.getUnitRPName also, gives me no name to display.

I'm utterly confused by all of this, tbh :S

Joker119 11-15-17 08:44 AM

With more tinkering, I've come to this function for my tag
lua Code:
  1. oUF.Tags.Methods["diablo:name"] = function(unit)
  2.     local color = oUF.Tags.Methods["diablo:color"](unit)
  3.     local name = UnitName(unit)
  4.     if IsAddOnLoaded("Totalrp3") then
  5.         local UnitID = TRP3_API.utils.str.getUnitID(unit)
  6.         if UnitID == nil then
  7.             local name = UnitName(unit)
  8.             return "|cff"..color..(name or "").."|r"
  9.         else
  10.             local name = TRP3_API.chat.getFullnameForUnitUsingChatMethod(UnitID)
  11.             return "|cff"..color..(name or "").."|r"
  12.         end
  13.     end
  14. end

However, it misbehaves.

If I target someone with a TRP profile, it works 100% as expected, however, whenever I target someone without a profile, or an NPC, it doesn't display a name.
The "if UnitID == nil" /should/ work around this issue, but for some reason it does now, and i'm confused as to why.

MunkDev 11-15-17 10:25 AM

Lua Code:
  1. oUF.Tags.Methods["diablo:name"] = function(unit)
  2.     local cc = ("|cff%s%%s|r"):format(oUF.Tags.Methods["diablo:color"](unit))
  3.     local unitID = IsAddOnLoaded("Totalrp3") and TRP3_API.utils.str.getUnitID(unit)
  4.     local fullName = unitID and TRP3_API.chat.getFullnameForUnitUsingChatMethod(unitID)
  5.     return cc:format(fullName or UnitName(unit) or "")
  6. end

Joker119 11-15-17 10:46 PM

Thank you! <3 Much love


All times are GMT -6. The time now is 09:53 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI