Thread Tools Display Modes
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
05-20-16, 09:39 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
Where are you getting a UnitID from? I can't find it anywhere in the code.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
05-21-16, 08:56 AM   #3
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by SDPhantom View Post
Where are you getting a UnitID from? I can't find it anywhere in the code.
I'm not sure where to look for the UnitID of a chat message I have been searching all morning and can not find anything that will help me get the senders reaction to the player.

I guess ill just have to stick with the Class color for players and grey for everything else.

Thanks
Coke
  Reply With Quote
05-21-16, 11:22 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Have you had a look at BubbleBobble? http://www.wowinterface.com/download...bleBobble.html (I don't remember if it has what you're looking for)
/edit: it's also 5 years old.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-21-16, 03:14 PM   #5
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
http://www.wowinterface.com/forums/s...8&postcount=15
  Reply With Quote
05-25-16, 08:27 AM   #6
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Ok so I think I'm getting closer..

I know this may seem long and drawn out but seems the only choice I have at the moment...

Here is the code I'm trying
Code:
local function UpdateFrame(frame, guid, name)
    if (not frame.text) then
        SkinFrame(frame)
    end
    frame.inUse = true

    local class
    if (guid ~= nil and guid ~= '') then
        _, class, _, _, _, _ = GetPlayerInfoByGUID(guid)
    end

	CUSTOM_FACTION_BAR_COLORS = {
		[1] = {r = 1, g = 0, b = 0},
		[2] = {r = 1, g = 0, b = 0},
		[3] = {r = 1, g = 1, b = 0},
		[4] = {r = 1, g = 1, b = 0},
		[5] = {r = 0, g = 1, b = 0},
		[6] = {r = 0, g = 1, b = 0},
		[7] = {r = 0, g = 1, b = 0},
		[8] = {r = 0, g = 1, b = 0},
	}	
	
	-- Find Unit Types
	for _, UNITZ in pairs ({
	
		-- Main Units
		player, pet, vehicle, target, focus, mouseover, none, npc,
		
		-- Party Members
		party1, party2, party3, party4,
		
		-- Party Pets
		partypet1, partypet2, partypet3, partypet4, 
		
		-- Raid Players
		raid1, raid2, raid3, raid4, raid5, raid6, raid7, raid8, raid9, raid10,
		raid11, raid12, raid13, raid14, raid15, raid16, raid17, raid18, raid19, raid20,
		raid21, raid22, raid23, raid24, raid25, raid26, raid27, raid28, raid29, raid30,
		raid31, raid32, raid33, raid34, raid35, raid36, raid37, raid38, raid39, raid40,
		
		-- Raid Player Pets
		raidpet1, raidpet2, raidpet3, raidpet4, raidpet5, raidpet6, raidpet7, raidpet8, raidpet9, raidpet10,
		raidpet11, raidpet12, raidpet13, raidpet14, raidpet15, raidpet16, raidpet17, raidpet18, raidpet19, raidpet20,
		raidpet21, raidpet22, raidpet23, raidpet24, raidpet25, raidpet26, raidpet27, raidpet28, raidpet29, raidpet30,
		raidpet31, raidpet32, raidpet33, raidpet34, raidpet35, raidpet36, raidpet37, raidpet38, raidpet39, raidpet40,

		-- Bosses
		boss1, boss2, boss3, boss4, boss5,
		
		-- Arena Players
		arena1, arena2, arena3, arena4, arena5,
		
	}) do
		reaction = UnitReaction(UNITZ, "player")
	end
	
	if (name) then
		local color = RAID_CLASS_COLORS[class] or CUSTOM_FACTION_BAR_COLORS[reaction]
		frame.sender:SetText(('|cFF%2x%2x%2x%s|r'):format(color.r * 255, color.g * 255, color.b * 255, name))
		if frame.text:GetWidth() < frame.sender:GetWidth() then
			frame.text:SetWidth(frame.sender:GetWidth())
		end
	end	
end
Now for players again it works fine, but for my NPC in my Garrison I get a color error

Error:
Code:
2x cChat\cChat-6.2.3.lua:493: attempt to index local 'color' (a nil value)
cChat\cChat-6.2.3.lua:493: in function <cChat\cChat.lua:435>
cChat\cChat-6.2.3.lua:528: in function <cChat\cChat.lua:522>

Locals:
frame = <unnamed> {
 0 = <userdata>
 text = <unnamed> {
 }
 inUse = true
 sender = <unnamed> {
 }
}
guid = nil
name = "Scout Valdez"
class = nil
color = nil
(*temporary) = <function> defined =[C]:-1
(*temporary) = <unnamed> {
 0 = <userdata>
}
(*temporary) = <function> defined =[C]:-1
(*temporary) = "|cFF%2x%2x%2x%s|r"
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index local 'color' (a nil value)"
SkinFrame = <function> defined @cChat\cChat.lua:400
Line 493 is the local color one

Any ideas?

Coke
  Reply With Quote
05-25-16, 05:42 PM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Throwing darts here, but this might help. Or not LOL.

First, what kind of unit is "UNITZ"? Surely that's a typo...
Lua Code:
  1. do
  2. reaction = UnitReaction(UNITZ, "player")
  3. end

Next, since NPCs don't have unitIDs unless you are directly interracting with them, but they do have GUIDs, you might want to sort that out. In other words, if you want to keep the reaction color for an NPC that you are indirectly interracting with (IE target of target, where target == tankPlayer and target'starget == boss), you will need to store or cache that.
Lua Code:
  1. local color
  2. -- if a player unitID then ...
  3. color = CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]
  4. -- elseif unitID is an NPC then ...
  5. color = CUSTOM_FACTION_BAR_COLORS[UnitReaction(unitID)] or UnitReaction(unitID)
  6. -- end
  Reply With Quote
05-25-16, 06:09 PM   #8
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I was browsing the CHAT_MSG_xx events, and nearly all have a GUID as one of their args. You can then convert the GUID into an unitID if necessary, even NPCs.

About using custom colors: you must check for those first before you use built in colors, for logical reasons. Think about this psuedocode logic:
Lua Code:
  1. local _, class = UnitClass("player")
  2. local color = RAID_CLASS_COLORS[class] or CUSTOM_COLORS[class] -- will always find RCC and never CC
  3. local color = CUSTOM_COLORS[class] or RCC[class] -- if CC not found, then check RCC, which is found
The same will go for your custom unit reaction colors. You must check for those first, then built in API.
  Reply With Quote
05-25-16, 06:57 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by myrroddin View Post
First, what kind of unit is "UNITZ"? Surely that's a typo...
Lua Code:
  1. do
  2. reaction = UnitReaction(UNITZ, "player")
  3. end
UNITZ is a variable that is assigned a unitID in the pairs loop that line is found in.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-26-16, 08:35 AM   #10
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Thanks Everyone for the Help but it seems my coding skills suck so I'm just going to stick with what I have gotten to work.

This works for half of what I'm looking for.
Code:
local function UpdateFrame(frame, guid, name)
    if (not frame.text) then
        SkinFrame(frame)
    end
    frame.inUse = true

    local class
    if (guid ~= nil and guid ~= '') then
        _, class, _, _, _, _ = GetPlayerInfoByGUID(guid)
    end

	
	if (name) then
		local color = RAID_CLASS_COLORS[class] or {r = 1, g = 1, b = 0.2}
		frame.sender:SetText(('|cFF%2x%2x%2x%s|r'):format(color.r * 255, color.g * 255, color.b * 255, name))
		if frame.text:GetWidth() < frame.sender:GetWidth() then
			frame.text:SetWidth(frame.sender:GetWidth())
		end
	end	
end
Thanks again
Coke
  Reply With Quote

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

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