doc_gonzo

blackjack eggdrop

Jan 27th, 2021
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 16.95 KB | None | 0 0
  1. # # Konfiguration:
  2. #
  3. # Spiel trigger einstellen. Standard w?re ?blackjack
  4. set ::blackjack(trigger) "!"
  5.  
  6. # Spielsperre einstellen. 300 = 5 Minuten Pause zwischen jedem Spiel.
  7. set ::blackjack(flood) "300"
  8.  
  9. #
  10. # # ?NDERE AB HIER NICHTS MEHR, AU?ER DU BIST DIR SICHER WAS DU MACHST!
  11.  
  12. set bj(author)      "funny"
  13. set bj(web)         "https://funxd.site"
  14. set bj(name)        "Blackjack spiel"
  15. set bj(version)     "v1.0"
  16.  
  17. setudef     flag    blackjack
  18. setudef     str     blackjackc
  19.  
  20. bind pub    *   $::blackjack(trigger)blackjack  game:blackjack
  21. bind pub    *   $::blackjack(trigger)join       blackjack:join
  22. bind pub    *   $::blackjack(trigger)karte      blackjack:karte
  23. bind pub    *   $::blackjack(trigger)genug      blackjack:genug
  24. bind pub    n   $::blackjack(trigger)stop       blackjack:stop
  25.  
  26. # sendmsg proc by ircscript.de - R.I.P. #ircscript
  27. proc sendmsg {target command message} {
  28.     if {![string match "#*" $target]} {
  29.         putquick "notice $target :\002? $command ? ?\002 $message \002?\002"
  30.     } else {
  31.         if {[string match "*c*" [getchanmode $target]]} {
  32.             putquick "privmsg $target :? $command ? ? $message ?"
  33.         } else {
  34.             putquick "privmsg $target :\002? $command ? ?\002 $message \002?\002"
  35.         }
  36.     }
  37. }
  38.  
  39. # string2pattern proc by CyBex - tclhelp.net
  40. proc str2pat {string} {
  41.     return [string map [list \\ \\\\ \[ \\\[ \] \\\] ] $string]
  42. }
  43.  
  44. proc game:blackjack {nick host hand chan arg} {
  45.     switch -exact -- [string tolower [lindex [split $arg] 0]] {
  46.         "on" {
  47.             if {![matchattr $hand n|n $chan]} {
  48.                 return 0
  49.             }
  50.             if {[channel get $chan "blackjack"]} {
  51.                 putserv "notice $nick :Blackjack ist schon in $chan eingeschaltet."
  52.                 return 0
  53.             } elseif {![channel get $chan "blackjack"]} {
  54.                 channel set $chan +blackjack
  55.                 putserv "notice $nick :Blackjack wurde erfolgreich in $chan eingeschaltet."
  56.             }
  57.         }
  58.         "off" {
  59.             if {![matchattr $hand n|n $chan]} {
  60.                 return 0
  61.             }
  62.             if {![channel get $chan "blackjack"]} {
  63.                 putserv "notice $nick :Blackjack ist schon in $chan ausgeschaltet."
  64.                 return 0
  65.             } elseif {[channel get $chan "blackjack"]} {
  66.                 channel set $chan -blackjack
  67.                 putserv "notice $nick :Blackjack wurde erfolgreich in $chan ausgeschaltet."
  68.             }
  69.         }
  70.         "stats" {
  71.             if {[info exists ::blackjack(flood,count,$chan)] && [expr {[unixtime] - $::blackjack(flood,count,$chan)}] < 300} {
  72.                 return 0
  73.             } else {
  74.                 if {[channel get $chan "blackjackc"] == ""} {
  75.                     sendmsg $chan Blackjack "Ich habe in $chan noch kein einziges Spiel gesehen!"
  76.                 } elseif {[channel get $chan "blackjackc"] == "1"} {
  77.                     sendmsg $chan Blackjack "Ich habe in $chan erst ein einziges Spiel gesehen!"
  78.                 } else {
  79.                     sendmsg $chan Blackjack "Ich habe in $chan bisher [channel get $chan "blackjackc"] Spiele gesehen!"
  80.                 }
  81.                 set ::blackjack(flood,count,$chan) [unixtime]
  82.                 utimer 300 [list unset ::blackjack(flood,count,$chan)]
  83.             }
  84.         }
  85.         "version" {
  86.             global bj
  87.             if {[info exists ::blackjack(flood,version,$chan)] && [expr {[unixtime] - $::blackjack(flood,version,$chan)}] < 300} {
  88.                 return 0
  89.             } else {
  90.                 sendmsg $chan Blackjack "Ich benutze das $bj(name) $bj(version) von $bj(author) - $bj(web)"
  91.                 set ::blackjack(flood,version,$chan) [unixtime]
  92.                 utimer 300 [list unset ::blackjack(flood,version,$chan)]
  93.             }
  94.         }
  95.         "" {
  96.             if {![channel get $chan "blackjack"]} {
  97.                 return 0
  98.             } elseif {[info exists ::blackjack(flood,$chan)] && [expr {[unixtime] - $::blackjack(flood,$chan)}] < $::blackjack(flood)} {
  99.                 return 0
  100.             } else {
  101.                 if {[info exists ::blackjack(request,$chan)] == "1" || [info exists ::blackjack(started,$chan)] == "1"} {
  102.                     puthelp "notice $nick :In $chan ist schon ein Blackjack Spiel gestartet worden!"
  103.                     return 0
  104.                 } else {
  105.                     set ::blackjack(request,$chan) "1"
  106.                 }
  107.             }
  108.             if {$::blackjack(request,$chan) == "1"} {
  109.                 set ::blackjack(player,$chan) "[str2pat $nick]"
  110.                 set ::blackjack(active,$chan) "0"
  111.                 sendmsg $chan Blackjack "Das Spiel beginnt in 30 Sekunden! Schreibe $::blackjack(trigger)join um dem Spiel beizutreten!"
  112.                 utimer 30 [list blackjack:expire $chan]
  113.                 return
  114.             }
  115.         }
  116.     }
  117. }
  118.  
  119. proc blackjack:join {nick host hand chan arg} {
  120.     if {![channel get $chan "blackjack"]} {
  121.         return 0
  122.     } elseif {[info exists ::blackjack(request,$chan)] == "0"} {
  123.         return 0
  124.     } elseif {[llength $::blackjack(player,$chan)] == 5} {
  125.         puthelp "notice $nick :Das Blackjack Spiel in $chan ist schon voll!"
  126.         return 0
  127.     }
  128.     if {[lsearch $::blackjack(player,$chan) [str2pat $nick]] == "-1"} {
  129.         lappend ::blackjack(player,$chan) $nick
  130.         puthelp "notice $nick :Du bist dem Blackjack Spiel in $chan beigetreten!"
  131.     } else {
  132.         puthelp "notice $nick :Du bist dem Blackjack Spiel in $chan schon l?ngst beigetreten!"
  133.     }
  134. }
  135.  
  136. proc blackjack:expire {chan} {
  137.     if {[llength $::blackjack(player,$chan)] < 2} {
  138.         sendmsg $chan Blackjack "Die 30 Sekunden sind um und es hat sich niemand gemeldet. Ich geh weiter Karten mischen!"
  139.         unset ::blackjack(player,$chan)
  140.         unset ::blackjack(request,$chan)
  141.     } else {
  142.         unset ::blackjack(request,$chan)
  143.         set ::blackjack(started,$chan) "1"
  144.         foreach player $::blackjack(player,$chan) {
  145.             set ::blackjack(gesamt,wert,$chan,[getchanhost $player]) "0"
  146.             set ::blackjack(gesamt,karten,$chan,[getchanhost $player]) "0"
  147.         }
  148.         set ::blackjack(stapel,Kreuz,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  149.         set ::blackjack(stapel,Pik,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  150.         set ::blackjack(stapel,Herz,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  151.         set ::blackjack(stapel,Karo,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  152.         set ::blackjack(stapel,alle,$chan) "Kreuz Pik Herz Karo"
  153.         sendmsg $chan Blackjack "Das Spiel beginnt. Die Spieler sind [join $::blackjack(player,$chan) ", "]. Mit !karte l?sst du dir eine Karte geben. Mit !genug h?rst du auf. [lindex $::blackjack(player,$chan) 0] f?ngt an!"
  154.         set ::blackjack(idletimer,$chan) [utimer 60 [list blackjack:idle [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)] $chan]]
  155.     }
  156. }
  157.  
  158. proc blackjack:karte {nick host hand chan arg} {
  159.     if {![channel get $chan "blackjack"]} {
  160.         return 0
  161.     } elseif {![info exists ::blackjack(started,$chan)]} {
  162.         return 0
  163.     } elseif {$nick != [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)]} {
  164.         return 0
  165.     }
  166.  
  167.     if {[info exists ::blackjack(idletimer,$chan)]} {
  168.         killutimer $::blackjack(idletimer,$chan)
  169.         unset ::blackjack(idletimer,$chan)
  170.     }
  171.  
  172.     foreach stapel $::blackjack(stapel,alle,$chan) {
  173.         if {[llength $::blackjack(stapel,$stapel,$chan)] < 1} {
  174.             set ::blackjack(stapel,alle,$chan) "[lrange $::blackjack(stapel,alle,$chan) 0 [expr {[lsearch -exact $::blackjack(stapel,alle,$chan) $stapel] - 1}]] [lrange $::blackjack(stapel,alle,$chan) [expr {[lsearch -exact $::blackjack(stapel,alle,$chan) $stapel] + 1}] end]"
  175.             set ::blackjack(stapel,$chan) "[rand [llength $::blackjack(stapel,alle,$chan)]]"
  176.             set ::blackjack(stapelw,$chan) "[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)]"
  177.             set ::blackjack(karte,$chan) "[rand [llength $::blackjack(stapel,$::blackjack(stapelw,$chan),$chan)]]"
  178.             set ::blackjack(wert,$chan) "[lindex $::blackjack(stapel,[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)],$chan) $::blackjack(karte,$chan)]"
  179.         } else {
  180.             set ::blackjack(stapel,$chan) "[rand [llength $::blackjack(stapel,alle,$chan)]]"
  181.             set ::blackjack(stapelw,$chan) "[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)]"
  182.             set ::blackjack(karte,$chan) "[rand [llength $::blackjack(stapel,$::blackjack(stapelw,$chan),$chan)]]"
  183.             set ::blackjack(wert,$chan) "[lindex $::blackjack(stapel,[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)],$chan) $::blackjack(karte,$chan)]"
  184.         }
  185.     }
  186.     if {$::blackjack(stapelw,$chan) == "Kreuz" || $::blackjack(stapelw,$chan) == "Pik"} {
  187.         set blackjack(farbe,$chan) "\0031,0"
  188.     } elseif {$::blackjack(stapelw,$chan) == "Herz" || $::blackjack(stapelw,$chan) == "Karo"} {
  189.         set blackjack(farbe,$chan) "\0030,2"
  190.     }
  191.  
  192.     if {$::blackjack(gesamt,wert,$chan,$host) == 21 || $::blackjack(gesamt,wert,$chan,$host) > 21} {
  193.         puthelp "notice $nick :Du hast schon $::blackjack(gesamt,wert,$chan,$host) Punkte! Gib nun ?genug ein."
  194.         return 0
  195.     } elseif {$::blackjack(wert,$chan) == "Bube" || $::blackjack(wert,$chan) == "Dame" ||  $::blackjack(wert,$chan) == "K?nig"} {
  196.         set ::blackjack(gesamt,wert,$chan,$host) "[expr {$::blackjack(gesamt,wert,$chan,$host) + 10}]"
  197.     } elseif {$::blackjack(wert,$chan) == "Ass"} {
  198.         if {[expr {$::blackjack(gesamt,wert,$chan,$host) + 11}] > 21} {
  199.             set ::blackjack(gesamt,wert,$chan,$host) "[expr {$::blackjack(gesamt,wert,$chan,$host) + 1}]"
  200.         } else {
  201.             set ::blackjack(gesamt,wert,$chan,$host) "[expr {$::blackjack(gesamt,wert,$chan,$host) + 11}]"
  202.         }
  203.     } else {
  204.         set ::blackjack(gesamt,wert,$chan,$host) "[expr {$::blackjack(gesamt,wert,$chan,$host) + $::blackjack(wert,$chan)}]"
  205.     }
  206.  
  207.     set ::blackjack(gesamt,karten,$chan,$host) " $::blackjack(gesamt,karten,$chan,$host) $blackjack(farbe,$chan)$::blackjack(stapelw,$chan) $::blackjack(wert,$chan)\003"
  208.  
  209.     putquick "notice $nick :Deine Karten:$::blackjack(gesamt,karten,$chan,$host) - Gesamt Wert: $::blackjack(gesamt,wert,$chan,$host)"
  210.     set ::blackjack(stapel,[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)],$chan) "[lrange $::blackjack(stapel,[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)],$chan) 0 [expr {$::blackjack(karte,$chan)-1}]] [lrange $::blackjack(stapel,[lindex $::blackjack(stapel,alle,$chan) $::blackjack(stapel,$chan)],$chan) [expr {$::blackjack(karte,$chan)+1}] end]"
  211. }
  212.  
  213. proc blackjack:idle {nick chan} {
  214.     sendmsg $chan Blackjack "$nick ist eingeschlafen... Wieso zum Teufel mach ich das hier eigentlich!?"
  215.     unset ::blackjack(idletimer,$chan)
  216.     blackjack:genug $nick [getchanhost $nick] [nick2hand $nick] $chan keyed
  217. }
  218.  
  219. proc blackjack:kick {nick chan} {
  220.     set ::player(kick,$chan) "$::blackjack(player,$chan)"
  221.     set ::blackjack(player,$chan) ""
  222.     foreach players $::player(kick,$chan) {
  223.         if {$players != $nick} {
  224.             lappend ::blackjack(player,$chan) "$players"
  225.         } else {
  226.             continue;
  227.         }
  228.     }
  229.     unset ::player(kick,$chan)
  230. }
  231.  
  232. proc blackjack:genug {nick host hand chan arg} {
  233.     if {![channel get $chan "blackjack"]} {
  234.         return 0
  235.     } elseif {![info exists ::blackjack(started,$chan)]} {
  236.         return 0
  237.     }
  238.     if {$nick != [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)]} {
  239.         return 0
  240.     }
  241.     if {$::blackjack(gesamt,wert,$chan,$host) == 0 && [llength $::blackjack(gesamt,karten,$chan,$host)] == 0 && $arg != "keyed"} {
  242.         puthelp "notice $nick :Du musst dir mindestens einmal eine Karte geben lassen, bevor du ?genug machen kannst"
  243.         return 0
  244.     } elseif {$::blackjack(gesamt,wert,$chan,[getchanhost [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)]]) > 21 || $::blackjack(gesamt,wert,$chan,[getchanhost [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)]]) == "0" && $arg == "keyed"} {
  245.         blackjack:kick [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)] $chan
  246.     } else {
  247.         incr ::blackjack(active,$chan)
  248.     }
  249.     if {[expr {[llength $::blackjack(player,$chan)]-1}] < $::blackjack(active,$chan)} {
  250.         if {[llength $::blackjack(player,$chan)] < 1} {
  251.             sendmsg $chan Blackjack "Unentschieden! Alle Spieler sind ausgeschieden!"
  252.         } else {
  253.             set ::blackjack(winner,$chan,check) "$::blackjack(gesamt,wert,$chan,[getchanhost [lindex $::blackjack(player,$chan) 0]])"
  254.             set ::blackjack(winner,$chan) "[lindex $::blackjack(player,$chan) 0]"
  255.             set ::blackjack(winner,$chan,zahl) "1"
  256.             foreach player $::blackjack(player,$chan) {
  257.                 if {$::blackjack(winner,$chan) == $player} {
  258.                     continue;
  259.                 } elseif {$::blackjack(gesamt,wert,$chan,[getchanhost $player]) > 21} {
  260.                     continue;
  261.                 } elseif {$::blackjack(gesamt,wert,$chan,[getchanhost $player]) > $::blackjack(winner,$chan,check)} {
  262.                     set ::blackjack(winner,$chan) "$player"
  263.                     set ::blackjack(winner,$chan,check) "$::blackjack(gesamt,wert,$chan,[getchanhost $player])"
  264.                     continue;
  265.                 } elseif {$::blackjack(gesamt,wert,$chan,[getchanhost $player]) == $::blackjack(winner,$chan,check)} {
  266.                     lappend ::blackjack(winner,$chan) "$player"
  267.                     continue;
  268.                 }
  269.             }
  270.             if {[llength $::blackjack(winner,$chan)] > 1} {
  271.                 set ::blackjack(player,$chan) "$::blackjack(winner,$chan)"
  272.                 foreach player $::blackjack(player,$chan) {
  273.                     set ::blackjack(gesamt,wert,$chan,[getchanhost $player $chan]) "0"
  274.                     set ::blackjack(gesamt,karten,$chan,[getchanhost $player $chan]) ""
  275.                 }
  276.                 set ::blackjack(stapel,Kreuz,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  277.                 set ::blackjack(stapel,Pik,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  278.                 set ::blackjack(stapel,Herz,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  279.                 set ::blackjack(stapel,Karo,$chan) "Ass 2 3 4 5 6 7 8 9 10 Bube Dame K?nig"
  280.                 set ::blackjack(stapel,alle,$chan) "Kreuz Pik Herz Karo"
  281.                 set ::blackjack(active,$chan) "0"
  282.                 sendmsg $chan Blackjack "Die Spieler [join $::blackjack(player,$chan) ", "] haben mit $::blackjack(winner,$chan,check) die gleiche Punktzahl, deswegen gibt es nun ein Stechen! [lindex $::blackjack(player,$chan) 0] f?ngt an."
  283.                 set ::blackjack(idletimer,$chan) [utimer 60 [list blackjack:idle [lindex $::blackjack(player,$chan) 0] $chan]]
  284.                 return 0
  285.             } else {
  286.                 sendmsg $chan Blackjack "Der Gewinner ist $::blackjack(winner,$chan) mit $::blackjack(gesamt,wert,$chan,[getchanhost $::blackjack(winner,$chan) $chan]) Punkten!"
  287.             }
  288.             unset ::blackjack(winner,$chan)
  289.             unset ::blackjack(winner,$chan,zahl)
  290.             unset ::blackjack(winner,$chan,check)
  291.         }
  292.         if {[channel get $chan "blackjackc"] == ""} {
  293.             set bjcount "0"
  294.         } else {
  295.             set bjcount "[channel get $chan blackjackc]"
  296.         }
  297.         incr bjcount
  298.         channel set $chan blackjackc "$bjcount"
  299.         set ::blackjack(flood,$chan) [unixtime]
  300.         utimer 300 [list unset ::blackjack(flood,$chan)]
  301.         foreach player $::blackjack(player,$chan) {
  302.             unset ::blackjack(gesamt,wert,$chan,[getchanhost $player $chan])
  303.         }
  304.         unset ::blackjack(player,$chan)
  305.         unset ::blackjack(started,$chan)
  306.         unset ::blackjack(stapel,Kreuz,$chan)
  307.         unset ::blackjack(stapel,Pik,$chan)
  308.         unset ::blackjack(stapel,Herz,$chan)
  309.         unset ::blackjack(stapel,Karo,$chan)
  310.         unset ::blackjack(stapel,alle,$chan)
  311.         unset ::blackjack(stapel,$chan)
  312.         unset ::blackjack(stapelw,$chan)
  313.         unset ::blackjack(karte,$chan)
  314.         unset ::blackjack(wert,$chan)
  315.         return 0
  316.     } else {
  317.         sendmsg $chan Blackjack "Ok, [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)] du bist an der Reihe!"
  318.         set ::blackjack(idletimer,$chan) [utimer 60 [list blackjack:idle [lindex $::blackjack(player,$chan) $::blackjack(active,$chan)] $chan]]
  319.     }
  320. }
  321.  
  322. proc blackjack:stop {nick host hand chan arg} {
  323.     if {[info exists ::blackjack(request,$chan)]} {
  324.         unset ::blackjack(request,$chan)
  325.         putquick "notice $nick :Done! Die Variable \$::blackjack(request,$chan) ist in $chan resettet!"
  326.     }
  327.     if {[info exists ::blackjack(started,$chan)]} {
  328.         unset ::blackjack(started,$chan)
  329.         putquick "notice $nick :Done! Die Variable \$::blackjack(started,$chan) ist in $chan resettet!"
  330.     }
  331. }
  332.  
  333. putlog "$bj(name) $bj(version) von $bj(author) - $bj(web) erfolgreich geladen!"
  334.  
  335. #EOF
Add Comment
Please, Sign In to add comment