To calculate an average, you will need, their Join Time, Part/Quit Time, and How many times they have joined in total, if thats what your after, see an example full script below.
If however you just want the difference, you need Join time, and part/quit time and the following:
$duration($calc($ctime([color:red]QUIT/PART-TIME) - $ctime(JOINTIME)))[/color]
i.e. $duration($calc($ctime(9/8/04 7:31:50) - $ctime(9/8/04 7:01:10)))
A full example, of a script to gather average online times, replacing the red only, trigger is !avgtime [nickname].
alias avgtime.channel { return [color:red]#channel1 #channel2 }
alias avgtime {
if (!$hget(avgtime)) {
hmake avgtime 5000
if ($file(avgtime.hash)) { hload avgtime $+(",$mircdir,avgtime.hash,") }
}
else { hsave -o avgtime avgtime.hash }
}
On *:Join:#:{
if (($istok($avgtime.channel,$chan,32)) && (!$hget(tmpavgtime,$nick))) {
avgtime
hadd -m tmpavgtime $nick $ctime
hinc -m avgtime $+($nick,.visits) 1
}
}
On !*:Part:#:{
if (($istok($avgtime.channel,$chan,32)) && ($hget(tmpavgtime,$nick))) {
avgtime
hinc -m avgtime $nick $calc($ctime - $hget(tmpavgtime,$nick))
.hdel tmpavgtime $nick
}
}
On !*:Quit:{
var %i = $comchan($nick,0)
while (%i) {
if (($istok($avgtime.channel,$comchan($nick,%i),32)) && ($hget(tmpavgtime,$nick))) {
avgtime
hinc -m avgtime $nick $calc($ctime - $hget(tmpavgtime,$nick))
.hdel tmpavgtime $nick
return
}
dec %i
}
}
On !*:Text:!avgtime*:#:{
var %avgnick $iif($2,$2,$nick)
if (!$hget(avgtime,%avgnick)) {
if ($hget(tmpavgtime,%avgnick)) { msg $chan This is %avgnick $+ 's first visit, and has been here for, $duration($calc($ctime - $ifmatch)) }
else { msg $chan I have no record of, %avgnick $+ . }
}
else {
var %tmp = $calc($ctime - $hget(tmpavgtime,%avgnick))
if ((!%tmp) || (!$hget(tmpavgtime,%avgnick))) { %tmp = 0 }
msg $chan %avgnick has visited $calc($hget(avgtime,$+(%avgnick,.visits)) + 1) time(s), $iif(%tmp > 0,and has been here for $duration(%tmp) this visit) averaging, $duration($calc(($hget(avgtime,%avgnick) + %tmp) / $calc($hget(avgtime,$+(%avgnick,.visits)) + 1))) per visit.
}
}
[/color]
Eamonn.