Lottery Game

Release your script here.
State:
- Author
- What it does
- Perhaps a little guide.
- Also, if the snippet is of any use to the community, it has a chance of getting posted on the main page, so don't hesitate to submit/ask!

Lottery Game

Postby GaRfWeN » Wed Dec 17, 2008 8:59 am

Hello,

I had a channel running lottery, well its over.
Here is the script:
Hope you enjoy :P

Code: Select all
# Author: tomekk
# Edited by GaRfWeN
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
#
#
#Simple lottery script
#Commands:
#!reg !regs
#!remove
#!start
#!stop
#well just read the script, you'll understand :p

bind pub M !start start_proc
bind pub M !prize prize_proc
bind pub - !reg reg_proc
bind pub - !regs regs_proc
bind pub M !setwinner setwinner
bind pub M !stop stop
bind pub M !setprize setprize
bind pub M !max maxusers
bind pub - "-m" menosm
bind pub - "+m" maism
bind pub - .not pub:server
bind pub - .notice pub:server
bind pub - !remove remove
bind pub - !del del
bind pub - !last last
bind pub - !lotterys number

set lotterynumber "1"


set corinicial "10,15\[6«5" 
set corfinal "6»10\]" 


set game_status 0
set game_prize ""
set reg_status 0
set max_players 0
set player_list [list]
set the_winner_is ""
set lotterychan "#Your Lottery Chan"
set mainchan "$lotterychan"
set lastwinner "None"
set lastlottery ""
set lastadmin ""
set lastprize ""
set onjoinchan "$mainchan"
set lotteryadmin ""
set lotterychan ""


proc number {nick uhost hand chan rest} {
        global lotterynumber
      putquick "privmsg $chan :$::corinicial Total Lotteries: $lotterynumber $::corfinal"

}

bind part - * holm-join_greet
proc holm-join_greet {nick uhost hand channel args} {
global onjoinchan greet reg_status player_list max_players game_status game_prize the_winner_is lotteryadmin mainchan  lotteryadmin lastwinner lotterynumber
      if {$game_status == 1} {
        if {(([lsearch -exact [string tolower $onjoinchan] [string tolower $channel]] != -1) || ($onjoinchan == "*"))} {
if { $nick == $lotteryadmin } {
      putquick "PRIVMSG $mainchan :$::corinicial $nick (admin) parted, Lottery canceled  $::corfinal"
      utimer 10 [list putquick "TOPIC $channel :$::corinicial Welcome² $channel $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $lastwinner $::corfinal"]
      utimer 10 [list putquick "TOPIC $mainchan :$::corinicial Welcome² $channel $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $lastwinner $::corfinal"]
            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
            set the_winner_is ""
      } else {
      set searchnode "$nick;$uhost"
   set pos [lsearch $player_list $searchnode]
      set player_list [lreplace $player_list $pos 0]
      }
   }
}
}

proc last {nick uhost hand chan rest} {
        global lastadmin lastlottery lastwinner lastprize
              if {$lastlottery == ""} {
      putquick "privmsg $chan :$::corinicial No stats yet, sorry. $::corfinal"
              } else {
      putquick "privmsg $chan :$::corinicial Last Lottery was on $lastlottery, by $lastadmin $::corfinal$::corinicial Winner was: $lastwinner , and his prize was: $lastprize $::corfinal"
}
}


proc pub:server { nick userhost handle channel text } {
if {[isop $nick $channel]} {
        global botnick
        putquick "mode $::mainchan -N"
        putquick "notice $::mainchan :$::corinicial $text ($nick) $::corfinal"
        putquick "notice $::mainchan :$::corinicial $text ($nick) $::corfinal"
        putquick "notice $::mainchan :$::corinicial $text ($nick) $::corfinal"
        putquick "mode $::mainchan +N"
}
}

proc setwinner {nick uhost hand chan rest} {
   global the_winner_is game_status
      if {$game_status == 1} {
if {[isop $nick $chan]} {
set the_winner_is $rest
      putquick "notice $nick :$::corinicial Winner added ($rest) $::corfinal"
}
}
}

proc remove {nick uhost hand chan rest} {
   global reg_status player_list max_players game_status game_prize the_winner_is
      if {$game_status == 1} {
        set searchnode "$nick;$uhost"
   set pos [lsearch $player_list $searchnode]
   if { $pos > -1 } {
            set player_list [lreplace $player_list $pos 0]
      putserv "NOTICE $nick :$::corinicial Removed! $::corfinal"
   } else {
      putserv "NOTICE $nick :$::corinicial You are not registered! $::corfinal"
   }
}
}
proc setprize {nick uhost hand chan rest} {
   global game_prize max_players lastadmin game_status
      if {$game_status == 1} {
      putquick "privmsg $chan :$::corinicial Prize changed to: $rest $::corfinal"
set game_prize $rest
    utimer 5 [list putquick "TOPIC $chan :$::corinicial Lottery started $::corfinal$::corinicial Max users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal"]
}
}

proc stop {nick uhost hand chan rest} {
   global reg_status player_list max_players game_status game_prize the_winner_is lotterynumber lastwinner
      if {$game_status == 1} {
      putquick "PRIVMSG $chan :$::corinicial The game has been stopped by $nick $::corfinal"
            putquick "TOPIC $chan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $lastwinner $::corfinal"
            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
set the_winner_is ""
set lotterychan ""
}
}


proc maxusers {nick uhost hand chan rest} {
   global reg_status player_list max_players game_status game_prize the_winner_is lastadmin lastlottery lastwinner lastprize lotterychan lotterynumber mainchan
      if {$game_status == 1} {
      putquick "PRIVMSG $chan :$::corinicial Max-users is now $rest $::corfinal"
            putquick "TOPIC $chan :$::corinicial Lottery started $::corfinal$::corinicial Max users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal"
            set max_players $rest
         if {[llength $player_list] == $max_players} {
              if {$the_winner_is == ""} {
            set lottery_winner [expr {int(rand() * $max_players)}]
            set the_winner_is [lindex [split [lindex $player_list $lottery_winner] ";"] 0]
     putquick "MODE $chan +v $the_winner_is"
        putquick "mode $chan +m"
set time "[clock format [clock seconds] -format {%H:%M:%S %x}]"
set lastlottery $time
set lastwinner $the_winner_is
set lastprize $game_prize
set lotterynumber [expr $lotterynumber +1]
            putquick "PRIVMSG $chan :$::corinicial $the_winner_is you have just won the lottery! your prize is $game_prize $::corfinal"
      putquick "TOPIC $chan :$::corinicial Lottery had finished. $::corfinal$::corinicial Number of Users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal$::corinicial Winner: $the_winner_is $::corfinal$::corinicial Brought to you by:  #aBNC - #iBots $::corfinal"
            putquick "PRIVMSG $the_winner_is :$::corinicial $the_winner_is congrats ! your prize is: $game_prize $::corfinal$::corinicial Please contact the Lottery admin.$::corfinal"
          utimer 15 [list putquick "TOPIC $chan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
          utimer 15 [list putquick "TOPIC $mainchan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
          utimer 16 [list putquick "mode $chan -m"]
            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
set the_winner_is ""
set lotterychan ""
                    } else {
        putquick "mode $chan +m"
set time "[clock format [clock seconds] -format {%H:%M:%S %x}]"
set lastlottery $time
set lastwinner $the_winner_is
set lastprize $game_prize
set lotterynumber [expr $lotterynumber +1]
     putquick "MODE $chan +v $the_winner_is"
            putquick "PRIVMSG $chan :$::corinicial $the_winner_is you have just won the lottery! your prize is $game_prize $::corfinal"
      putquick "TOPIC $chan :$::corinicial Lottery had finished. $::corfinal$::corinicial Number of Users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal$::corinicial Winner: $the_winner_is $::corfinal$::corinicial Brought to you by:  #aBNC - #iBots $::corfinal"
            putquick "PRIVMSG $the_winner_is :$::corinicial $the_winner_is congrats ! your prize is: $game_prize $::corfinal$::corinicial Please contact the Lottery admin.$::corfinal"
          utimer 15 [list putquick "TOPIC $chan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
          utimer 15 [list putquick "TOPIC $mainchan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
          utimer 16 [list putquick "mode $chan -m"]
            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
set the_winner_is ""
set lotterychan ""
            }
         }
   }
}


proc start_proc { nick uhost hand chan arg } {
   global max_players game_status

   if {$game_status == 0} {
      set players_num [lindex [split $arg] 0]

      if {[regexp {^([0-9]+)$} $players_num]} {
         set max_players $players_num
         set game_status 1
            putquick "PRIVMSG $chan :$::corinicial Trying to start a lottery with $max_players users (please type !prize <prize> to start.) $::corfinal"
      }
   }
}



proc prize_proc { nick uhost hand chan arg } {
   global game_status reg_status max_players game_prize lastadmin lotteryadmin lotterychan

   if {$game_prize == ""} {
      if {$game_status == 1} {
         if {$arg != ""} {
            set game_prize $arg
            set reg_status 1
        putquick "mode $chan +m"
set lastadmin $nick
set lotteryadmin $nick
set lotterychan $chan
      putquick "TOPIC $chan :$::corinicial Lottery starting! $::corfinal$::corinicial Be ready !!! $::corfinal$::corinicial Lottery admin: $nick $::corfinal"
            putquick "PRIVMSG $chan :$::corinicial Removing Moderated in 10 seconds $::corfinal"
    utimer 10 [list putquick "mode $chan -m"]
    utimer 9 [list putquick "TOPIC $chan :$::corinicial Lottery started $::corfinal$::corinicial Max users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal"]
         }
      }
   }
}


proc reg_proc { nick uhost hand chan arg } {
   global reg_status player_list max_players game_status game_prize the_winner_is lastadmin lastlottery lastwinner lastprize lotterychan lotterynumber mainchan
   if {$reg_status == 0} {
            putquick "PRIVMSG $chan :$::corinicial There is no lottery game started ! $::corfinal"
         } else {
      set player_exists 0
      foreach new_player $player_list {
   set gimme_host [lindex [split $new_player ";"] 1]
   set current_in [llength $player_list]
       if {$gimme_host == $uhost} {
            set player_exists 1
            putquick "NOTICE $nick :$::corinicial You can only add one time with that adress $::corfinal"
            break
    }
  }
      if {$player_exists == 0} {
         lappend player_list "$nick;$uhost"

         if {[llength $player_list] == $max_players} {
              if {$the_winner_is == ""} {
            set lottery_winner [expr {int(rand() * $max_players)}]
            set the_winner_is [lindex [split [lindex $player_list $lottery_winner] ";"] 0]
     putquick "MODE $chan +v $the_winner_is"
        putquick "mode $chan +m"
set time "[clock format [clock seconds] -format {%H:%M:%S %x}]"
set lastlottery $time
set lastwinner $the_winner_is
set lastprize $game_prize
set lotterynumber [expr $lotterynumber +1]
            putquick "PRIVMSG $chan :$::corinicial $the_winner_is you have just won the lottery! your prize is $game_prize $::corfinal"
      putquick "TOPIC $chan :$::corinicial Lottery had finished. $::corfinal$::corinicial Number of Users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal$::corinicial Winner: $the_winner_is $::corfinal$::corinicial Brought to you by:  #aBNC - #iBots $::corfinal"
          utimer 15 [list putquick "TOPIC $chan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
          utimer 15 [list putquick "TOPIC $mainchan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
            putquick "PRIVMSG $the_winner_is :$::corinicial $the_winner_is congrats ! your prize is: $game_prize $::corfinal$::corinicial Please contact the Lottery admin.$::corfinal"
                     utimer 16 [list putquick "mode $chan -m"]
            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
            set the_winner_is ""
set lotterychan ""
                    } else {
     putquick "MODE $chan +v $the_winner_is"
        putquick "mode $chan +m"
set time "[clock format [clock seconds] -format {%H:%M:%S %x}]"
set lastlottery $time
set lastwinner $the_winner_is
set lastprize $game_prize
set lotterynumber [expr $lotterynumber +1]
            putquick "PRIVMSG $chan :$::corinicial $the_winner_is you have just won the lottery! your prize is $game_prize $::corfinal"
      putquick "TOPIC $chan :$::corinicial Lottery had finished. $::corfinal$::corinicial Number of Users: $max_players $::corfinal$::corinicial Prize: $game_prize $::corfinal$::corinicial Winner: $the_winner_is $::corfinal$::corinicial Brought to you by:  #aBNC - #iBots $::corfinal"
          utimer 15 [list putquick "TOPIC $chan :$::corinicial Welcome² $chan $::corfinal$::corinicial Lotteries: $lotterynumber $::corfinal$::corinicial Last winner: $the_winner_is $::corfinal"]
            putquick "PRIVMSG $the_winner_is :$::corinicial $the_winner_is congrats ! your prize is: $game_prize $::corfinal$::corinicial Please contact the Lottery admin.$::corfinal"
          utimer 16 [list putquick "mode $chan -m"]
            set game_status 0
            set game_prize ""
            set reg_status 0
            set max_players 0
            set player_list [list]
set the_winner_is ""
set lotterychan ""
            }
         }
      }
   }
}

proc regs_proc { nick uhost hand chan arg } {
   global reg_status max_players game_prize player_list

   set current_in [llength $player_list]

   set rdy_player_list [list]

   foreach lt_player $player_list {
      if {$lt_player != ""} {
         set need_only_nick [lindex [split $lt_player ";"] 0]
         lappend rdy_player_list $need_only_nick
      }
   }

   if {$rdy_player_list == ""} {
      set rdy_player_list "-"
   } {
      set rdy_player_list [join $rdy_player_list ", "]
   }

   if {$reg_status == 1} {
      putquick "PRIVMSG $chan :$::corinicial Total regs: $current_in/$max_players: $rdy_player_list $::corfinal$::corinicial Prize: $game_prize $::corfinal"
   }
}


proc menosm {nick host hand chan text} {
if {[isop $nick $chan]} {
        putquick "mode $chan -m"
}
}

proc maism {nick host hand chan text} {
if {[isop $nick $chan]} {
        putquick "mode $chan +m"
}
}

putlog "lottery.tcl by tomekk, edited by GaRfWeN loaded"
GaRfWeN
 

Return to TCL Scripting Release

Who is online

Users browsing this forum: No registered users and 0 guests