Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: FrOzeN on May 24, 2006, 04:44 AM

Title: AddChat Procedure
Post by: FrOzeN on May 24, 2006, 04:44 AM
Thought I'd share this. Slightly different to the more common methods. It's just ment to be a really simple way of adding text without any format required. Also by expanding vbCurreny constances it could be easily modified to add more abilties to it.

Private Const AC_BOLD_ON As Currency = 0
Private Const AC_BOLD_OFF As Currency = 1
Private Const AC_ITALIC_ON As Currency = 2
Private Const AC_ITALIC_OFF As Currency = 3

Private Sub AddChat(ParamArray Parts() As Variant)
    Dim i As Integer
    With rtbChat
        .SelStart = Len(.Text)
        For i = LBound(Parts) To UBound(Parts)
            .SelLength = 0
            If VarType(Parts(i)) = vbCurrency Then
                Select Case Parts(i)
                    Case 0: .SelBold = True
                    Case 1: .SelBold = False
                    Case 2: .SelItalic = True
                    Case 3: .SelItalic = False
                End Select
            ElseIf (VarType(Parts(i)) = vbInteger) Or (VarType(Parts(i)) = vbLong) Then
                .SelColor = Parts(i)
            Else
                .SelText = CStr(Parts(i))
                .SelStart = Len(.Text)
            End If
        Next i
    .SelText = vbCrLf
    .SelStart = Len(.Text)
    End With
End Sub


Example:
AddChat AC_ITALIC_ON, vbWhite, "Hello ", vbRed, " there.", AC_ITALIC_OFF, vbWhite, AC_BOLD_ON, " BOLD!"
Output:
QuoteHello there. BOLD!

[EDIT] Note: When parsing Integers, Longs or Curreny into the function to be displayed as text. Place CStr() around them to convert them to a string so they don't get interpreted as Colours/Formatting.
Title: Re: AddChat Procedure
Post by: MyndFyre on May 24, 2006, 01:19 PM
Out of curiousity, why didn't you just make a bitmask for what things you wanted?


Const AC_NONE As Integer = 0  ' Why the hell would you use Currency???
Const AC_BOLD As Integer = 1
Const AC_ITALIC As Integer = 2
Const AC_UNDERLINE As Integer = 4
Const AC_OVERLINE As Integer = 8
Const AC_LINK As Integer = 16
Const AC_AD_NAUSEUM As Integer = &HFFFFFFE0
Title: Re: AddChat Procedure
Post by: topaz on May 24, 2006, 06:38 PM
Interesting.
Title: Re: AddChat Procedure
Post by: FrOzeN on May 24, 2006, 09:50 PM
Quote from: MyndFyre[vL] on May 24, 2006, 01:19 PM
Out of curiousity, why didn't you just make a bitmask for what things you wanted?


Const AC_NONE As Integer = 0  ' Why the hell would you use Currency???
Const AC_BOLD As Integer = 1
Const AC_ITALIC As Integer = 2
Const AC_UNDERLINE As Integer = 4
Const AC_OVERLINE As Integer = 8
Const AC_LINK As Integer = 16
Const AC_AD_NAUSEUM As Integer = &HFFFFFFE0


It's ment to be able to parse colours, text and formatting. By default, colours are parsed to the sub as Integers/Longs and the sub works by determining what DATA TYPE they are to know how to process them. Because of this for my constances I parse to the sub, I had to use a different data type so it can tell them apart from colours. So I just chose Currency. For any other data types that get parsed to the sub, I assume there text and just add them to get displayed.

If I made the constances as Integers like your code is. There'd be no way to tell 'AC_BOLD' apart from 'vbWhite' when they get parsed, as there both the same value '1'.

Also your right about bitwise, that'd be better. I'll add it in later.
Title: Re: AddChat Procedure
Post by: DeathSoldier on June 20, 2006, 01:38 AM
2 questions, I hope you can help a friendly kid out  ::)

1. How do I make it so  a time stamp shows before the lines in the color white, right now it just shows it the current color as the text?

2. If I was to turn bold on, then in another word turn italic on, the timestamp would show twice.
^
ex: [2:00 PM] HELLO [2:00 PM] there!

See how it shows the timestamp twice? I am new to vb, can anyone help me?

Current code:
Public Sub AddC(RTB As RichTextBox, ParamArray Parts() As Variant)
    Dim i As Integer
    With RTB
        .SelStart = Len(.Text)
        For i = LBound(Parts) To UBound(Parts)
            .SelLength = 0
            If VarType(Parts(i)) = vbCurrency Then
                Select Case Parts(i)
                    Case 0: .SelBold = True
                    Case 1: .SelBold = False
                    Case 2: .SelItalic = True
                    Case 3: .SelItalic = False
                End Select
            ElseIf (VarType(Parts(i)) = vbInteger) Or (VarType(Parts(i)) = vbLong) Then
                .SelColor = Parts(i)
            Else
                .SelText = "[ " & Time & "] " & CStr(Parts(i))
                .SelStart = Len(.Text)
            End If
        Next i
    .SelText = vbCrLf
    .SelStart = Len(.Text)
    End With
End Sub


Only thing change is the '.SelText = "[ " & Time & "] " & CStr(Parts(i)' (the adding of "[ " & Time & "] " &).

Thank you.
Title: Re: AddChat Procedure
Post by: MyndFyre on June 20, 2006, 04:28 AM
My chat-adding routine includes a timestamp based on a bitmask.  The time stamp is built within the add-chat function itself, not outside.
Title: Re: AddChat Procedure
Post by: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Title: Re: AddChat Procedure
Post by: DeathSoldier on June 20, 2006, 07:52 PM
Quote from: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Instead of bashing the code, why not post a 'well' writting AddChat routine?
Title: Re: AddChat Procedure
Post by: FrOzeN on June 21, 2006, 05:23 AM
Heh, I know it was a pretty poorly written piece of code. I wasn't really expecting any practical use of it, just posting another method for newcomers to see different ways code can be used.

I'll post a cleaner version tomorrow.
Title: Re: AddChat Procedure
Post by: rabbit on June 21, 2006, 07:34 AM
Quote from: DeathSoldier on June 20, 2006, 07:52 PM
Quote from: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Instead of bashing the code, why not post a 'well' writting AddChat routine?
People should not be spoonfed.  If I said not to use a "poorly written AddChat routine", it's clearly indicated that there are better routines out there, and he should try searching.  But, because you insist on spoon feeding him, here (http://sidoh.dark-wire.net/?fuseaction=code.view&id=5).  Now be quiet.
Title: Re: AddChat Procedure
Post by: Spht on June 23, 2006, 07:32 PM
Quote from: rabbit on June 21, 2006, 07:34 AM
Quote from: DeathSoldier on June 20, 2006, 07:52 PM
Quote from: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Instead of bashing the code, why not post a 'well' writting AddChat routine?
People should not be spoonfed.  If I said not to use a "poorly written AddChat routine", it's clearly indicated that there are better routines out there, and he should try searching.  But, because you insist on spoon feeding him, here (http://sidoh.dark-wire.net/?fuseaction=code.view&id=5).  Now be quiet.

The page says it's Grok's, but it's not.  Grok wouldn't do something as stupid as:

If Len(rtb.text) > 50000 Then
      With rtb
           .Visible = False
           .SelStart = 0
           .SelLength = InStr(1, .text, vbLf, vbTextCompare)
           .SelText = vbNullString
           .Visible = True
      End With
End If


See the original post here (http://botdev.valhallalegends.com/documents/vbrtbpro.html).
Title: Re: AddChat Procedure
Post by: rabbit on June 24, 2006, 07:07 AM
Hm.  It still works.  And I do remember it from somewhere.
Title: Re: AddChat Procedure
Post by: UserLoser on June 25, 2006, 12:40 AM
What's with the 50000?  Random number some newbie used I guess :)
Title: Re: AddChat Procedure
Post by: FrOzeN on June 25, 2006, 03:15 AM
Quote from: UserLoser on June 25, 2006, 12:40 AM
What's with the 50000?  Random number some newbie used I guess :)
It makes it so if the RichTextBox has more than 50 thousand characters in it, it clears the top line. This way it doesn't use up excessive temporary cache.
Title: Re: AddChat Procedure
Post by: UserLoser on June 25, 2006, 01:21 PM
Seems like a stupid way to do it