This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Top10 Help (Custom Design)

Old posts that have not been replied to for several years.
Locked
D
Darkj
Halfop
Posts: 86
Joined: Sun Jul 06, 2003 9:58 pm

Top10 Help (Custom Design)

Post by Darkj »

The way I am doing this seems way to complicated. There is like 200 lines of code for this, which isn't quite right. Now my code my be newbish, its kind of my first attempt at top10 scores. It does work, surprisingly enough, but it sucks.

The way the score database is designed is:
[nick]
value1=#
value2=#

[nick]
value1=#
value2=#

etc...

Now the code

Code: Select all

proc proc_top10 {nick uhost handle chan text} {
   global mainchanreqs inifilereqs inifilescores
   if {$chan != $mainchanreqs} {
     return 0
   } 
   set choice [lindex $text 0]
   if {[string match -nocase "reqs" $text]} {
   set v 0
   set hscore(0) 0
   set hiscore(0) 0
   foreach {name} [parseIni $inifilescores] {
   incr v 
   set hscore($v) value1
   set hiscore($v) value2
   if {($hscore($v) == "\;") && ($hiscore($v) == "\;")} {
    set hscore($v) 0
    set hiscore($v) 0
   }
   }
   set first 0
   set second 0
   set third 0
   set fourth 0
   set fifth 0
   set sixth 0
   set seventh 0
   set eight 0
   set ninth 0
   set tenth 0
   for { set k 0 } {$k < $v} {incr k} {
    if {$hscore($k) > $hscore($first)} {
	set tenth $ninth
	set ninth $eight
	set eight $seventh
	set seventh $sixth
       set sixth $fifth
       set fifth $fourth
       set fourth $third
       set third $second
       set second $first
       set first $k
       continue
       }
    if {$hscore($k) > $hscore($second)} {
        set tenth $ninth
        set ninth $eight
        set eight $seventh
        set seventh $sixth
	set sixth $fifth
       set fifth $fourth
       set fourth $third
       set third $second
       set second $k
       continue
       }
    if {$hscore($k) > $hscore($third)} {
        set tenth $ninth
        set ninth $eight
        set eight $seventh
        set seventh $sixth
        set sixth $fifth
       set fifth $fourth
       set fourth $third
       set third $k
       continue
       }
    if {$hscore($k) > $hscore($fourth)} {
        set tenth $ninth
        set ninth $eight
        set eight $seventh
        set seventh $sixth
        set sixth $fifth
       set fifth $fourth
       set fourth $k
       continue
       }
    if {$hscore($k) > $hscore($fifth)} {
        set tenth $ninth
        set ninth $eight
        set eight $seventh
        set seventh $sixth
        set sixth $fifth
       set fifth $k
       continue
       }
    if {$hscore($k) > $hscore($sixth)} {
        set tenth $ninth
        set ninth $eight  
        set eight $seventh
        set seventh $sixth
        set sixth $k
       continue
       }
    if {$hscore($k) > $hscore($seventh)} {
        set tenth $ninth
        set ninth $eight  
        set eight $seventh
        set seventh $k
       continue
       }
    if {$hscore($k) > $hscore($eight)} {
        set tenth $ninth
        set ninth $eight  
        set eight $k
       continue
       }
    if {$hscore($k) > $hscore($ninth)} {
	set tenth $ninth
        set ninth $k
       continue
       }
    if {$hscore($k) > $hscore($tenth)} {
       set tenth $k
       continue
       }
    }
    if {($hscore($first) == "0") && ($hiscore($first) == "0")} {
      putserv "PRIVMSG $mainchanreqs :\0032No one has requested anything yet.\003"
      return 0
    }
    if {($hscore($second) == "0") && ($hiscore($second) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 1 Requester\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003\002" 
      return 0
    }
    if {($hscore($third) == "0") && ($hiscore($third) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 2 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003\002" 
      return 0
    }
    if {($hscore($fourth) == "0") && ($hiscore($fourth) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 3 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003\002" 
      return 0
    }
    if {($hscore($fifth) == "0") && ($hiscore($fifth) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 4 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003\002" 
      return 0
    }
    if {($hscore($sixth) == "0") && ($hiscore($sixth) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 5 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003  5\)\0034 $hiscore($fifth)\003 \0036 $hscore($fifth)\003\002" 
      return 0
    }
    if {($hscore($seventh) == "0") && ($hiscore($seventh) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 6 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003  5\)\0034 $hiscore($fifth)\003 \0036 $hscore($fifth)\003  6\)\0034 $hiscore($sixth)\003 \0036 $hscore($sixth)\003\002" 
      return 0
    }
    if {($hscore($eight) == "0") && ($hiscore($eight) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 7 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003  5\)\0034 $hiscore($fifth)\003 \0036 $hscore($fifth)\003  6\)\0034 $hiscore($sixth)\003 \0036 $hscore($sixth)\003  7\)\0034 $hiscore($seventh)\003 \0036 $hscore($sixth)\003\002" 
      return 0
    }
    if {($hscore($ninth) == "0") && ($hiscore($ninth) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 8 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003  5\)\0034 $hiscore($fifth)\003 \0036 $hscore($fifth)\003  6\)\0034 $hiscore($sixth)\003 \0036 $hscore($sixth)\003  7\)\0034 $hiscore($seventh)\003 \0036 $hscore($sixth)\003  8\)\0034 $hiscore($eight)\003 \0036 $hscore($eight)\003\002" 
      return 0
    }
    if {($hscore($tenth) == "0") && ($hiscore($tenth) == "0")} {
      puthelp "PRIVMSG $mainchanreqs :\0032Top 9 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003  5\)\0034 $hiscore($fifth)\003 \0036 $hscore($fifth)\003  6\)\0034 $hiscore($sixth)\003 \0036 $hscore($sixth)\003  7\)\0034 $hiscore($seventh)\003 \0036 $hscore($sixth)\003  8\)\0034 $hiscore($eight)\003 \0036 $hscore($eight)\003  9\)\0034 $hiscore($ninth)\003 \0036 $hscore($ninth)\003\002" 
      return 0
    } 
    puthelp "PRIVMSG $mainchanreqs :\0032Top 10 Requesters\:\003 1\)\0034 $hiscore($first)\003 \0036 $hscore($first)\003  2\)\0034 $hiscore($second)\003 \0036 $hscore($second)\003  3)\0034 $hiscore($third)\003 \0036 $hscore($third)\003  4\)\0034 $hiscore($fourth)\003 \0036 $hscore($fourth)\003  5\)\0034 $hiscore($fifth)\003 \0036 $hscore($fifth)\003  6\)\0034 $hiscore($sixth)\003 \0036 $hscore($sixth)\003  7\)\0034 $hiscore($seventh)\003 \0036 $hscore($sixth)\003  8\)\0034 $hiscore($eight)\003 \0036 $hscore($eight)\003  9\)\0034 $hiscore($ninth)\003 \0036 $hscore($ninth)\003  10\)\0034 $hiscore($tenth)\003 \0036 $hscore($tenth)\003\002" 
    return 0
   }
 return 0
}
Any suggestions would help. Thanks
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Top10 Help (Custom Design)

Post by user »

I'd make a list of lists that contain name and score..like this:

Code: Select all

# this list will of course be generated by the code reading your .ini:
set unsorted {{Name1 1000} {Name2 1001} {Name3 999}}

if {[llength $unsorted]==0} {
	set result "\0032No one has requested anything yet.\003"
} else {
	# lsort that list using the -index option:
	set sorted [lsort -index 1 -integer -decreasing $unsorted]
	set result {}
	set i 0
	# and use a foreach loop to generate the output (using lrange to limit the number to max 10)
	foreach pair [lrange $sorted 0 9] {
		lappend result "[incr i]) \00304[join $pair " \00306"]\003"
	}
	if {[llength $result]==1} {
		set result "\0032Top Requester:\003 [join $result]"
	} {
		set result "\0032Top [llength $result] Requesters:\003 [join $result]"
	}
}
puthelp "PRIVMSG #chan :$result"
Have you ever read "The Manual"?
D
Darkj
Halfop
Posts: 86
Joined: Sun Jul 06, 2003 9:58 pm

Post by Darkj »

Awesome user, that put me on a great step to the right direction. Thank you muchly.
Locked