Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Crim-Training on October 30, 2003, 04:38 PM

Title: away idle timers
Post by: Crim-Training on October 30, 2003, 04:38 PM
most can do it, now to teach me..

ive got my timer inplace (idleAway)

and this is as much as ive done

Private Sub IdleAway_Timer()
idleAway.Interval = 30000
Dim Mins As Integer
Mins = Mins + 1
CleanSlateBot1.Send "/away Has been idle for " & Mins & " Seconds."
End Sub


am i missing anything? can someone help me plz
Title: Re:away idle timers
Post by: iago on October 30, 2003, 05:16 PM
Did you set the initial interval?
Did you set it to enabled?

You aren't initializing Mins
You aren't remembering Mins
You're adding one to Mins every 30 seconds
You called Seconds Mins
Title: Re:away idle timers
Post by: MyndFyre on October 30, 2003, 05:40 PM
Trying to remember as much VB as I can...

Once you're connected, you start by initializing your Timer (assuming that it's called IdleTimer elsewhere):



' This code MUST go somewhere else in your code that makes it global
' for example, a module
Dim Mins As Integer
Dim Away As Boolean

' Start your timer upon connection to BNCS
Private Sub CleanSlateBot1_Connect ()
   ' .... other init stuff here
   IdleTimer.Interval = 60000
   Mins = 0
   Away = False
   IdleTimer.Start
End Sub

Private Sub IdleTimer_Tick()
   Mins = Mins + 1
   If Away Then
       CleanSlateBot1.Send "/away"
       Away = False
   End If
   CleanSlateBot1.Send "/away Has been idle for " & Mins & " minutes."
   Away = True
End Sub


Now, if you wanted to do something so that you would reset the timer whenever typing happened:


Private Sub TextBox1_TextChanged()
   Mins = 0
   If (Away) Then
       CleanSlateBot1.Send("/away")
       Away = False
   End If
   IdleTimer.Stop
   IdleTimer.Start
End Sub


Now, I'm not sure if my code works or not, because I'm not a VB6 programmer.  What I want you to understand is why I did what I did.

Your Mins variable is going to be available throughout your code.  It needs to be accessible at a global level.  That's why we declared it in a module.

You want your timer to update your away message each minute.  Thus, you set your interval to 60 seconds (or 60,000 milliseconds) so that its event handler is called every 60 seconds.  You also want to initialize your minutes count to zero, so that the first time your away message is set, it sets to 1 minute.

Each time your timer ticks, it increments your minutes count, and sends two messages over CSB: the first is a standard "/away" to clear your previous away message, and the second sets your new away status.  If you weren't previously marked away (this is where the Boolean value Away comes in), then it doesn't send the first one.  That way your away states are kept straight (assuming B.net responds as it should).  

I'm not sure how CSB works, but I assumed that you need to have a textbox in the form to enter your chat text.  I just called it "TextBox1" and wired up to the TextChanged event.  Since you're no longer idle when you are typing something at the console, it clears your away status and restarts your timers.  The .Stop then .Start commands effectively reset your timer's count to zero.

Hope this helps - and works!

--Rob
Title: Re:away idle timers
Post by: warz on October 30, 2003, 05:41 PM
You're sending your idle message every 30 seconds?
Title: Re:away idle timers
Post by: iago on October 30, 2003, 05:58 PM
Ugh, you really ought to let him figure stuff out for himself; he won't learn anything if you copy/paste!!
Title: Re:away idle timers
Post by: Kp on October 30, 2003, 11:11 PM
Quote from: Myndfyre on October 30, 2003, 05:40 PM
Private Sub IdleTimer_Tick()
   Mins = Mins + 1
   If Away Then
       CleanSlateBot1.Send "/away"
       Away = False
   End If
   CleanSlateBot1.Send "/away Has been idle for " & Mins & " minutes."
   Away = True
End Sub


Each time your timer ticks, it increments your minutes count, and sends two messages over CSB: the first is a standard "/away" to clear your previous away message, and the second sets your new away status.  If you weren't previously marked away (this is where the Boolean value Away comes in), then it doesn't send the first one.  That way your away states are kept straight (assuming B.net responds as it should).
It's actually not necessary to send the first /away.  Attempting to set one away message while you already have another in place immediately overwrites the old one.  You don't need to explicitly clear it first.
Title: Re:away idle timers
Post by: Crim-Training on October 31, 2003, 01:26 AM
thx mate

and iago, i do like to learn its just it kept me up til 3am working on it and i needed help.

oh and i only named it "Mins" cuz its old names was "Fuckers"

EDIT: wont compile, "IdleTimer.Start"
Title: Re:away idle timers
Post by: iago on October 31, 2003, 01:37 AM
Figure it out! That's the only way to learn.  :P
Title: Re:away idle timers
Post by: Crim-Training on October 31, 2003, 01:41 AM
as much as i hate spamming, the timer wont change from 1min

Private Sub CleanSlateBot1_Connect()
   IdleTimer.Interval = 60000
   Mins = 0
   Away = False
   IdleTimer.Start
End Sub

Private Sub IdleTimer_Tick()
   Mins = Mins + 1
   If Away Then
       CleanSlateBot1.Send "/away"
       Away = False
   End If
   CleanSlateBot1.Send "/away Has been idle for " & Mins & " minutes."
   Away = True
End Sub

Private Sub Info_TextChanged()
   Mins = 0
   If (Away) Then
       CleanSlateBot1.Send ("/away")
       Away = False
   End If
   IdleTimer.Stop
   IdleTimer.Start
End Sub


anyone know why ?
Title: Re:away idle timers
Post by: warz on October 31, 2003, 07:37 AM
Because, you're incrimenting Mins but not doing anything with it. I suggest setting the idle interval to 1 second, and checking the value of Mins before sending the idle message. Something like...


if mins >= 120 then
        send "/message"
        mins = 0
end if
Title: Re:away idle timers
Post by: Grok on October 31, 2003, 08:21 AM
+1 to warz because ... well because he only had  +8.
Title: Re:away idle timers
Post by: Dyndrilliac on November 02, 2003, 02:05 PM
Hm, whats wrong with just:

Dim varIdle As String

Private Sub IdleMsg_Timer()
varIdle = GetStuff("Config", "Main", "IdleMessage")
Send varIdle '<-- This is how mines setup, I'm not using CSB
End Sub


And on connect have it...

IdleMsg.Enabled = True
IdleMsg.Interval = varIdleTick * 100 '(Sets it up for seconds instead of the normal milliseconds)


And last but not least, on disconnect:

IdleMsg.Enabled = False

That works for me and it's incredibly simple.
Title: Re:away idle timers
Post by: Crim-Training on November 03, 2003, 03:05 AM
cuz thats not what i was after.. Anyway the problem has been resolved, if anyone would like to know how feel free to pm me or aim me or trick (ps. thx for the help trick)
Title: Re:away idle timers
Post by: iago on November 03, 2003, 03:13 AM
Quote from: Crim-Training on November 03, 2003, 03:05 AM
cuz thats not what i was after.. Anyway the problem has been resolved, if anyone would like to know how feel free to pm me or aim me or trick (ps. thx for the help trick)

Why wouldn't you just post it here?
Title: Re:away idle timers
Post by: Crim-Training on November 03, 2003, 06:09 AM
Quote from: iago on November 03, 2003, 03:13 AM
Why wouldn't you just post it here?

i dont want you to laugh and make a fool out of myself

well.. if u must ill upload
http://zonebot.ath.cx/users/crim/awayidle.zip
Title: Re:away idle timers
Post by: hismajesty on November 03, 2003, 10:23 AM
Quote from: Crim-Training on November 03, 2003, 06:09 AM
Quote from: iago on November 03, 2003, 03:13 AM
Why wouldn't you just post it here?

i dont want you to laugh and make a fool out of myself

well.. if u must ill upload
http://zonebot.ath.cx/users/crim/awayidle.zip

Why would they laugh? As long as your code works I see no reason to laugh. (Except for the fact that you spelled 'milliseconds' wrong :P)
Title: Re:away idle timers
Post by: Crim-Training on January 11, 2004, 11:55 AM
Quote from: Crim-Training on November 03, 2003, 06:09 AM
Quote from: iago on November 03, 2003, 03:13 AM
Why wouldn't you just post it here?

i dont want you to laugh and make a fool out of myself

well.. if u must ill upload
http://zonebot.ath.cx/users/crim/awayidle.zip



sorry to bring this back up, but did anyone download that file ? i lost it when i had to format
Title: Re:away idle timers
Post by: Stealth on January 11, 2004, 03:50 PM
Quote from: Dyndrilliac on November 02, 2003, 02:05 PM
IdleMsg.Enabled = True
IdleMsg.Interval = varIdleTick * 100 '(Sets it up for seconds instead of the normal milliseconds)


Seconds = Milliseconds * 1000 (not 100) :)