ComputerTech Owner
Posts : 99 Points : 268 Reputation : 0 Join date : 2020-04-30
| Subject: Bar.tcl 2/7/2020, 23:24 | |
| Hey all so i made a bar script and a friend helped me with some things. Only thing i dont personally like about this script is the amount of procs. I dont like every drink having a separate proc, any advise on making this script better or shorter is much appreciated Very Happy - Code:
-
set barcmd "!"
namespace eval ::beer { global barcmd variable beer set pt "0"
bind pub - "${barcmd}beer" ::beer::do_the_beer bind pub - "${barcmd}pay" ::beer::do_the_pay bind pub - "${barcmd}menu" ::beer::do_the_menu bind pub - "${barcmd}wine" ::beer::do_the_wine bind pub - "${barcmd}water" ::beer::do_the_water bind pub - "${barcmd}coke" ::beer::do_the_coke bind pub - "${barcmd}coke" ::beer::do_the_orange
proc do_the_beer {nick uhost handle chan text} { variable beer global pt set guy [lindex [split $text] 0] set loaded [array names beer -exact $nick] if {$pt == 50} { putserv "privmsg $chan : $nick Your Tab is full With the amount of $pt Please pay before ordering more drink" return } incr pt +5 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with Beer\001" putserv "PRIVMSG $chan :\001ACTION Gives the Beer to $nick\001" putserv "privmsg $chan : Enjoy your Beer $nick, Your Total Bill Amount Is $pt" array unset beer $nick }
proc do_the_wine {nick uhost handle chan text} { variable beer global pt set guy [lindex [split $text] 0] set loaded [array names beer -exact $nick] if {$pt == 50} { putserv "privmsg $chan : $nick Your Tab is full With the amount of $pt Please pay before ordering more drink" return } incr pt +25 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with Wine\001" putserv "PRIVMSG $chan :\001ACTION Gives the Wine to $nick\001" putserv "privmsg $chan : Enjoy your Wine $nick, Your Total Bill Amount Is $pt" array unset beer $nick }
proc do_the_water {nick uhost handle chan text} { variable beer global pt set guy [lindex [split $text] 0] set loaded [array names beer -exact $nick] if {$pt == 50} { putserv "privmsg $chan : $nick Your Tab is full With the amount of $pt Please pay before ordering more drink" return } incr pt +2 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with Water\001" putserv "PRIVMSG $chan :\001ACTION Gives the Water to $nick\001" putserv "privmsg $chan : Enjoy your Water $nick, Your Total Bill Amount Is $pt" array unset beer $nick }
proc do_the_orange {nick uhost handle chan text} { variable beer global pt set guy [lindex [split $text] 0] set loaded [array names beer -exact $nick] if {$pt == 50} { putserv "privmsg $chan : $nick Your Tab is full With the amount of $pt Please pay before ordering more drink" return } incr pt +3 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with Orange juice\001" putserv "PRIVMSG $chan :\001ACTION Gives the Orange Juice to $nick\001" putserv "privmsg $chan : Enjoy your Orange Juice $nick, Your Total Bill Amount Is $pt" array unset beer $nick }
proc do_the_coke {nick uhost handle chan text} { variable beer global pt set guy [lindex [split $text] 0] set loaded [array names beer -exact $nick] if {$pt == 50} { putserv "privmsg $chan : $nick Your Tab is full With the amount of $pt Please pay before ordering more drink" return } incr pt +4 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with Coke\001" putserv "PRIVMSG $chan :\001ACTION Gives the Coke to $nick\001" putserv "privmsg $chan : Enjoy your Coke $nick, Your Total Bill Amount Is $pt" array unset beer $nick }
proc do_the_pay {nick uhost handle chan text} { variable beer global pt set loaded [array names beer -exact $nick] if {$loaded != ""} { putserv "privmsg $chan :$nick Your Already Payed Your Bill" return } array set beer "$nick 1" putserv "privmsg $chan :$nick Thank You For Paying Your Bill, Here's your receipt" putserv "notice $chan : ------------------- " putserv "notice $chan :|Bar receipt " putserv "notice $chan :| $ $pt " putserv "notice $chan :| $nick " putserv "notice $chan :| $chan" putserv "notice $chan : ------------------- " set pt "0" }
proc do_the_menu {nick uhost handle chan text} { global barcmd putserv "notice $nick :Welcome $nick This is our Menu" putserv "notice $nick :${barcmd}beer $ 5 , ${barcmd}water $ 2 , {barcmd}wine $ 25 , ${barcmd}coke $ 4 ${barcmd}orange $ 3" } } ;# end namespace
| |
|
ComputerTech Owner
Posts : 99 Points : 268 Reputation : 0 Join date : 2020-04-30
| Subject: Re: Bar.tcl 3/7/2020, 13:07 | |
| Alright So CrazyCat Was Super Nice to tune my script up a bit Here's it is - Code:
-
namespace eval ::beer {
variable barcmd "!" variable beer array set bills {}
array set drinks { beer 5 wine 25 water 2 coke 3 orange 4 } foreach dr [array names drinks] { bind pubm - "*$::beer::barcmd$dr*" ::beer::do_drink } bind pub - "${barcmd}pay" ::beer::do_the_pay bind pub - "${barcmd}menu" ::beer::do_the_menu
proc do_drink {nick uhost handle chan text} { set args [split $text " "] set key [stripcodes abcgru [lindex $args 0]] set key [string range $key 1 end] if {[lsearch [array names ::beer::drinks] $key] == -1} { putserv "PRIVMSG $chan :Sorry $nick, I haven't $key in the fridge" return 0 } set cost $::beer::drinks($key) if {[array names ::beer::bills -exact $nick] ne ""} { set bill $::beer::bills($nick) if {$bill >= 50} { putserv "PRIVMSG $chan : $nick Your Tab is full With the amount of \$$bill | |
|