You can loop through the contents of an INI file using the $ini()
identifier. $ini(cookies.ini, $chan, 0)
will return the total of people with a record on that channel, whereas $ini(cookies.ini, $chan, N)
will return the name of the Nth person (which can then be passed as the last parameter in $readini()
).
Furthermore, don't include the messages with the if/elseif/else structure inside the while loop; you'll probably want to message the outcome once, after the highest record has been found:
on *:TEXT:!winning:#:{
var %i = 1, %highestCookies = 0, %highestUser
; This will run as long as %i is smaller than or equal to the number of lines in the ini section $chan
while (%i <= $ini(cookies.ini, $chan, 0)) {
; As we loop through the file, store the item name (the nickname) and the cookies (the value)
var %user = $ini(cookies.ini, $chan, %i), %cookies = $readini(cookies.ini, n, $chan, %user)
; Is this the highest found so far?
if (%cookies > %highestCookies) {
var %highestCookies = %cookies
var %highestUser = %user
}
inc %i
}
; Now that we have the correct values in our variables, display the message once
if (%highestCookies == 1) {
msg $chan %highestUser is winning with %highestCookies count.
}
elseif (%highestCookies > 1) {
msg $chan %highestUser is winning with %highestCookies counts.
}
else {
msg $chan No one has any count! Must try harder!
}
}
Edit: Fixed an issue that caused no higher values to be found because %highestCookies was assigned a $null value instead of 0.
As for your second question, it's not possible to have different script files for different channels. However, you could modify the location parameter in the event catchers so it only catchers events on specific channels. As an example, this is how an on TEXT
would look like:
; This event will only listen to the word "hello" in #directpixel and #stackoverflow
on *:TEXT:hello:#directpixel,#stackoverflow:{
msg $chan Hello $nick $+ !
}