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/ } } ```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.
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...
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.
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)
It sets aside enough memory for about 1000 records when you use -m. You are much better off just setting the var.
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.
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/
}
}
UPDATED::::
Created by Carlosrevilla. Special Thanks to Napa182 for his help. Get The snippet @ http://www.hawkee.com/snippet/7032/
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
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/
}
}
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.