I'm new to TCL, but I decided to challenge myself to make a script for a game that I love watching - Deal Or No Deal
The problem appears when choosing a case from the crowd, nothing happens.
Code: Select all
# Deal Or No Deal script by Andrew #
# Some settings for you to configure
# The binding to start Deal Or No Deal
set dondtrigger "!dnd"
# The binding to stop Deal Or No Deal
set dondstoptrigger "!stdnd"
# Flags required to stop Deal Or No Deal
# For anybody, set it to "-"
set dondstopflags "o"
# The binding to choose your case
set dondchoosecasetrigger "!choose"
# The binding to choose a case from the crowd
set dondcasetrigger "!case"
# The binding to make a deal
set donddealtrigger "!deal"
# The binding for no deal
set dondnodealtrigger "!nodeal"
# The message that must be sent to the bot for the person to be a banker
set dondbankermsg "banker"
# The prefix of the message that the banker must send to set an offer
set dondofferprefix "offer"
# Bindings according to what you have set
bind pub - $dondtrigger dond:init
bind pub $dondstopflags $dondstoptrigger dond:stop
bind pub - $dondchoosecasetrigger dond:choosecase
bind pub - $dondcasetrigger dond:choosecrowdcase
bind pub - $donddealtrigger dond:deal
bind pub - $dondnodealtrigger dond:nodeal
bind msg - $dondbankermsg dond:banker
bind msg - $dondofferprefix dond:banker:offer
# Global variables (Leave these alone)
set dondplaying "false"
set dondplayer ""
set dondbanker ""
set dondround ""
set dondoffer ""
set dondcase ""
set dondchan ""
set casestoopen ""
set casesopened ""
set dondplayercase ""
set dondplayerhascase "false"
# Global arrays (leave these alone as well)
set array("casesopened") ""
set array("amountsopened") ""
# Deal Or No Deal logo
set dondlogo "\002\0038,1Deal Or No Deal\003\002"
# Amount list
set dondamounts {
"\002\00301,03.01\003\002"
"\002\00301,031\003\002"
"\002\00301,035\003\002"
"\002\00301,0310\003\002"
"\002\00301,0325\003\002"
"\002\00301,0350\003\002"
"\002\00301,0375\003\002"
"\002\00301,03100\003\002"
"\002\00301,03200\003\002"
"\002\00301,03300\003\002"
"\002\00301,03400\003\002"
"\002\00301,03500\003\002"
"\002\00301,03750\003\002"
"\002\00301,031,000\003\002"
"\002\00301,035,000\003\002"
"\002\00301,0310,000\003\002"
"\002\00301,0325,000\003\002"
"\002\00301,0850,000\003\002"
"\002\00301,0875,000\003\002"
"\002\00301,08100,000\003\002"
"\002\00301,08200,000\003\002"
"\002\00301,08300,000\003\002"
"\002\00301,08400,000\003\002"
"\002\00301,04500,000\003\002"
"\002\00301,04750,000\003\002"
"\002\00301,041,000,000\003\002"
}
# Initiate Deal Or No Deal
proc dond:init {nick host hand chan arg} {
global dondplaying dondlogo dondplayer dondchan dondbankermsg botnick
if {$dondplaying == "false" && $dondchan == "" && $dondplayer == ""} {
set dondplaying "true"
set dondplayer $nick
set dondchan $chan
putserv "PRIVMSG $dondchan :$dondlogo has been started by $dondplayer!"
putserv "PRIVMSG $dondchan :Now a banker is needed, please \002/msg $botnick $dondbankermsg\002 if you would like to be the banker."
}
}
# We need a banker!
proc dond:banker {nick host hand arg} {
global dondplaying dondlogo dondplayer dondchan dondbanker dondchoosecasetrigger
set dondbanker $nick
putserv "PRIVMSG $dondchan :The banker for $dondlogo is going to be $dondbanker!"
putserv "NOTICE $dondbanker :Your objective is to make $dondplayer walk away with as little as possible. Be sure to make fair offers, or they will keep rejecting your offers."
putserv "PRIVMSG $dondchan :\002$dondplayer:\002 Please choose the case you want to hold by typing \002$dondchoosecasetrigger <case>\002"
}
proc dond:choosecase {nick host hand chan arg} {
global dondplayercase dondplayer dondplaying dondchan dondlogo dondplayerhascase dondcasetrigger
if {$chan != $dondchan} { putserv "NOTICE $nick :Sorry, $dondlogo is already being played on $dondchan" ; return 0 }
if {$nick != $dondplayer} { putserv "NOTICE $nick :You can't choose a case because you are not the current $dondlogo player." ; return 0 }
if {$dondplayerhascase == "true"} { putserv "NOTICE $dondplayer :You are already holding a case: \002$dondplayercase\002." ; return 0 }
# If nothing was said we'll be nice and give them a case at random
if {$arg == ""} {
set dondplayercase [expr {[rand 26] + 1}]
set dondplayerhascase "true"
putserv "PRIVMSG $dondchan :The case chosen for $dondplayer is $dondplayercase."
putserv "PRIVMSG $dondchan :Please start opening cases with \002$dondcasetrigger <case>\002"
# Give them the case they said they want
} else {
set dondplayercase [lindex $arg 0]
set dondplayerhascase "true"
# Make sure that they didn't go over 26 or below 1
if {$dondplayercase > 26 || $dondplayercase <= 0} { putserv "NOTICE $dondplayer :Case number must be no greater than 26 and above 0." ; return 0 }
putserv "PRIVMSG $dondchan :$dondplayer's case is going to be $dondplayercase"
putserv "PRIVMSG $dondchan :Please start opening cases with \002$dondcasetrigger <case>\002"
}
}
proc dond:choosecrowdcase {nick host hand chan arg} {
global dondchan dondplayer casesopened amountsopened casesopened casestoopen dondround dondamounts
if {$chan != $dondchan} { putserv "NOTICE $nick :Sorry, $dondlogo is already being played on $dondchan" ; return 0 }
if {$nick != $dondplayer} { putserv "NOTICE $nick :You can't choose a case because you are not the current $dondlogo player." ; return 0 }
set casetoopen [lindex $arg 0]
if {$casetoopen >26 || $casetoopen <= 0} { putserv "NOTICE $nick :$casetoopen is out of range." ; return 0 }
# Round check
# 6 cases to open in round 1
if {$dondround == 1} {
set casestoopen 6
putserv "PRIVMSG $dondchan :$dondplayer has chosen case number $casetoopen"
putserv "PRIVMSG $dondchan :Which contains..."
# Get the amount for the case you just opened
set amount [lindex $amounts [rand [llength $amounts]]]
# Check the array to make sure the amount isn't already chosen
if {$amount != $amountsopened($amount)} {
putserv "PRIVMSG $dondchan :$amount"
incr casesopened +1
}
# 5 cases to open in round 2
} elseif {$dondround == 2} {
set casestoopen 5
putserv "PRIVMSG $dondchan :$dondplayer has chosen case number $casetoopen"
putserv "PRIVMSG $dondchan :Which contains..."
# Get the amount for the case you just opened
set amount [lindex $amounts [rand [llength $amounts]]]
# Check the array to make sure the amount isn't already chosen
if {$amount != $amountsopened($amount)} {
putserv "PRIVMSG $dondchan :$amount"
incr casesopened +1
}
# 4 cases to open in round 3
} elseif {$dondround == 3} {
set casestoopen 4
putserv "PRIVMSG $dondchan :$dondplayer has chosen case number $casetoopen"
putserv "PRIVMSG $dondchan :Which contains..."
# Get the amount for the case you just opened
set amount [lindex $amounts [rand [llength $amounts]]]
# Check the array to make sure the amount isn't already chosen
if {$amount != $amountsopened($amount)} {
putserv "PRIVMSG $dondchan :$amount"
incr casesopened +1
}
# 3 cases to open in round
} elseif {$dondround == 4} {
set casestoopen 3
putserv "PRIVMSG $dondchan :$dondplayer has chosen case number $casetoopen"
putserv "PRIVMSG $dondchan :Which contains..."
# Get the amount for the case you just opened
set amount [lindex $amounts [rand [llength $amounts]]]
# Check the array to make sure the amount isn't already chosen
if {$amount != $amountsopened($amount)} {
putserv "PRIVMSG $dondchan :$amount"
incr casesopened +1
}
# 2 cases to open in round 5
} elseif {$dondround == 5} {
set casestoopen 2
putserv "PRIVMSG $dondchan :$dondplayer has chosen case number $casetoopen"
putserv "PRIVMSG $dondchan :Which contains..."
# Get the amount for the case you just opened
set amount [lindex $amounts [rand [llength $amounts]]]
# Check the array to make sure the amount isn't already chosen
if {$amount != $amountsopened($amount)} {
putserv "PRIVMSG $dondchan :$amount"
incr casesopened +1
}
# At this point, we just take it one case at a time
} elseif {$dondround >= 6} {
set casestoopen 1
putserv "PRIVMSG $dondchan :$dondplayer has chosen case number $casetoopen"
putserv "PRIVMSG $dondchan :Which contains..."
# Get the amount for the case you just opened
set amount [lindex $amounts [rand [llength $amounts]]]
# Check the array to make sure the amount isn't already chosen
if {$amount != $amountsopened($amount)} {
putserv "PRIVMSG $dondchan :$amount"
incr casesopened +1
}
if {$casesopened == $casestoopen} {
all_cases_opened
}
}
}
proc all_cases_opened {} {
global dondbanker dondchan dondplaer dondlogo dondbanker dondofferprefix botnick
if {$chan != $dondchan} { putserv "NOTICE $nick :Sorry, $dondlogo is already being played on $dondchan" ; return 0 }
if {$nick != $dondplayer} { putserv "NOTICE $nick :You aren't the current $dondlogo player." ; return 0 }
putserv "PRIVMSG $dondchan :Now it's time for an offer from the banker."
putserv "NOTICE $dondbanker :I need an offer from you. Please use \002/msg $botnick $dondofferprefix <offer> to send your offer."
}
proc dond:banker:offer {nick host hand arg} {
global dondchan dondplayer dondbanker dondoffer dondlogo
if {$nick != $dondbanker} { putserv "NOTICE $nick :You are not the current $dondlogo banker." ; return 0 }
set offer [lindex $arg 0]
putserv "PRIVMSG $dondchan :\002$dondplayer:\002 Your offer is:"
putserv "PRIVMSG $dondchan :$offer"
putserv "PRIVMSG $dondchan :\002$dondplayer\002 Deal, or no deal?"
}
proc dond:deal {nick host hand chan arg} {
global dondchan dondplayer
putserv "PRIVMSG $dondchan :\002\0030,3Deal!!!"
}
proc dond:nodeal {nick host hand chan arg} {
global dondchan dondplayer dondround dondcasetrigger
putserv "PRIVMSG $dondchan :\002\0040,4No Deal!"
putserv "PRIVMSG $dondchan :Continue opening cases with \002$dondcasetrigger <case>\002"
}
proc dond:stop {nick host hand chan arg} {
global dondplaying dondplayer dondbanker dondround dondoffer dondcase dondchan casestoopen casesopened dondplayercase dondplayerhascase dondlogo dondtrigger
if {[info exists dondplaying]} { set dondplaying "false" }
if {[info exists dondplayer]} { set dondplayer "" }
if {[info exists dondbanker]} { set dondbanker "" }
if {[info exists dondround]} { set dondround "" }
if {[info exists dondoffer]} { set dondoffer "" }
if {[info exists dondcase]} { set dondcase "" }
if {[info exists dondchan]} { set dondchan "" }
if {[info exists casestoopen]} { set casestoopen "" }
if {[info exists casesopened]} { set casesopened "" }
if {[info exists dondplayercase]} { set dondplayercase "" }
if {[info exists dondplayerhascase]} { set dondplayerhascase "false" }
putserv "PRIVMSG $chan :$dondlogo has been stopped by $nick! Type \002$dondtrigger\002 to start again."
}