Valhalla Legends Forums Archive | Battle.net Bot Development | Why isn't this working?

AuthorMessageTime
OuTLawZGoSu
[code]

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If
[/code]

Can you tell me why this isnt working?

FLAGS = 0 works fine. It gets all the user's icons. Only game icons, not squelch or gravel.

The rest dont do anything. Am I doing something wrong?
January 28, 2004, 10:09 PM
ObsidianWolf
Have you checked your ImageList to see that the Appropriate Keys Have been set for those Icons?
January 28, 2004, 10:11 PM
warz
I'd suggest Switch (FLAGS) { } also
January 28, 2004, 10:12 PM
Kp
[quote author=OuTLawZGoSu link=board=17;threadid=4976;start=0#msg41539 date=1075327757]Can you tell me why this isnt working?[/quote]

Yes.

[quote author=OuTLawZGoSu link=board=17;threadid=4976;start=0#msg41539 date=1075327757]The rest dont do anything. Am I doing something wrong?[/quote]

Yes.

Thus spake the Oracle.
January 28, 2004, 10:12 PM
Zakath
I'm going to do something I don't normally do and just drop some code on you, because you've completely missed a critical aspect of the flags bitmask. Hopefully you'll learn something from this.

[code]
void CheckFlags( DWORD dwFlags, int *lpnStatImg, int *lpnLagImg ) {
   if ( dwFlags & 0x10 )
      *lpnLagImg = ICON_PLUG;
   if ( dwFlags & 0x20 )
      *lpnStatImg = ICON_SQUELCH;
   if ( dwFlags & 0x04 )
      *lpnStatImg = ICON_MEGAPHONE;
   if ( dwFlags & 0x02 )
      *lpnStatImg = ICON_GAVEL;
   if ( dwFlags & 0x08 )
      *lpnStatImg = ICON_BNET;
   if ( dwFlags & 0x01 )
      *lpnStatImg = ICON_BLIZZARD;
}
[/code]

There are three key concepts in that function that you've missed. See if you can figure out what they are.
January 28, 2004, 10:21 PM
OuTLawZGoSu
I got no idea what that does. I dont know C++ :/
January 28, 2004, 10:25 PM
hismajesty
[quote]FLAGS = 0 works fine. It gets all the user's icons. Only game icons, not squelch or gravel. [/quote]

gravel eh? Is that a new flag? :P

[quote]I got no idea what that does. I dont know C++ :/ [/quote]
My C++ knowledge is limited but it's not too hard to figure out what that means.
January 28, 2004, 11:32 PM
R.a.B.B.i.T
Switch(Value){} is the same as Select Case Value:Case Value:EndSelect.
January 28, 2004, 11:47 PM
Myndfyr
You'd better raise my karma for this one.

The following code:
[code]
Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If
[/code]
determines if the flags value equals EXACTLY the value that you're looking for.

I can see two things that you are doing wrong.

First, part of the entire point of using flags is to allow for several boolean values within a single numeric value. Because data is stored ultimately in bits, a 1 can represent a true value, and a 0 a false value.

So, if you wanted a user to have the regular icon, no special icon flags are set. Hence, the flags value is 0.

An example 8-bit number like the ones that are used in this case might be 01001010b = 0x4A (hex), or in Visual Basic, &H4A, the decimal equivalent being 74.

On Battle.net, it is possible (for example) for a squelched user to have the gavel. Thus, you need to be able to check each individual BIT for its truth value.

Zakath posted some C-style code that lets you do this. In your case, perhaps try modifying your code to utilize the bitwise operators AND and OR.

[code]
Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
If FLAGS And &H2 = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS And &H20 = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If
End If
[/code]

These code modifications do two things....

First, it completely removes conditional checking of the second case (special icons) if the first (standard game icon) turns out being the case.

Second, it changes your flags tests to ensure that 1.) you are using HEX values and not DECIMAL values (checking for decimal 20 would never work, because it's the bitwise combination of 16 and 4 -- you'd get megaphone if that was in there), and 2.) that you are actually doing BITWISE FLAGS tests and not direct numeric comparisons.

Make sure to have them in the correct order; I believe a squelched gavel holder has the squelched icon.

Cheers
--Rob
January 29, 2004, 12:09 AM
o.OV
[quote author=Myndfyre link=board=17;threadid=4976;start=0#msg41572 date=1075334962]
You'd better raise my karma for this one.

The following code:
[code]
Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If
[/code]
determines if the flags value equals EXACTLY the value that you're looking for.

I can see two things that you are doing wrong.

First, part of the entire point of using flags is to allow for several boolean values within a single numeric value. Because data is stored ultimately in bits, a 1 can represent a true value, and a 0 a false value.

So, if you wanted a user to have the regular icon, no special icon flags are set. Hence, the flags value is 0.

An example 8-bit number like the ones that are used in this case might be 01001010b = 0x4A (hex), or in Visual Basic, &H4A, the decimal equivalent being 74.

On Battle.net, it is possible (for example) for a squelched user to have the gavel. Thus, you need to be able to check each individual BIT for its truth value.

Zakath posted some C-style code that lets you do this. In your case, perhaps try modifying your code to utilize the bitwise operators AND and OR.

[code]
Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
If FLAGS And &H2 = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS And &H20 = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If
End If
[/code]

These code modifications do two things....

First, it completely removes conditional checking of the second case (special icons) if the first (standard game icon) turns out being the case.

Second, it changes your flags tests to ensure that 1.) you are using HEX values and not DECIMAL values (checking for decimal 20 would never work, because it's the bitwise combination of 16 and 4 -- you'd get megaphone if that was in there), and 2.) that you are actually doing BITWISE FLAGS tests and not direct numeric comparisons.

Make sure to have them in the correct order; I believe a squelched gavel holder has the squelched icon.

Cheers
--Rob
[/quote]

Here is another modification..

[code]
Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
If (FLAGS And &H2) = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf (FLAGS And &H20) = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If
End If
[/code]

If you plan on a moderation bot with a feature to unignore safelisted users you will have to setup another check to detect for a squelched ops..
Assuming you will use this example in other cases.
January 29, 2004, 12:28 PM
DarkMinion
Never ever ever check a bitmask with =
January 29, 2004, 2:08 PM
o.OV
[quote author=DarkMinion link=board=17;threadid=4976;start=0#msg41649 date=1075385289]
Never ever ever check a bitmask with =
[/quote]

Well I only did a minor fix on it.. and I'm not even sure exactly what you mean by that.. lol

I could do the fix like this..

[code]
If (flags And &H2) = &H2 Then
Form1.ChannelList.ListItems.Add 1, , Username, , ICON_GAVEL
ElseIf (flags And &H20) = &H20 Then
Form1.ChannelList.ListItems.Add 1, , Username, , ICON_SQUELCH
Else
Form1.ChannelList.ListItems.Add 1, , Username, , GetIcon
End If
[/code]
January 29, 2004, 6:15 PM
Networks
did u make columns in the list box? so that the icons go where they're supposed to.
January 29, 2004, 7:27 PM
UserLoser.
[quote author=Networks link=board=17;threadid=4976;start=0#msg41694 date=1075404433]
did u make columns in the list box? so that the icons go where they're supposed to.
[/quote]

Subclassing, or you can just use a ListView if you want columns and icons (which is a lot easier)
January 29, 2004, 7:43 PM
Myndfyr
[quote author=DarkMinion link=board=17;threadid=4976;start=0#msg41649 date=1075385289]
Never ever ever check a bitmask with =
[/quote]

Well thanks, I'm not a VB programmer, I do C/Java/C#, so I wouldn't know. It was intended more to point him in the right direction. :) When I check bitmasks in C#, I go:

[code]
if ( (flags & (int)UserFlags.Squelched) == UserFlags.Squelched)
// assign squelched icon
else if ( (flags & (int)UserFlags.Moderator) == UserFlags.Moderator)
// give it the gavel.
[/code]
etc.
January 30, 2004, 3:02 AM
Spht
[quote author=Myndfyre link=board=17;threadid=4976;start=0#msg41782 date=1075431773]
[quote author=DarkMinion link=board=17;threadid=4976;start=0#msg41649 date=1075385289]
Never ever ever check a bitmask with =
[/quote]

Well thanks, I'm not a VB programmer, I do C/Java/C#, so I wouldn't know. It was intended more to point him in the right direction. :) When I check bitmasks in C#, I go:

[code]
if ( (flags & (int)UserFlags.Squelched) == UserFlags.Squelched)
// assign squelched icon
else if ( (flags & (int)UserFlags.Moderator) == UserFlags.Moderator)
// give it the gavel.
[/code]
etc.
[/quote]

Same concept...
January 30, 2004, 4:00 AM

Search