Here, let me cut out all the "error" messages and explain it. It's actually not a hard-to-understand script.
Note that I would recommend using the code above as it will point out errors when someone using the commands incorrectly. I just removed them to make explaining easier. The parts removed are just to display errors if something is done incorrectly.
on *:text:add *:[color:red]#yourchan[/color]: {
[color:green]; Halt (return) if there aren't 3 parts to the command (the trigger, the filename, and the size), or if the filename is already in the table.[/color]
if ($3 == $null || $hget(PicData,$2) != $null) return
[color:green]; Otherwise, run the alias and send the filename and filesize to the alias.[/color]
AddPicData $2 $3
}
on *:text:update *:[color:red]#yourchan[/color]: {
[color:green]; Almost the same as above... halt if there aren't 3 parts, or, in this case, if the filename isn't added yet (you can't update something that isn't there)[/color]
if ($3 == $null || $hget(PicData,$2) == $null) return
[color:green]; Otherwise, run the alias (as above)[/color]
AddPicData $2 $3
}
on *:text:!kb:[color:red]#yourchan[/color]: {
[color:green]; Set up a loop to add up all the values in the table[/color]
var %c = 1
[color:green]; This is the total number of items in the table (we're looping from 1 to that)[/color]
var %i = $hget(PicData,0).item
while (%c <= %i) {
[color:green]; Add each value together into the one variable[/color]
var %picbytes = %picbytes + $hget(PicData,%c)
inc %c
}
[color:green]; When done, output the size. Using $bytes lets us see the total size in bytes,kb,mb,etc.[/color]
msg $chan There are $bytes(%picbytes).suf of pictures.
}
[color:green]; The alias to add the data[/color]
alias AddPicData {
[color:green]; Check to see if the table is made. If not, make it.[/color]
if ($hget(PicData,0).item == $null) {
hmake PicData 20
}
[color:green]; If the size is in kb, multiply the size by 1024 (this is the number of actual bytes rather than kb... it makes it easier to output a valid amount)[/color]
if (kb isin $2) { var %picbytes = $remove($2,kb) * 1024 }
[color:green]; This is the same thing, but for any that are in MB instead of kB. Multiple it by 1024 and again by 1024 to give the total bytes.[/color]
elseif (mb isin $2) { var %picbytes = $calc($remove($2,mb) * 1024 * 1024) }
[color:green]; Add the filename and bytes to the table.[/color]
hadd PicData $1 %picbytes
}
What makes it seem more complicated is that it inputs bytes into the table. The reason for this is because if someone adds a picture that is 1.5mb, you will want to differentiate between that and 1.5kb. Also, putting it into bytes will allow a nice, clean output using $bytes. Of course, if you don't ever use files that are over 1mb, then you can simply remove the mb section. I'd still leave the rest like it is. Note that I did make one small change to the kb/mb code... I wasn't thinking when I did it up.
This will be faster than trying to save it and examine the data from a file.
As a final note, you may want to consider adding a /hsave (on a timer) and /hload to the script if you want to avoid losing the data since hash tables are in memory and aren't saved automatically if you exit mIRC.
Oh, and if you wanted to, you could just use a single command to add and update ... it wouldn't matter since it would automatically update it if it was already there or add it if it wasn't... However, I did it like this (with the error messages in the script previously) so that you don't accidentally overwrite something or end up adding a new entry when you thought you were updating one (maybe because of a typo).
If you wanted to make it one command, remove the first two on texts, and replace them with:
on *:text:add *:[color:red]#yourchan[/color]: {
[color:green]; Halt (return) if there aren't 3 parts to the command (the trigger, the filename, and the size)[/color]
if ($3 == $null) return
[color:green]; Otherwise, run the alias and send the filename and filesize to the alias.[/color]
AddPicData $2 $3
}
Not really much different, except how it handles if the data is there or not.