Thread Tools Display Modes
Prev Previous Post   Next Post Next
05-20-16, 08:26 AM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Chat Bubble help

Hello,

I have found a code I'm trying to get to my liking and need some assistance.

Below is the current code i'm using I have everything set how I would like it except the Senders name, I can get the "player" names to be class color but I cannot seem to get the NPC's name to change to the reaction they have against me (ie Friendly hated and so on).

Current Code:
Lua Code:
  1. local events = {
  2.     CHAT_MSG_SAY = 'chatBubbles',
  3.     CHAT_MSG_YELL = 'chatBubbles',
  4.     CHAT_MSG_PARTY = 'chatBubblesParty',
  5.     CHAT_MSG_PARTY_LEADER = 'chatBubblesParty',
  6.     CHAT_MSG_MONSTER_SAY = 'chatBubbles',
  7.     CHAT_MSG_MONSTER_YELL = 'chatBubbles',
  8.     CHAT_MSG_MONSTER_PARTY = 'chatBubblesParty',
  9. }
  10.  
  11. local function SkinFrame(frame)
  12.     for i = 1, select('#', frame:GetRegions()) do
  13.         local region = select(i, frame:GetRegions())
  14.         if (region:GetObjectType() == 'FontString') then
  15.             frame.text = region
  16.         else
  17.             region:Hide()
  18.         end
  19.     end
  20.  
  21.     frame.text:SetFontObject('SystemFont_Small')
  22.     frame.text:SetJustifyH('LEFT')
  23.  
  24.     frame:ClearAllPoints()
  25.     frame:SetPoint('TOPLEFT', frame.text, -7, 25)
  26.     frame:SetPoint('BOTTOMRIGHT', frame.text, 7, -7)
  27.     frame:SetBackdrop({
  28.         bgFile = 'Interface\\Tooltips\\UI-Tooltip-Background',
  29.         edgeFile = 'Interface\\Tooltips\\UI-Tooltip-Border',
  30.         tileSize = 16,
  31.         edgeSize = 12,
  32.         insets = {left=3, right=3, top=3, bottom=3},
  33.     })
  34.     frame:SetBackdropColor(0, 0, 0, 1)
  35.     local _, class = UnitClass("player")
  36.     local color = RAID_CLASS_COLORS[class] or { r = 0.5, g = 0.5, b = 0.5 }
  37.     frame:SetBackdropBorderColor(color.r * 255, color.g * 255, color.b * 255)
  38.  
  39.     frame.sender = frame:CreateFontString(nil, 'OVERLAY', 'NumberFont_Outline_Med')
  40.     frame.sender:SetPoint('BOTTOMLEFT', frame.text, 'TOPLEFT', 0, 4)
  41.     frame.sender:SetJustifyH('LEFT')
  42.  
  43.     frame:HookScript('OnHide', function()
  44.         frame.inUse = false
  45.     end)
  46. end
  47.  
  48. local function UpdateFrame(frame, guid, name)
  49.     if (not frame.text) then
  50.         SkinFrame(frame)
  51.     end
  52.     frame.inUse = true
  53.  
  54.     local class
  55.     if (guid ~= nil and guid ~= '') then
  56.         _, class, _, _, _, _ = GetPlayerInfoByGUID(guid)
  57.     end
  58.    
  59.     if (name) then
  60.         local color = RAID_CLASS_COLORS[class] or { r = 0.75, g = 0.75, b = 0.75 }
  61.         frame.sender:SetText(('|cFF%2x%2x%2x%s|r'):format(color.r*255, color.g*255, color.b*255, name))
  62.         if frame.text:GetWidth() < frame.sender:GetWidth() then
  63.             frame.text:SetWidth(frame.sender:GetWidth())
  64.         end
  65.     end
  66. end
  67.  
  68. local function FindFrame(msg)
  69.     for i = 1, WorldFrame:GetNumChildren() do
  70.         local frame = select(i, WorldFrame:GetChildren())
  71.         if (not frame:GetName() and not frame.inUse) then
  72.             for i = 1, select('#', frame:GetRegions()) do
  73.                 local region = select(i, frame:GetRegions())
  74.                 if region:GetObjectType() == 'FontString' and region:GetText() == msg then
  75.                     return frame
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. local ChatBubbleFrame = CreateFrame('Frame')
  83. for event, cvar in pairs(events) do
  84.     ChatBubbleFrame:RegisterEvent(event)
  85. end
  86.  
  87. ChatBubbleFrame:SetScript('OnEvent', function(self, event, msg, sender, _, _, _, _, _, _, _, _, _, guid)
  88.     if (GetCVarBool(events[event])) then
  89.         ChatBubbleFrame.elapsed = 0
  90.         ChatBubbleFrame:SetScript('OnUpdate', function(self, elapsed)
  91.             self.elapsed = self.elapsed + elapsed
  92.             local frame = FindFrame(msg)
  93.             if (frame or self.elapsed > 0.3) then
  94.                 ChatBubbleFrame:SetScript('OnUpdate', nil)
  95.                 if (frame) then
  96.                     UpdateFrame(frame, guid, sender)
  97.                 end
  98.             end
  99.         end)
  100.     end
  101. end)

I have tried:
Lua Code:
  1. local reaction = UnitReaction(unit, 'player')
  2.  
  3.         if (reaction) then
  4.             r = FACTION_BAR_COLORS[reaction].r
  5.             g = FACTION_BAR_COLORS[reaction].g
  6.             b = FACTION_BAR_COLORS[reaction].b
  7.         else

But I keep getting an error that says unit is nil.

Any help on this would be great.

Thanks Coke
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Chat Bubble help


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