This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

bar script help (again)

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

bar script help (again)

Post by ComputerTech »

so trying to add the option to give a beer to a user like !beer john

bot gives john a beer

this is the code I have so far :roll:

Code: Select all

#################################################################################################################################################################
# Bar.tcl 1.0.5
#################################################################################################################################################################
#ComputerTech
#Irc     irc.technet.xi.ht #ComputerTech123
#Email   ComputerTech312@Gmail.com
#GitHub  https://github.com/computertech312
#Website http://tcl3.webnode.co.uk
#################################################################################################################################################################
#START OF SETTINGS#
#Set trigger

set barcmd ""

#Set the maxium amount the tab can be

set max "100"


#END OF SETTINGS#
#################################################################################################################################################################
   
namespace eval ::beer {

   variable barcmd ";"
    variable beer
   array set bills {}

   array set drinks {
      heineken 6
      wine   25
      water   2
      coke   5
      orange   4
      vodka    10
      brandy   30
      whiskey   9
      budwiser 7
      guinness 14
      carlsberg 8
      redbull   6
      fanta     5
      tea       4
      coffee    6
   }
   
   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]

      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
         if {[lindex [split $text] 0 ]} {
       set dnick "[lindex [split $text] 0 ]"
       putserv "privmsg $chan : here ya go go $dnick some $key"
    }  else {
        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"
}   

putlog "Bar 1.0.5 Loaded"
#################################################################################################################################################################
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You can try the following:

Code: Select all

#################################################################################################################################################################
# Bar.tcl 1.0.5
#################################################################################################################################################################
#ComputerTech
#Irc     irc.technet.xi.ht #ComputerTech123
#Email   ComputerTech312@Gmail.com
#GitHub  https://github.com/computertech312
#Website http://tcl3.webnode.co.uk
#################################################################################################################################################################
#START OF SETTINGS#
#Set trigger

set barcmd ""

#Set the maxium amount the tab can be

set max "100"


#END OF SETTINGS#
#################################################################################################################################################################
   
namespace eval ::beer {

	variable barcmd ";"
    variable beer
	array set bills {}

	array set drinks {
		heineken 6
		wine   25
		water   2
		coke   5
		orange   4
		vodka    10
		brandy   30
		whiskey   9
		budwiser 7
		guinness 14
		carlsberg 8
		redbull   6
		fanta     5
		tea       4
		coffee    6
	}
   
	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 { [llength $args]==2 } {
			set vict [stripcodes abcgru [lindex $args 1]]
			if {![onchan $vict $chan]} {
				putserv "PRIVMSG $chan :$nick, you can't afford a $key to $vict, she/he is not here"
				return 0
			}
		} else {
			set vict $nick
		}
		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 $vict\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.6 loaded"
}
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Haha, Cheers CrazyCat :wink:

I'll give it a go :P

*ComputerTech Gives CrazyCat A Beer
Last edited by ComputerTech on Mon Jul 27, 2020 9:16 am, edited 1 time in total.
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Code: Select all

cd /pub/ && more beer
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Hmm, it works good, but this part

Code: Select all

 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with $key\001" 
      putserv "PRIVMSG $chan :\001ACTION Gives the $key to $vict\001" 
      putserv "PRIVMSG $chan : Enjoy your $key $nick, Your Total Bill Amount Is \$$::beer::bills($nick)" 
if i change $nick to $vict ,will that make it if i just type !beer it will say giving to me?

and for this part.

Code: Select all

  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) 
    } 
is there a way to make the receipt show each drink the user ordered on the receipt?
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

ComputerTech wrote:Hmm, it works good, but this part

Code: Select all

 putserv "PRIVMSG $chan :\001ACTION Fills up the glass with $key\001" 
      putserv "PRIVMSG $chan :\001ACTION Gives the $key to $vict\001" 
      putserv "PRIVMSG $chan : Enjoy your $key $nick, Your Total Bill Amount Is \$$::beer::bills($nick)" 
if i change $nick to $vict ,will that make it if i just type !beer it will say giving to me?
Read the beginning of the code, $vict is depending on the second part of the command:

Code: Select all

if { [llength $args]==2 } {
         set vict [stripcodes abcgru [lindex $args 1]]
         if {![onchan $vict $chan]} {
            putserv "PRIVMSG $chan :$nick, you can't afford a $key to $vict, she/he is not here"
            return 0
         }
      } else {
         set vict $nick
      } 
ComputerTech wrote:and for this part.

Code: Select all

  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) 
    } 
is there a way to make the receipt show each drink the user ordered on the receipt?
Wasn't in the previous question, and it's more elaborate than a simple bill counter.
I can do it, but managing bills and payments needs more things than "I want a bar script for fun"
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Yeah, but when i did

Code: Select all

!heineken john
it responded with

Code: Select all

*Fills up the glass with heineken
*Gives the heineken to j9hn
*Enjoy your heineken ComputerTech, Your Total Bill Amount Is $6
 
so i guess this >> *Enjoy your heineken ComputerTech, Your Total Bill Amount Is $6
is the problem, perhaps if it checked if i specified a person to say a different sentence

8) perhaps like this

Code: Select all

if {[llength [split $text] 0]}
putserv "privmsg $chan :here ya go john"
} else {
putserv "privmsg $chan :here ya go computertech"
something like that perhaps?
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Sorry, I didn't read totaly the last putserv which is used to speak to the "victim" and the afforder.

So, you have 2 choices:
- use separate lines to say "enjoy" and to give the total amount of the bill
- compare $vict and $nick and then choose an appropriate sentence.

First way:

Code: Select all

putserv "PRIVMSG $chan :: Enjoy your $key $vict, it's a gift from $nick"
putserv "PRIVMSG $chan: $nick, your Total Bill Amount is \$$::beer::bills($nick)"
Second way:

Code: Select all

if {$vict eq $nick} {
   putserv "PRIVMSG $chan :Enjoy your $key $nick, Your Total Bill Amount Is \$$::beer::bills($nick)"
} else {
   putserv "PRIVMSG $chan :Enjoy your $key $vict, the Total Bill Amount for $nick is \$$::beer::bills($nick)"
}
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Second Choice looks good :D

Thanks CrazyCat, i'll go add it right away :wink:

Cheers :P
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Cool, worked a treat CrazyCat :D

i was thinking of anothr feature, a tip service, could we work with this perhaps?


!tip $amount

and this adds to the receipt as a seperate line or array

but some how make a total amount of both the drinks and the tip

would this be possibly easy? or quite difficult to do?
All help appreciated as always :D
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Hmm, little problem with the bar script, if a user changes nick it clears their bar tab, is there a way to associate the variable with the user's hostmask?

Thanks in advanced :P
ComputerTech
Post Reply