Thread Tools Display Modes
08-08-09, 05:14 AM   #1
Aetharan
A Defias Bandit
 
Aetharan's Avatar
Join Date: Mar 2009
Posts: 3
Code Help - Duplication of a Chat Type

I'm attempting to build a method that dupes a chat-output type such as RAID_BOSS_WHISPER within the user's interface. The goal is to have the script/addon making use of the code to be able to give output as if it were a real Boss Whisper, or MONSTER_EMOTE, or whatever else, viewable only by the person running it.

Thus far, I have the following:
Code:
local info = ChatTypeInfo["RAID_BOSS_WHISPER"];

local origin = "[BigBadGuy]";

local divider = " whispers: ";

local message = "Message.";

for i=1,NUM_CHAT_WINDOWS do
getglobal("ChatFrame" .. i ):AddMessage(origin..divider..message, info.r, info.g, info.b, info.id);
end
This will produce the appearance of a Boss Whisper, but it outputs on every single chat frame whether said frame is supposed to show said whispers or not. Is there a way to check within that final loop whether each given frame should print Boss Whispers before adding the message to that frame?
__________________
Give a man a fire, and he's warm for a day. Set a man on fire, and he's warm for the rest of his life.

Last edited by Aetharan : 08-08-09 at 07:55 AM.
  Reply With Quote
08-08-09, 05:49 AM   #2
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Aetharan View Post
I'm attempting to build a method that dupes a chat-output type such as RAID_BOSS_WHISPER within the user's interface. The goal is to have the script/addon making use of the code to be able to give output as if it were a real Boss Whisper, or MONSTER_EMOTE, or whatever else, viewable only by the person running it.

Thus far, I have the following:
Code:
local info = ChatTypeInfo["RAID_BOSS_WHISPER"];

local origin = "[BigBadGuy];

local divider = " whispers: ";

local message = "Message.";

for i=1,NUM_CHAT_WINDOWS do
getglobal("ChatFrame" .. i ):AddMessage(origin..divider..message, info.r, info.g, info.b, info.id);
end
This will produce the appearance of a Boss Whisper, but it outputs on every single chat frame whether said frame is supposed to show said whispers or not. Is there a way to check within that final loop whether each given frame should print Boss Whispers before adding the message to that frame?
I'm sure there is, but can't think of it off the top of my head. Just woke up and have to go to work.
  Reply With Quote
08-08-09, 06:16 AM   #3
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Basically,
Code:
type1, type2, type3, ... = GetChatWindowMessages(frameID)
is what you're looking for, API-wise.

But I've taken a quick look into the ChatConfig-frame of Blizz (where you toggle the messageTypes) and they used a function to retrieve whether a type is checked or not. I've modified it a bit to work with the channel-id and here it is:

Code:
local function IsListeningForMessageType(frameID, messageType)
    local messageTypeList = _G['ChatFrame'..frameID].messageTypeList
    for _, value in pairs(messageTypeList) do
        if(value == messageType) then
            return true
        end
    end
    return false
end
So you can just use IsListeningForMessageType(i, "RAID_BOSS_WHISPER") in your for-loop to test whether the chatframe has enabled it.
Note, that I've used _G["ChatFrame"..i] instead of getglobal("ChatFrame" .. i) - it does basically the same, but setglobal() / getglobal() are deprecated and with 3.2 even Blizz tries to get rid of it in their code.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
08-08-09, 08:04 AM   #4
Aetharan
A Defias Bandit
 
Aetharan's Avatar
Join Date: Mar 2009
Posts: 3
Thank you for your response, Cargor. I get the distinct impression that what you've given me should work, but I can't seem to make it do so.

To clarify my situation, I'm currently using the script within the addon Gryphonheart Items (at least partially as a crutch), as part of an item I'm making. I'm trying to learn the basics of scripting in WoW. If I try to add the local function into my scriptlet, I get an error saying I'm attempting to index _G, a function, and the item stops trying to process the script. Thus, nothing gets as far as trying to post the message.

I'm afraid when it comes to making anything happen in WoW, I'm an extreme newbie. I'm far more used to RUBY than Lua, and the language shift is making things a bit hard.
__________________
Give a man a fire, and he's warm for a day. Set a man on fire, and he's warm for the rest of his life.
  Reply With Quote
08-08-09, 08:41 AM   #5
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
It's strange that _G is a function, because it should be by default the global table holding all global elements. But you can fetch it like this on top of your script:

local _G = getfenv(0)
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
08-08-09, 09:56 AM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I was having problems yesterday where I was getting an error saying a variable was a function when it should have been a table. Then I found out that I had already used that variable name to define a function, so the table was being overwritten.

My guess is that somewhere later in your code, you're assigning a function to _G.
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » Code Help - Duplication of a Chat Type


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