AddChat function

From StealthBot Wiki
Jump to: navigation, search

AddChat is a popular function used in programming Battle.net chat clients. It prints formatted text, generally accompanied by a line break and some sort of time stamp.

Development

The function was popularized by Grok of Clan vL, who released an implementation of it in Visual Basic 6. StealthBot features its own version of the AddChat function that follows these conventions as of the first version of the Scripting system.

In version 2.7, the function was enhanced to allow the modification of rich text box font as well as color, per block of text.

Documentation

'// ADDCHAT
'// Grok's famous AddChat subroutine. Processes Starcraft/Diablo II color codes automatically.
'// Format: AddChat(Color, Text)
'// Extensible as far as you need:
'// AddChat(Color, Text, Color, Text, Color, Text) -- will all display on one line.
'// For example:
'//     AddChat vbRed, "Hello, world!"
'// will display that phrase in red.
Public Sub AddChat(ParamArray saElements() As Variant)
    Dim arr() As Variant ' ...
    
    ' ...
    arr() = saElements
    
    ' ...
    Call DisplayRichText(frmChat.rtbChat, arr)
End Sub

Summary

This subroutine is called to print text to your bot window, in any amount of colors and/or fonts.

Syntax

Pass any amount of arguments to it in one of the two following formats (there must be at least one set of two or three, and they must be all in one format or the other):

  • AddChat Color, Text, ...
  • AddChat Font, Color, Text, ...

Arguments

  • Color is an integer you provide. Generally, these built-in VBScript constants are used:
  • vbRed, vbYellow, vbGreen, vbCyan, vbBlue, vbMagenta, vbBlack, vbWhite They evaluate to a number you can pass to AddChat. Other ways to generate a desired color is to call the RGB() function or to pass a hexadecimal value (or its numeric equivalent) for the color if you know it.

  • Text is the text you would like displayed in that color. AddChat takes a string, but it is possible to pass variables that can be converted to a string easily (such as a number).
  • Font is a string that you pass containing the font name you wish to use. If the font wasn't found, it defaults to "Tahoma".

Examples

  • Print "Hello world!" in green.
  • AddChat vbGreen, "Hello world!"
    
    Output:
    [1:33:25 PM] Hello, world!
  • Print seperate fonts and colors.
  • AddChat "Courier New", RGB(0, 127, 255), "HI, THIS IS LIGHT BLUE MONOSPACE TEXT, ", "Tahoma", vbRed, "and this is red and normal!"
    
    Output:
    [1:33:45 PM] HI, THIS IS LIGHT BLUE MONOSPACE TEXT, and this is red and normal!

See also