mIRC Homepage
Posted By: kantremem Setting up a timer - 29/09/06 04:15 AM
So far I have :

on *:CONNECT: { .timerstart 19:34:00 1 1 .timermsg 0 10 msg #channel hello | .timerend 4:00:00 1 1 .timermsg off }

What I want to do is say hello between the hours of 7:34pm to 4:00am everyday even if I get disconnected and reconnected to the IRC server. For example, if at 8:35pm my internet connection dies, and mirc reconnects to the server and rejoins the channel, I still want "hello" to be said as if I wasn't disconnected - never missing a heartbeat. So I want to say "hello" strickly between the hours of 7:34pm to 4:00am even if my connection dies and reconnects - I still want "hello" to be said in circumstances like that.

So what commands do I add?
Posted By: RusselB Re: Setting up a timer - 29/09/06 05:00 AM
First off, I wouldn't have this as an on connect event, since there's no guarantee that you're going to be in a channel for the message to be sent to via the timer. I changed it to an on join event, and did a bit of re-writing, coming up with
Code:
 on me:*:join:#:{
  if !$timer(end) {
    .timerend 4:00 1 1 timermsg off
  }
  if ($asctime(HH:nn) < 19:34) && ($v1 > 04:00) && !$timer(start)   {
    .timerstart 19:34 1 1 msg $chan
  }
  else {
    msg $chan
  }
}
alias msg {
  .timermsg 0 10 msg $1 hello
}
on *:disconnect:{
  .timermsg off
  .timerstart off
  .timerend off
}
 

Please note that you can't have a script that literally "never missing a heartbeat", since the script won't work if you're disconnected.
However, aside from the condition that you must be connected, I think the above script will work per your request.
Posted By: Lpfix5 Re: Setting up a timer - 29/09/06 05:56 AM
Quote:

Please note that you can't have a script that literally "never missing a heartbeat", since the script won't work if you're disconnected.
However, aside from the condition that you must be connected, I think the above script will work per your request.


You can actually never miss that heart beat :P

timer -o DATAHOUR DATAXTIMES DATAINTERVAL COMMAND

will create whats called a offline timer meaning that should it occur the user is disconnected or something the command will still work or the timer in question I should say
Posted By: RusselB Re: Setting up a timer - 29/09/06 06:33 AM
Yes, an offline timer would do that, but the command line (from my script, msg $1 hello), would generate an error when offline, since no channel could be passed to the alias via $1.
Posted By: Lpfix5 Re: Setting up a timer - 29/09/06 08:22 AM
In theory thats correct however is not quite the hard problem to fix

A simple check to see if server is null meaning connection is not current.

if (!$server) { echo -a result }
else { perform old stuff from the script }
Posted By: billythekid Re: Setting up a timer - 29/09/06 09:06 AM
i'm not keen on using msg as an alias name since there is already a built in /msg command.
Posted By: kantremem Re: Setting up a timer - 29/09/06 07:33 PM
Will the code posted by RusselB repeat itself 24/7, 365/year?(as long as I am connected to the irc server) And since msg is an alias already built into mirc, what code should I use to replace:

alias msg {
.timermsg 0 10 msg $1 hello
}

?
Posted By: Lpfix5 Re: Setting up a timer - 29/09/06 07:45 PM
Quote:
First off, I wouldn't have this as an on connect event, since there's no guarantee that you're going to be in a channel for the message to be sent to via the timer. I changed it to an on join event, and did a bit of re-writing, coming up with
Code:
 on me:*:join:#:{
  if !$timer(end) {
    .timerend 4:00 1 1 timermsg off
  }
  if ($asctime(HH:nn) < 19:34) && ($v1 > 04:00) && !$timer(start)   {
    .timerstart 19:34 1 1 [color:red]T[/color]msg $chan
  }
  else {
    [color:red]T[/color]msg $chan
  }
}
alias [color:red]Tmsg[/color] {
  .timermsg 0 10 msg $1 hello
}
on *:disconnect:{
  .timermsg off
  .timerstart off
  .timerend off
}
 

Please note that you can't have a script that literally "never missing a heartbeat", since the script won't work if you're disconnected.
However, aside from the condition that you must be connected, I think the above script will work per your request.


look above @ red code.
Posted By: kantremem Re: Setting up a timer - 29/09/06 09:23 PM
How do I repeat the above code so it does this everyday?

I tried:

alias repeat { on me:*:join:#:{
if !$timer(end) {
.timerend 4:00 1 1 timermsg off
}
if ($asctime(HH:nn) < 19:34) && ($v1 > 04:00) && !$timer(start) {
.timerstart 19:34 1 1 Tmsg $chan
}
else {
Tmsg $chan
}
}
alias Tmsg {
.timermsg 0 10 msg $1 hello
}
on *:disconnect:{
.timermsg off
.timerstart off
.timerend off
}
}

/timer1 0 500 /repeat

but that doesn't work.
Posted By: kantremem Re: Setting up a timer - 29/09/06 09:51 PM
What does "$v1" mean in :

if ($asctime(HH:nn) < 19:34) && ($v1 > 04:00) && !$timer(start) {
.timerstart 19:34 1 1 Tmsg $chan

?
Posted By: deegee Re: Setting up a timer - 29/09/06 10:30 PM
Directly from mirc.hlp
Quote:
$v1 & $v2

Returns the first and second parameters of an if-then-else comparison. So, in the case of this comparison:

if (text isin sometext) { ... }

$v1 will return "text" and $v2 will return "sometext".

"if ($asctime(HH:nn) < 19:34) && ($v1 > 04:00)"
19:34 would be $v2
Posted By: RusselB Re: Setting up a timer - 29/09/06 10:39 PM
Under those conditions, yes my code would work 24/7 365 days/year (366 for leap years). You can use msg as the alias name, although it would be a good idea to use something else, since /msg is a built in command. If you use msg as the alias, you'll have to remember to use /!msg <nick/channel> <message> in order for the built in command to run, rather than the alias. I'm honestly not sure why I didn't catch that when I wrote the code.
Posted By: kantremem Re: Setting up a timer - 29/09/06 10:49 PM
It's only 3:43pm and the script is already saying "hello." I want it to say hello inbetween the hours of 7:34pm to 4:00am.
Posted By: RusselB Re: Setting up a timer - 29/09/06 11:44 PM
Sorry about that, I re-did the method of determining the correct start and end times. Here's the new
Code:
on me:*:join:#:{
  if !$timer(end) {
    .timerend 4:00 1 1 timermsg off
  }
  if ($calc($ctime - $ctime($date 00:00:00)) &lt; 70440) &amp;&amp; ($v1 &gt; 14400) &amp;&amp; !$timer(start)   {
    .timerstart 19:34 1 1 tmsg $chan
  }
  else {
    tmsg $chan
  }
}
alias tmsg {
  .timermsg 0 10 msg $1 hello
}
on *:disconnect:{
  .timermsg off
  .timerstart off
  .timerend off
} 

I also changed the alias name so that it won't be confused with the built-in /msg command.
Posted By: kantremem Re: Setting up a timer - 30/09/06 12:04 AM
No problem, but even if I copy and pasted your new command in the remote window, it still says and repeats hello (the time now is 5:01pm) before 7:34pm.
Posted By: RusselB Re: Setting up a timer - 30/09/06 03:12 AM
I doin't know what you're doing, but I just retested the code, after changing the time on my system to check the code without having to wait the full time (as my normal time at this hour would have it working based on your specified times), and it worked exactly as the script calls for.

Make sure you don't have an old version of the script still running.
Posted By: kantremem Re: Setting up a timer - 30/09/06 03:46 AM
You were right. I was running some other mirc scripts and I guess it was conflicting with their timers. Thank you so much for this, I really do like it a lot! smile
Posted By: kantremem Re: Setting up a timer - 02/10/06 05:04 AM
I'm having trouble making the code repeat everyday, month, year, leap year etc. What is the code to make RusselB's code repeat everyday, month, year, etc?
Posted By: Lpfix5 Re: Setting up a timer - 02/10/06 05:20 AM
well theres many ways you can setup the timer for every week/month/year example

.timerYEAR 0 xnumberofsecondstillyear2007 commandhere

or have it condition as a if statement like for example

on *:JOIN:#:{
if ($date(yy) == 06) { run timer here }
}
Posted By: RusselB Re: Setting up a timer - 02/10/06 05:21 AM
OK, I think what you mean, is that once the timer stops at 4 am, it doesn't restart at 5:34 pm. If this is correct, then the following code will work as a replacement for my original.
Code:
 on me:*:join:#:{
  if !$timer(end) {
    .timerend 4:00 1 1 timermsg off
    .timerstart 19:34 1 1 tmsg $chan
  }
  if ($calc($ctime - $ctime($date 00:00:00)) &lt; 70440) &amp;&amp; ($v1 &gt; 14400) &amp;&amp; !$timer(start)   {
    .timerstart 19:34 1 1 tmsg $chan
  }
  else {
    tmsg $chan
  }
}
alias tmsg {
  .timermsg 0 10 msg $1 hello
}
on *:disconnect:{
  .timermsg off
  .timerstart off
  .timerend off
} 
 


I forgot to mention this earlier, but due to the way the timers work, the first hello message won't go until 10 seconds after the script actually starts and the last hello message will actually be displayed 10 seconds after the script ends. So the timerstart timer won't actually produce a message until 5:34:10 pm and the last message will go out at 4:00:10 am
Posted By: RusselB Re: Setting up a timer - 02/10/06 05:23 AM
The code already uses an ON JOIN event.
Posted By: Lpfix5 Re: Setting up a timer - 02/10/06 05:37 AM
I know that I meant it as for to add a if statement in the script
Posted By: kantremem Re: Setting up a timer - 02/10/06 05:53 AM
I tried copy and pasting RuesselB's new code in my remote window, and now it's saying hello before the time it's suppose to be saying hello. I change my time clock to 6:50pm, and the script isn't suppose to say hello until 7:34pm. Thank you again or all your help, I really am thankful for it.
Posted By: RusselB Re: Setting up a timer - 02/10/06 07:27 AM
OK..This should work for you (I did test it briefly using the same method of changing my system time)
Code:
 on me:*:join:#:{
  if !$timer(end) {
    .timerend 4:00 1 1 tmsg
  }
  if ($calc($ctime - $ctime($date 00:00:00)) &lt; 70440) &amp;&amp; ($v1 &gt; 14400) &amp;&amp; !$timer(start)   {
    .timerstart 19:34 1 1 tmsg $chan
  }
  else {
    tmsg $chan
  }
}
alias tmsg {
  if !$1 {
    timermsg off
    .timerstart 19:34 1 1 tmsg $chan
  }
  else {
    .timermsg 0 10 msg $1 hello  
  }
}
on *:disconnect:{
  .timermsg off
  .timerstart off
  .timerend off
} 
 
I'm not sure why, but I've got the feeling this could be written up better, although, exactly how & why escpaes me at the moment.
Posted By: kantremem Re: Setting up a timer - 02/10/06 10:29 AM
Yes! That did the trick. Thank you so much!
Posted By: kantremem Re: Setting up a timer - 03/10/06 05:10 AM
Sorry, I thought it did the trick, but when I tested it, it does not repeat. The timer works inbetween 7:34pm and 4:00am for the first time around. But when it tries to repeat those times the second time around, it doesn't repeat. The timer just says * timer start 19:34.
Posted By: RusselB Re: Setting up a timer - 03/10/06 06:19 AM
OK...Almost a complete re-write, and while it doesn't work the way you wanted, as in starting and stopping the timer at certain times, this does work and has been tested for several times.
Code:
 on me:*:join:#:{
  .timermsg 0 10 tmsg $chan
}
alias tmsg {
  if $time &gt; 19:34:00 || $time &lt; 04:00:00 {
    .msg $1 hello
  }
}
on *:disconnect:{
  .timermsg off
} 
 
Posted By: kantremem Re: Setting up a timer - 03/10/06 10:33 AM
Thank you again for all your help. You helped solve the problem I was having. I really mean it this time. THANK YOU!
© mIRC Discussion Forums