mIRC Home    About    Download    Register    News    Help

Print Thread
Specific Countdown Timer #158209 02/09/06 12:07 AM
Joined: Sep 2006
Posts: 18
S
Skylax Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Sep 2006
Posts: 18
Ok i have tried and tried and tried. I need a Countdown timer that counts down to the Specific time, hours. And you can set it by typing a codeword such as !setdate <month> <day> <hour> <am/pm>.I would probably google mirc scripts or something to figure out how to do it myself, but i dont have the time between studing for school and construction on the house. Additional info is below. Thanks.
This would be greatly appreciated.
Three 'codewords' - one for setting it, one for help on how to set it, and one for telling how much time is left until the set time, or that repeats the set time back in a msg.
Example:
<to tell the date> (!howlong)
Time left until the event : <Countdown timer- Month, Day, hour)
<for help on how to set> (!sethelp)
To set the date and time, type !setcd <Month> <day> <hour> <am/pm> Example: !setcd May 21 5:00 pm

Re: Specific Countdown Timer #158210 03/09/06 03:45 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
This has been tested for a little bit, although I don't guarantee that it is flawless, I've done my best to ensure that people trying to fool it won't be able to. This is configured to manage multiple count down timers.
Code:
on *:text:!help:*:{
  cd.help
}
alias -l cd.help {
  .msg $nick To set count down date, use !cd [month] [day] &lt;year&gt; &lt;time&gt; &lt;am/pm&gt;
  .msg $nick Only [month] and [day] are required.  &lt;year&gt; will default to the current year, or next if the date has already passed.
  .msg $nick Midnight will be the default time, unless specified
  .msg $nick &lt;time&gt; can be in 12 or 24 hour format. If the 12 hour format is used, am will be the default
  .msg $nick $str($chr(46),20)
  .msg $nick To see how much time is left, use !cd &lt;count down number&gt;
  .msg $nick If &lt;count down number&gt; is left blank, then a list of all count downs will be shown
}
alias -l last.day {
  return $gettok(31 28 31 30 31 30 31 31 30 31 30 31,$1,32)
}
alias count_down {
  return $gettok($hget(count_down,$1).data,$3-,32)
}
on *:text:!cd*:*:{
  set %nick $iif($chan,$chan,$nick)
  if !$2 {
    var %a = 1, %b = $hget(count_down,0).item
    while %a &lt;= %b {
      .timer 1 %a .msg %nick Count down timer $hget(count_down,%a).item set for $count_down(%a) expires in $duration($timer($+(count.down,.,%a)).secs)
      inc %a
    }
  }
  elseif $2 isnum &amp;&amp; $hget(count_down,$2) {
    .msg %nick Count down timer $2 set for $gettok($hget(count_down,$2).data,$3-,32) expires in $duration($timer($+(count.down,.,$2)).secs)
  }
  else {
    ;get the month number in order to see how many days in the month
    var %month = $findtok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,$left($2,3),32)
    if !%month {        cd.help      }
    else {
      ;is year specified? if not use current year
      var %year = $iif($3 isnum,$3,$right($date,4))
      ;leap year?
      if %last.day == 28 &amp;&amp; ($calc(%year / 400) == $int($calc(%year / 400)) || $calc(%year / 4) == $int($calc(%year / 4))) {
        inc %last.day
      }
    }
    ;year or expiry time?
    var %time = $iif(!$3 || $3 isnum || $istok(am pm,$3,32),00:00:00,$3-)
    var %hour = $gettok(%time,1,58), %min = $gettok(%time,2,58), %sec = $gettok(%time,3,58), %day = $2
    if !%hour { %hour = 0 }
    if !%min { %min = 0 }
    if !%sec { %sec = 0 }
    ;recalculate the expiry date &amp; time based on forwarding from invalid entries
    while %sec &gt; 59 {
      inc %min
      dec %sec 60
    }
    while %min &gt; 59 {
      inc %hour
      dec %min 60
    }
    while %hour &gt; 23 {
      inc %day
      dec %hour 24
    }
    while %day &gt; $last.day(%month) {
      inc %month 
      dec %day $last.day($calc(%month - 1))
    }
    while %month &gt; 12 {
      inc %year
      dec %month 12
    }
    while %day &gt; $last.day(%month) {
      inc %month 
      dec %day $last.day($calc(%month - 1))
    }
    while %month &gt; 12 {
      inc %year
      dec %month 12
    }
    inc %count_down
    var %month.name $gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,%month,32)
    ;add entry to hash table for future reference
    .hadd -m count_down %count_down %nick $nick %month.name %day %year $+(%hour,:,%min,:,%sec) $iif(am pm,$gettok($1-,-1,32),$v1)
    activate_timer %count_down
  }
}
alias -l activate_timer {
  if !$1 {
    var %a = 1, %b = $hget(count_down,0).item
    while %a &lt;= %b {
      $+(.timer,count_down,.,%a) -o 1 $calc($ctime($gettok($hget(count_down,%a).data),$3-,32)) - $ctime) timer.up %a
      inc %a
    }
  }
  else {
    $+(.timer,count_down,.,$1) -o 1 $calc($ctime($gettok($hget(count_down,$1).data,$3-,32)) - $ctime) timer.up $1
  }
}
on *:start:{
  if !$hget(count_down) { .hmake count_down 10 }
  if $exists(count_down.hsh) { .hload count_down count_down.hsh }
  activate_timer
}
on *:exit:{
  .hsave -o count_down count_down.hsh
}
alias -l timer.up {
  var %chan = $gettok($hget(count_down,$1).data,1,32), %nick = $gettok($hget(count_down,$1).data,2,32)
  .msg %chan Timer set for $count_down($1) by %nick has now expired
} 


There's a lot there, including things you didn't ask for. If you have any questions about the code, specify what it is you don't understand and I'll do my best to explain.