Formatting of code : You can (and must) use [ tcl ] an [ /tcl ] tags (without spaces in tags) to format your TCL codes and have syntax coloration x


[Solved] 1-20 randoms roulette
#1
this will roll random roullete with player name and the results will be: 


example: 
i have 20 users to be added in random roullete .


<user> !roulette add nick1 nick2 nick3 nick4 nick5 up to nick20
<bot>Added 20 nicks for the random roulette.
***This is based on how many nick you want to add.

<user>!roulette list
<bot>Roulette's nick: Nick1, Nick2, Nick3, Nick4, Nick5, Nick6, Nick7, Nick8, Nick9, Nick10 and so on Nick20
***This is based on how many nick you want to add.


*** Now, lets start the roulette nicks


<user>!roulette
<bot>Mixing Random Roulette for Nicks
<bot>Result: Nick5 vs Nick10 

***Nick5, Nick10  (will be removed to the next roullete)
*** and then again...

<user>!roulette
<bot>Mixing Random Roulette for Nicks
<bot>Result: Nick1 vs Nick8 

***Nick1, Nick8 (will be removed to the next roullete)


<user>!roulette

<bot>Mixing Random Roulette for Nicks
<bot>Result: Nick4 vs Nick6 


and so on ...


until it finished all the nicks to be paired..
  Reply
#2
Here is a small script:
tcl
bind pub - "!roulette" roul.controler
 
proc roul.controler { nick uhost handle chan text} {
	set args [split $text]
	switch -exact [lindex $args 0] {
		"add" { roul.add $chan [lrange $args 1 end] }
		"list" { roul.list $chan }
		default { roul.run $chan }
	}
}
 
proc roul.add {chan users} {
	if {[info exists ::roul($chan)] && [llength $::roul($chan)]>0} {
		putserv "PRIVMSG $chan :roulette is already running"
		return
	}
	set ::roul($chan) {}
	set abs {}
	foreach user $users {
		putlog "test $user"
		if {[onchan $user $chan]} {
			putlog "append $user"
			lappend ::roul($chan) $user
		} else {
			putlog "refuse $user"
			lappend abs $user
		}
	}
	if {[llength $::roul($chan)]<2} {
		putserv "PRIVMSG $chan :Not enough real player"
		unset ::roul($chan)
		return
	}
	if {[expr {[llength $::roul($chan)] % 2}] != 0} {
		putserv "PRIVMSG $chan :odd number of players, aborting"
		unset ::roul($chan)
		return
	}
	if {[llength $abs]>0} {
		putserv "PRIVMSG $chan :Not kept: [join $abs ", "]"
	}
	roul.list $chan
}
 
proc roul.list {chan} {
	if {![info exists ::roul($chan)] || [llength $::roul($chan)]==0} {
		putserv "PRIVMSG $chan :roulette is empty"
		return
	}
	putserv "PRIVMSG $chan :Roulette's nick: [join $::roul($chan) ", "]"
}
 
proc roul.run {chan} {
	if {![info exists ::roul($chan)] || [llength $::roul($chan)]==0} {
		putserv "PRIVMSG $chan :Roulette is closed"
		return
	}
	putserv "PRIVMSG $chan :Mixing random roulette for nicks"
	set ind [rand [llength $::roul($chan)]]
	set vict1 [lindex $::roul($chan) $ind]
	set ::roul($chan) [lreplace $::roul($chan) $ind $ind]
	set ind [rand [llength $::roul($chan)]]
	set vict2 [lindex $::roul($chan) $ind]
	set ::roul($chan) [lreplace $::roul($chan) $ind $ind]
	putserv "PRIVMSG $chan :$vict1 vs $vict2"
	if {[llength $::roul($chan)]==0} {
		putserv "PRIVMSG $chan :Roulette is ended"
	}
}


irc.zeolia.net - Offrez-moi un café
Merci de ne pas demander d'aide en MP
  Reply
#3
Wow, thank you CrazyCat a lot... it works flawlessly..  (this post is SOLVED) .. thanks a lot..
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)