WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SendChatMessage and illegal chars (https://www.wowinterface.com/forums/showthread.php?t=45493)

gmarco 12-22-12 02:59 AM

SendChatMessage and illegal chars
 
Hi all,

I continue to ask questions on questions and I am sorry about it, but I googled a lot but could not find a solution to this.

I'd like to write something in a CHAT channel. And it works fine, but I was unable to write a something with the escape code to make string colored.

A sample...


Lua Code:
  1. local prgname1 = "|cffffd200addon1|r"
  2. local prgname2 =  "addon2"
  3. local msg1 = string.format("Hello %s !", prgname1)
  4. local msg2 = string.format("Hello %s !", prgname2)
  5.  
  6. print (msg1)
  7. print (msg2)
  8. SendChatMessage(msg1, "GUILD")
  9. SendChatMessage(msg2, "GUILD")

The print(msg?) works quite well but the SendChatMessage only work when the var is prgname2 because in the other case it contains illegal chars.

I check them here: http://www.wowwiki.com/ValidChatMessageCharacters

The problem is that the code doesn't complains but doesn't print either when it found such strings.

I check also:

Lua Code:
  1. SendAddonMessage( "ADDON", "Test", "GUILD" );

But it also don't print either and probably it is not I need.

So the question is ?

Have I to convert the string with some function before passing to SendChatMessage or I have to use different output type ?

Thanks very much for attention as usual.

Haleth 12-22-12 05:12 AM

You can't send coloured chat messages to other people, only show them for yourself using AddMessage().

SendAddonMessage uses a hidden channel to send data between addons, e.g. to synchronize timers or to check if someone has a newer version.

gmarco 12-22-12 05:36 AM

Hi, thanks for your reply...

The code is this:

Lua Code:
  1. local prgname = "|cffffd200autopsy|r"
  2.  
  3. local function color(destName)
  4.    if not UnitExists(destName) then return string_format("|cffff0000%s|r", destName) end
  5.    local _, class = UnitClass(destName)
  6.    local color = _G["RAID_CLASS_COLORS"][class]
  7.    return string_format("|cff%02x%02x%02x%s|r", color.r*255, color.g*255, color.b*255, destName)
  8. end
  9.  
  10.         -- begins code on parsing CLEU
  11.  
  12.     local timeStamp, event, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _, prefixParam1, prefixParam2, _, suffixParam1, suffixParam2 = ... 
  13.    
  14.     -- proceed with CLEU handling
  15.     if not playerGUID then
  16.         playerGUID = UnitGUID("player")
  17.     end
  18.    
  19.     if destGUID == playerGUID or (destName and UnitClass(destName)) then
  20.  
  21.     -- prevent the case the sourceName is nil (sometimes it is happened)
  22.     sourceName = sourceName or "Someone"
  23.    
  24.     if event == "SWING_DAMAGE" then
  25.             if prefixParam2 > 0 then
  26.                 print(string_format("%s: [%s] killed [%s] with %s Melee overkill %s", prgname, sourceName, color(destName), prefixParam1, prefixParam2))
  27.                 autopsy_msg = string_format("autopsy: [%s] killed [%s] with %s Melee overkill %s", sourceName, destName, prefixParam1, prefixParam2)
  28.                 SendChatMessage(autopsy_msg, autopsy_chn)
  29.             end
  30.  
  31.          -- proceed with other code and damage types...

The print() works fine and I think I can use as a self output.
The SendChatMessage is not able to to color both the "prgname" nor the color(destName) ...

The only problem of this approach is that I have to deal with 2 different string format for the output if I'd like to mantain the colors in the "self" output.

Btw if can't be solved it is not a problem, so ... :-)

Thanks very much for your kind reply.

Haleth 12-22-12 06:27 AM

I'm not sure what the problem is now. Like I said, you can't send coloured chat messages to other people.

If you only want to colour the print(), then you should use DEFAULT_CHAT_FRAME:AddMessage() instead. You can provide rgb values in the parameters so you don't need to format the string yourself.

gmarco 12-22-12 06:46 AM

1 Attachment(s)
There wasn't any problems I was only explaining why I asked so I posted the real code :-)

Just to clarify better I post an image:

http://s20.postimage.org/icdo1j1od/autopsy.png

As you can see the print works fine coloring the addon name and the name of the mage pg (Frostanzo).

The SendChatMessage(autopsy_msg, autopsy_chn) instead prints in the default chat color without any color modification for name and pg class.

What I would to obtain was that the SendChatMessage(autopsy_msg, autopsy_chn) can write the same string of the print(), but you said it is not possible so I have to forget to have a colored chat :-)

Thanks very much for your answers.
I really appreciated.

SDPhantom 12-22-12 04:02 PM

Also to add, there are special exceptions such as color codes that are associated with spell and item links as these codes are considered part of the link themselves by the chat server.

gmarco 12-24-12 01:51 AM

1 Attachment(s)
Hi,

thanks SDPhantom. I see that I can print escape code for players, spell and other things if they are hyperlinks.

Lua Code:
  1. local name = "|Hplayer:Axilea:1:WHISPER:Axilea|h[Axilea]|h"
  2. print("print:" .. name) --> works
  3. DEFAULT_CHAT_FRAME:AddMessage("addmsg: " .. name) --> works
  4. SendChatMessage("sendchat: " .. name) --> FAIL !

But frankly I don't understand how to write in others players GUILD/OFFICER/RAID channel using the AddMessage.

Probably I make mistakes in understanding the 2 different functions:

AddMessage vs SendChatMessage

They both can write in my ChatFrames, but I don't understand IF AddMessage can write in other players GUILD/OFFICER/RAID/INSTANCE_CHAT like SendChatMessage does.

So I finish the addon using 2 different strings.
The first with that I use with a print() (when self output is chosen) is colored and the second for the other channels is not :-)

I attach the addon, autopsy, that is a minimal implementation of a death reports, if someone want to check it before the post to the public. Any comments are welcome.

Lua Code:
  1. /autopsy testspell|testmelee

prints in the chosen channel a fake announce to test.

Thanks all again for your time.

Phanx 12-24-12 03:38 AM

Quote:

Originally Posted by gmarco (Post 271030)
But frankly I don't understand how to write in others players GUILD/OFFICER/RAID channel using the AddMessage.

You can't.

Quote:

Originally Posted by gmarco (Post 271030)
They both can write in my ChatFrames, but I don't understand IF AddMessage can write in other players GUILD/OFFICER/RAID/INSTANCE_CHAT like SendChatMessage does.

It can't.

Here's an example of how it works:

1. Someone (maybe you) uses the SendChatMessage function to send a message to the GUILD channel.

2. The server receives the message, and sends it back to every player who is in the same GUILD channel.

3. Your client receives the message, and fires the CHAT_MSG_GUILD event to inform the UI (including addons) that a message was received in the GUILD channel.

4. The default UI processes the CHAT_MSG_GUILD event, formats the mesage with the channel and sender names, and calls the AddMesssage method on each of the default chat frames that are configured to show messages in the GUILD channel.

AddMessage is a frame method, just like SetAlpha or ClearAllPoints, that all ScrollingMessageFrame type frames have. You can't call AddMessage for a chat frame on someone else's computer any more than you can call SetAlpha on a frame on someone else's computer.

gmarco 12-24-12 07:16 AM

Hi Phanx ...

Thanks for your reply, everything is clear now (as usual when you explain :).

I'd like to wish you and to the readers of the forum a merry christmas.

Thanks to everyone.

gmarco 01-15-13 11:57 PM

1 Attachment(s)
I'd like if possible to re-open this thread because there is a thing I don't understand.

I summarized :-)
I wanted to write the name of the player in other's chat (party, raid. instance etc etc) colored by class.
But the chat server always refused to process the "colored" name complaing about illegal chars (the escape codes). But it happily accepts the GetSpellLink(prefixParam1) that is the spell/ability casted.

Now I see that other addons are able to write colored player name in the chat frame.
I tried to understand how, but frankly I was not able to understand :-)

I attach an output.

As you see, axilea is my pg name and it is the killed one. Autopsy write in plain way while fatality is able to print class colored.
The first pg name colored (axilea and gheedo) is colored by the chat addon and it is not related to the report.

Any help / input / tips are welcome as usual.

Thanks to everyone.

Dridzt 01-16-13 04:01 AM

It doesn't (Fatality).

The relevant code snippet is this
Code:

local function colour(name)
        if (instance == "raid" and output1 ~= "SELF") or (instance == "party" and output2 ~= "SELF") then
                return strip(name)
        elseif not UnitIsFriend("player", name) then
                return format("|cffff0000%s|r", strip(name))
        end
        local _, class = UnitClass(name)
        local c = _G["RAID_CLASS_COLORS"][class]
        return format("|cff%02x%02x%02x%s|r", c.r*255, c.g*255, c.b*255, strip(name))
end

As you can see it only returns a colored name when the output is not raid or party, ie when it outputs to the local chatframe.

gmarco 01-16-13 08:23 AM

Uhm ... I don't understand.

I don't have fatality installed, I have autopsy, but I see the colored output of fatality that another member of my party, Gheedo, has installed.

So fatality is writing in party chatframe I suppose because I see its output (colored) as the other party member see my output of autopsy (not colored) .

Now I am lost ... :-)

break19 01-16-13 11:16 AM

You likely have another addon that is processing player names and coloring them by class, outside of any other addon.

Dridzt 01-16-13 11:39 AM

You most probably have a chat addon that colorizes your name. (NickAlert, a Prat module or similar)

gmarco 01-16-13 11:53 AM

:-)

Ehm probably yes :-)
I use BasicChatMods (and with this Phanx will never aswered me again :-) and yes it colors the name of the player I suppose.

Sorry to everyone for asking that silly question but I really don't think about this :-)

gmarco 01-17-13 05:53 AM

1 Attachment(s)
Hi all,
don't want to continue this discussion so much to annoy everyone, but I continue to be a little curious about a thing.

I post a screenshot of yesterday raid chat:



The autopsy lines are correctly displayed by the chat mod in color for my name, but not for the others, i.e. Tullinhood ... and I have it clear why it happens.

But what about the other pg names that some other addon wrote ?
Morgy, Alexyel, Gheedo and Eiki. They are class colored.

I have tried to check all Gara'jal addons I found on curese or wowi (and boss mode addon I use) but I didn't find i.e. the "Trapasso" keyword (with grep) on them ...

Could be the game itself that prints such alerts in this way ?

Thanks really so much to everyone.

Haleth 01-17-13 05:56 AM

Fairly sure that's just the way DBM formats its chat messages.

Dridzt 01-17-13 05:56 AM

Yes those are boss emotes (built-in boss warnings)

Edit: Or (because I can't be sure with your custom chat and client language) if it's a 3rd party bossmod it's printing to your chatframe where as discussed earlier escape codes are possible.
It's not announcing to a public channel in other words.

gmarco 01-17-13 08:57 AM

Thanks very much to everyones for your kind replies and time.

I think we can happily close this thread now :-)

SDPhantom 01-18-13 06:06 PM

Quote:

Originally Posted by gmarco (Post 271030)
I don't understand how to write in others players GUILD/OFFICER/RAID channel using the AddMessage.

The default UI access some globals for the chat windows by referencing _G["CHAT_"..type.."_GET"]. These are the message prefixes used.

Code:

CHAT_GUILD_GET = "|Hchannel:GUILD|h[Guild]|h %s:\32";
CHAT_INSTANCE_CHAT_GET = "|Hchannel:INSTANCE_CHAT|h[Instance]|h %s:\32";
CHAT_INSTANCE_CHAT_LEADER_GET = "|Hchannel:INSTANCE_CHAT|h[Instance Leader]|h %s:\32";
CHAT_MONSTER_PARTY_GET = "|Hchannel:PARTY|h[Party]|h %s:\32";
CHAT_OFFICER_GET = "|Hchannel:OFFICER|h[Officer]|h %s:\32";
CHAT_PARTY_GET = "|Hchannel:PARTY|h[Party]|h %s:\32";
CHAT_PARTY_GUIDE_GET = "|Hchannel:PARTY|h[Dungeon Guide]|h %s:\32";
CHAT_PARTY_LEADER_GET = "|Hchannel:PARTY|h[Party Leader]|h %s:\32";
CHAT_PET_BATTLE_COMBAT_LOG_GET = "|Hchannel:PET_BATTLE_COMBAT_LOG|h[Pet Battle]|h:\32";
CHAT_PET_BATTLE_INFO_GET = "|Hchannel:PET_BATTLE_INFO|h[Pet Battle]|h:\32";
CHAT_RAID_GET = "|Hchannel:RAID|h[Raid]|h %s:\32";
CHAT_RAID_LEADER_GET = "|Hchannel:RAID|h[Raid Leader]|h %s:\32";

Additional probing reveals the following:
Numbered channels; |Hchannel:CHANNEL:1|h[1. General - Dalaran]|h.
BNet conversations; |Hchannel:BN_CONVERSATION:1|h[11. Conversation]|h.
Note BNet conversations start with an internal index of 1 instead of their displayed index of MAX_WOW_CHAT_CHANNELS+1.

Note these are the links used to allow the user to click and open a chat message to the respective channel. These only work for chatframe:AddMessage() and will be refused by SendChatMessage().

Phanx 01-18-13 11:55 PM

To clarify, what PhantomSD posted does not let you "write in other players' GUILD/OFFICER/RAID channel using AddMessage". It only allows you to show messages in your own local chat frame that look like GUILD/OFFICER/RAID messages, but are not actually in those channels.

SDPhantom 01-22-13 05:52 PM

I guess I got a little confused on what the OP wanted to do. I thought we were still talking about links. :p
My explanation on channel links are to allow the user of the addon to click the link and open chat to that channel (relative to the user of course).

I'm going to try to condense this entire conversation into an easy explanation. To start with, we'll examine what happens when you send a message into chat. It all starts with a call to SendChatMessage(), which in turn, sends the message out to the chat servers. This is all it does, this function alone has nothing to do with displaying anything to the user. In addition to forwarding the message out to the intended people, the chat server responds with an echo, the message you sent as normal chat event. This is picked up by the OnEvent handler of any frame that has the respective event registered. The OnEvent handler set on the ChatFrames process this echo that looks exactly like any other chat message, formats it, and calls ChatFrame:AddMessage() to display it. This should explain what the difference is between these two functions.

On to UI Escape Sequences. These generally can be used on any widget that displays text, like FontStrings. Though, ChatFrames are the only widget that allows you to click links. This is the only part of the WoW API where these are of any significance. Everywhere else, they're nothing more than just contents of a string. When it comes to sending a message though SendChatMessage(), with few exceptions, UI Escape Sequences are forbidden. These exceptions being full links (links including the appropriate color codes generated with them). Note that not all links are supported by SendChatMessage(). Additional restrictions do apply.

For more information, see the following links:
SendChatMessage()
ChatFrame:AddMessage()
UI Escape Sequences

Phanx 01-22-13 07:39 PM

Quote:

Originally Posted by SDPhantom (Post 272264)
I guess I got a little confused on what the OP wanted to do. I thought we were still talking about links. :p

He wanted to write colored words in the middle of chat messages in other players' chat windows. The discussion of links came up when someone mentioned that player/item/other links can be sent in chat messages and will be automatically colored in the receiving player's chat window. Other than that, there is no way to send colors as part of your chat message. The receiving player may be using an addon that adds colors to the local display of messages, but you can't send the color codes to be seen by players not using such addons.

gmarco 01-23-13 01:24 PM

Thanks very much for the explanations.

I really appreciate them and I like very much to learn from them.

Phanx is correct when she says I wanna write in colored mode. But what I really liked to do was to send the player name only in class color, like I send the link of the spell (colored and linked). But as we have discussed there is no way to escape this like the spell.

Thanks again for the explanation on the globals ...


All times are GMT -6. The time now is 04:29 AM.

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