| View previous topic :: View next topic |
| Author |
Message |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Thu Jul 02, 2020 6:21 pm Post subject: Bar.tcl 1.0 |
|
|
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
| 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 |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Fri Jul 03, 2020 1:58 am Post subject: |
|
|
Yes, it could be reduced to only one proc for all the drinks. I'll try to do something
| 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 Please pay before ordering more drink"
return 0
}
} else {
set ::beer::bills($nick) 0
}
incr ::beer::bills($nick) $cost
putserv "PRIVMSG $chan :\001ACTION Fills up the glass with $key\001"
putserv "PRIVMSG $chan :\001ACTION Gives the $key to $nick\001"
putserv "PRIVMSG $chan : Enjoy your $key $nick, Your Total Bill Amount Is \$$::beer::bills($nick)"
}
proc do_the_pay {nick uhost handle chan text} {
set loaded [array names ::beer::bills -exact $nick]
if {$loaded eq ""} {
putserv "PRIVMSG $chan :$nick Your Already Payed Your Bill"
return
}
putserv "PRIVMSG $chan :$nick Thank You For Paying Your Bill, Here's your receipt"
putserv "NOTICE $nick : ------------------- "
putserv "NOTICE $nick :|Bar receipt "
putserv "NOTICE $nick :| \$$::beer::bills($nick) "
putserv "NOTICE $nick :| $nick "
putserv "NOTICE $nick :| $chan"
putserv "NOTICE $nick : ------------------- "
unset ::beer::bills($nick)
}
proc do_the_menu {nick uhost handle chan text} {
putserv "NOTICE $nick :Welcome $nick This is our Menu"
foreach {drink cost} [array get ::beer::drinks] {
putserv "NOTICE $nick :$::beer::barcmd$drink : \$$cost"
}
}
putlog "Barman 1.0.1 loaded"
} |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Fri Jul 03, 2020 7:59 am Post subject: |
|
|
Coooool, That Look's WAY better
Cheers CrazyCat
Will try it rignt away  _________________ ComputerTech |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Fri Jul 03, 2020 8:29 am Post subject: |
|
|
Absolute Perfection CrazyCat
Thank you so much  _________________ ComputerTech |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|