Cheiron, use
$ial($banmask,$chan,0).nick
in conjunction with a while loop. This will always return the correct banned nickname if a ban mask doesn't contain the nickname. This is my approach toward what your code should have been become of:
on *:ban:#: bklog
on *:kick:#: bklog
alias -l bklog {
window $iif($event == kick,@kicks,@bans)
if ($event == kick) {
echo -t @kicks [kick tracker] $nick kicked $knick from $chan on $date at $time
}
else {
var %b = 1
while ($ialchan($banmask,$chan,%b).nick) {
echo -t @bans [ban logger] $nick set the following ban against the user $v1 on $time $date in $chan
inc %b
}
}
}