on *:text:!top*:#: {
if ($2 < 1 || $0 < 2) {
msg $chan /me $nick to use the !top command you must specify a positive number.
}
elseif ($2 > 10) {
msg $chan /me $nick you cannot specify a number greater than 10.
}
else {
var %ID = $ini(%rosterFile, 0)
if ($2 > %ID) {
msg $chan /me $nick there are only %ID people in the level system.
}
else {
write -c %topFile
var %topList = The $2 highest level users:
var %i = 1
while (%i <= $2) {
$getTopID()
var %name = $readini(%topFile, %i, name)
var %points = $readini(%topFile, %i, levels)
if (%i != $2) {
%topList = $+(%topList, $chr(32), %name, $chr(32), %points, $chr(44))
}
else {
%topList = $+(%topList, $chr(32), %name, $chr(32), %points)
}
inc %i
}
msg $chan /me %topList
}
}
}
// ------------------------------------------------------------------------------------------------------------------------
// Format: $getTopID()
// Gets the ID with the highest number of points that is not already in the temp file
alias -l getTopID {
var %rosterID = $ini(%rosterFile, 0)
var %topID = $ini(%topFile, 0)
var %highestPoints = 0
var %highestID = -1
var %i = 1
while (%i <= %rosterID) {
var %points = $readini(%rosterFile, %i, levels)
if (%points >= %highestPoints) {
var %topNameFound = $false
var %j = 1
while (%j <= %topID) {
var %name = $readini(%rosterFile, %i, name)
var %topName = $readini(%topFile, %j, name)
if (%name == %topName) {
%topNameFound = $true
break
}
inc %j
}
if (%topNameFound == $false) {
%highestPoints = %points
%highestID = %i
}
}
inc %i
}
var %highestName = $readini(%rosterFile, %highestID, name)
writeini -n %topFile $calc(%topID + 1) name %highestName
writeini -n %topFile $calc(%topID + 1) levels %highestPoints
}