Very Simple Time Counter (Cronometer)

By carlosrevilla on Dec 16, 2009

Well this bot counts time between two commands using variables its very very simple but useful

!start Counter has initiated !stop Timer has been stopped at 13 seconds ```mirc on $*:TEXT:/^!(start|stop|info)$/iS:#:{ if ($regml(1) == start && !$($+(%,startime,.,$nick),2)) { set $+(%,startime,.,$nick) $nick $ctime msg # Counter For $gettok($($+(%,startime,.,$nick),2),1,32) has been initiated } if ($regml(1) == stop && $nick == $gettok($($+(%,startime,.,$nick),2),1,32)) { msg # Timer For $gettok($($+(%,startime,.,$nick),2),1,32) has been stopped at 12 $duration($calc($ctime - $gettok($($+(%,startime,.,$nick),2),2,32))) unset $+(%,startime,.,$nick) } if ($regml(1) == info && !$($+(%,floodt,.,#),2)) { set -eu30 $+(%,floodt,.,#) on msg # Created by Carlosrevilla. Special Thanks to Napa182 for his help. Get The snippet @ http://www.hawkee.com/snippet/7032/ } } ```

Comments

Sign in to comment.
gooshie   -  Dec 24, 2009

If the bot disconnects but mIRC doesn't close then
the hash table is retained anyway.. it only gets
flushed if you use /hfree or close mIRC.
The only reason I use a set variable is if I want
to retain data across sessions and make it avaiable
to all connections (which is very limited).
I use local variables as much as possible.. then if
I need to retain the data during session I use hash.
If I need to retain data across session and it's like
connect data for diff networks and such I use ini
format with a config.txt in mIRC root (so it's easily
available under help). I plan to one day do the config
so it uses /hload and /hsave and access and change the
data/settings through the hash to limit drive accesss
for those functions. I'm trying to future proof my
scripts so when I get an SSD I will be ready.

 Respond  
napa182   -  Dec 24, 2009

about the clean up i agree on but i still think hash is over kill for a script like this.
and what i ment about saving on exit was if the bot pinged nothing more.

 Respond  
gooshie   -  Dec 23, 2009

napa182
Ok, so we decide we need to retain this timer data across
sessions because we envision that maybe someone will be timing
something important like their wife's contractions and the bot
has to reboot so we don't want to lose this valuable data. So
I script up hsave/hload. Then the question is, how long do we
need to retain these records? I can envision a more likely
event being that people will start timers and then forget all
about them leaving orphaned set variables in the variable file.
Now we are gonna need some cleanup script but how do we decide
what gets deleted? Everything every month or only data that is
over a month old? I wont go into how if the bot is on more than
one network that the possiblity of two nicks being the same can
intefer with each others timers or how if someone figures out
the set variable thing they can change nicks and create bunches
of orphaned variables over time. That whole /set -e looks better
all the time...

 Respond  
gooshie   -  Dec 23, 2009

FordLawnmower
When you read that it may sound like alot but have
you checked how much memory it actually uses?

It says: if you expect that you'll be storing 1000 items in the table,
a table of N set to 100 is quite sufficient.

I'm not sure how to interpet that statement in relation
to how much memory it will use. I check my memory use
and can't see it changing between storing something and
then freeing the table.

I have several/many hash tables in my scripts and plan
to one day try to conglomerate them into one to four
main ones. I used them for many years without any
problems. I'm more concerned with writing to harddrive
or SSD or flash memory.

 Respond  
napa182   -  Dec 22, 2009

to me it's a waste to use hash, and i only used -e on the flood var. So if you are going to use hash you may as well add a save for the nicks on exit as well as a load on connect. for this script a var is the way to go...
but like i said To each their own.

 Respond  
FordLawnmower   -  Dec 22, 2009

The problem that I see with using hashtables for one record like this is the /hadd -m.
If you add -sm you will see something like this -->> * Made hash table 'tester' (100)

  • Added item 'test' to hash table 'tester'

It sets aside enough memory for about 1000 records when you use -m. You are much better off just setting the var.

 Respond  
gooshie   -  Dec 22, 2009

Aucun50
Why so emo? I was just pointing out the advantages
to using hash tables. The waste is actually in using
a set variable. Why favor one type of data storage
over another? Why not learn the advantages and dis-
advantages of the various data storage methods so
you can apply the apropriate one?
Btw, it's one variable for the flood control plus
one variable each per user.

 Respond  
Aucun50   -  Dec 22, 2009

Stfu gooshie hash tables for this would be a waste. It's not like that one variable is going to spam up and slow down your computer is it?

 Respond  
gooshie   -  Dec 22, 2009

Set variables require harddrive write/read hash tables do not.
I see no point in using a set variable since the -e flag will
make it act simular to a hash table anyway.

 Respond  
napa182   -  Dec 22, 2009

you can go with hash, but i just don't see the point of useing hash for this script when you can use a var.

eh to each their own i guess...

 Respond  
gooshie   -  Dec 22, 2009
on $*:TEXT:/^!(start|stop|info)$/iS:#:{
  var %c $regml(1),%s $($+(%,startime,.,$nick),2),%m msg # Timer For $nick has been
  if %c = start && !%s {
    set $+(%,startime,.,$nick) $ctime
    %m initiated
  }
  if %c = stop && %s {
    unset $+(%,startime,.,$nick)
    %m stopped at12 $duration($calc($ctime - %s))
  }
  if %c = info && !$($+(%,floodt,.,#),2) {
    inc -eu30 $+(%,floodt,.,#)
    msg # Created by Carlosrevilla. Special Thanks to Napa182 for his help. Get The snippet @ http://www.hawkee.com/snippet/7032/
  }
}

You could use hash table

on $*:TEXT:/^!(start|stop|info)$/iS:#:{
  var %c $regml(1),%s $hget(Crono,$nick),%m msg # Timer For $nick has been
  if %c = start && !%s {
    hadd -m Crono $nick $ctime
    %m initiated
  }
  if %c = stop && %s {
    hdel Crono $nick
    %m stopped at12 $duration($calc($ctime - %s))
  }
  if %c = info && !$hget(Crono,#) {
    hinc -mu30 Crono #
    msg # Created by Carlosrevilla. Special Thanks to Napa182 for his help. Get The snippet @ http://www.hawkee.com/snippet/7032/
  }
}
 Respond  
slub77   -  Dec 22, 2009

why not have just edited this one?

 Respond  
napa182   -  Dec 20, 2009

lol Thank you for that ;x

 Respond  
carlosrevilla   -  Dec 20, 2009

UPDATED::::
Created by Carlosrevilla. Special Thanks to Napa182 for his help. Get The snippet @ http://www.hawkee.com/snippet/7032/

 Respond  
slub77   -  Dec 17, 2009

u still ain't put the end bracket on

 Respond  
Silo   -  Dec 17, 2009

Awesome and thank you very much!!! Have you been $regexing for long?

 Respond  
napa182   -  Dec 17, 2009

the $ Matches the end of a string and the /iS the i case-insensitively and S acts like $strip

if you want to learn them read up on a few tutts you can start with this one http://www.hawkee.com/phpBB2/viewtopic.php?t=9764

 Respond  
Silo   -  Dec 17, 2009

Thanks for the info, nappa. That is very interesting. So what is $/iS all about? I have to learn this stuff!!!

 Respond  
napa182   -  Dec 17, 2009

@Silo yes it is. i am matching start or stop or info prefixed with !

So in order for it to work first chr has to be ! fallowed by either start stop or info

 Respond  
Silo   -  Dec 16, 2009

napa could you describe this line for me please?

on $*:TEXT:/^!(start|stop|info)$/iS:#:{

I can see you're using $regex throughout the script, but is the line I am discussing an extension of $regex?

Cheers

 Respond  
napa182   -  Dec 16, 2009

or you can also make it so more than one person can use it at the same time

on $*:TEXT:/^!(start|stop|info)$/iS:#:{
  if ($regml(1) == start && !$($+(%,startime,.,$nick),2)) { 
    set $+(%,startime,.,$nick) $nick $ctime 
    msg # Counter For $gettok($($+(%,startime,.,$nick),2),1,32) has been initiated
  }
  if ($regml(1) == stop && $nick == $gettok($($+(%,startime,.,$nick),2),1,32)) { 
    msg # Timer For $gettok($($+(%,startime,.,$nick),2),1,32) has been stopped at 12 $duration($calc($ctime - $gettok($($+(%,startime,.,$nick),2),2,32))) 
    unset $+(%,startime,.,$nick) 
  }
  if ($regml(1) == info && !$($+(%,floodt,.,#),2)) { 
    set -eu30 $+(%,floodt,.,#) on 
    msg # Created by Carlosrevilla. Get The snippet @ http://www.hawkee.com/snippet/7032/
  }
}
 Respond  
Aucun50   -  Dec 16, 2009

Missing a end bracket. Also you could make this better like:

on *:text:*:#: {
  if ($1 == !start) {
    if (!%startctime) {
      msg $chan Counter has initiated
      set %startctime $ctime
    }
    else {
      msg $chan Counter has already started
    }
  else if ($1 == !stop) {
    if (%startctime) {
      msg $chan Timer has been stopped at 12 $calc(%endctime - %startctime) Seconds
      msg $chan Or $duration($calc($ctime - %startctime))
      unset %startctime
    else {
      msg $chan Counter hasn't been started
    }
  else if ($1 == !info) {
    msg $chan This bot was created by Carlosrevilla and shared to the Hawkee community
  }
}
set %startctime 0
set %endctime 0

It's better to use unset %startctime and just delete the variable.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.