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.

scarabeo tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
s
sky6419
Voice
Posts: 23
Joined: Fri Jan 17, 2014 5:31 am

scarabeo tcl

Post by sky6419 »

HI everyone I'm new in to the forum someone can tell me how to remove the flag +Q into the script?
It also puts into the mouth for flood and ignore those who play you have any idea?

Code: Select all

#Scarabeo.tcl by cyborgirl & nilo
#spacial tnx DrGoNzO e tutti gli altri amici :°)



set vers "2.2.c"
set scadir "scarabeo"
set consonanti  "b c d f g h l m n p q r s t v z"
set vocali  "a e i o u"
set nletter 14
set numvocali 4
set vocabolario "$scadir/dizionario.txt"
if {![file exist $vocabolario]} {
 putlog "vocabolario non trovato"
 putlog "FAILED LOADED"
 return 0
}
proc lrand {letter} {
     set l [lindex $letter [rand [expr [llength $letter] - 1]]]
     return $l 
}

proc do_lettere {} {
      global vocali consonanti nletter numvocali
      set nvocali [expr $numvocali + [rand 2]]
      for {set i 0}  {$i < [expr $nletter - $nvocali]} {incr i} {
       lappend letters [lrand $consonanti]
      }
      for {set i 0}  {$i < $nvocali} {incr i} {
       lappend letters [lrand $vocali]
      }
     return $letters
}

proc nl_killutimer {cmd} {
  regsub -all -- {\[} $cmd {\[} cmd ; regsub -all -- {\]} $cmd {\]} cmd
  foreach tmr [utimers] {
    if {[string match $cmd* [join [lindex $tmr 1]]]} {
      killutimer [lindex $tmr 2]
    }
  }
}

bind pub Q !scarabeo pub_scarabeo

proc pub_scarabeo {nick host hand chan text} {
     global pubstarted scarachan stopped maxmanche global vers botnick consonanti vocali caos botj botd
     if {[info exist pubstarted] && [info exist scarachan] && ($chan != $scarachan)} { 
     putserv "PRIVMSG $chan :Scarabeo già attivo su $scarachan"
     return 0
     }
     set scarachan $chan
     if {[lindex $text 0] == "start"} {
       if {[info exist pubstarted]} {
         putserv "PRIVMSG $chan :Scarabeo già attivo su $chan"
         return 0
        }
      set mode [lindex $text 2]
      if {[lindex $text 1] > 0 && (( $mode == "caos") || ($mode == "standard") || ($mode == "bot"))} {
        if {$mode == "bot"} {
          if {[lindex $text 3] <= 0} {
           putserv "PRIVMSG $chan :Usa !scarabeo start n°matches bot difficoltà ( >= 10)"
           return 0
           }
         set botj 1
          if {[lindex $text 3] > 10} { 
           set botd [expr [lindex $text 3] - 4] 
          } else {
          set botd 6
          }
        set caos 1
        } 
        if {$mode == "caos"} {set caos 1}
        if {$mode == "standard"} {set caos 0}
        if {[info exist stopped]} {unset stopped}
        set maxmanche [lindex $text 1]
        set pubstarted 1
       foreach i $consonanti {
        lappend lettere $i
       }
       foreach i $vocali {
        lappend lettere $i
       }
       foreach l $lettere {
        set v "$l = \002 [lvalori $l] \002"
        lappend valori $v
       }
       regsub -all (\{|\}) $valori "" valori
       if {$caos == 0} {
        putserv "PRIVMSG $chan :\002 \0033Scarabeo Versione $vers "
        putserv "PRIVMSG $chan :\0033 Scrivete in query a $botnick la parola che riuscite a creare con le lettere che vi darò"
        putserv "PRIVMSG $chan :\0033 Solo la prima parola che digitate verrà accettata come risposta"
        putserv "PRIVMSG $chan :\0034 I valori delle lettere sono : $valori"
        putserv "PRIVMSG $chan :\0033 Buon Divertimento \002 :°D"
        utimer 5 [list scarabeostart $chan] 
        return 0
       }
       putserv "PRIVMSG $chan :\002 \0033Scarabeo Versione $vers " 
       putserv "PRIVMSG $chan :\0033 Scrivete in query a $botnick tutte le parole che riuscite a creare con le lettere che vi darò"
       putserv "PRIVMSG $chan :\0034 I valori delle lettere sono : $valori"
       putserv "PRIVMSG $chan :\0033 Buon Divertimento \002 :°D"
       utimer 5 [list scarabeostart $chan]
       return 0
      }
      putserv "PRIVMSG $chan :Usa !scarabeo start n°matches standard/caos/bot"
     }
     if {[lindex $text 0] == "stop" && [info exist pubstarted]} {
     scarabeostop     
     return 0
     }
}

bind pub Q !valori pub_valori

proc pub_valori {nick host hand chan arg} {
     global consonanti vocali
     foreach i $consonanti {
      lappend lettere $i
     }
     foreach i $vocali {
      lappend lettere $i
     }
     foreach l $lettere {
     set v "$l = \002 [lvalori $l] \002"
     lappend valori $v
     }
     regsub -all (\{|\}) $valori "" valori
     putserv "PRIVMSG $chan : $valori"
 
}

proc scarabeostop { } {
   global scarachan pubstarted stopped manche maxmanche punti pmatch caos botj botd
    if {[info exist pubstarted]} {unset pubstarted} 
    if {[info exist botj]} {unset botj}
    if {[info exist manche]} {unset manche}
    if {[info exist maxmanche]} { unset maxmanche}
    if {[info exist punti]} {unset punti}
    if {[info exist pmatch]} {unset pmatch}
    if {[info exist caos]} {unset caos}
    if {[info exist botd]} {unset botd}
    if {[info exist scarachan]} {
      putserv "PRIVMSG $scarachan :Scarabeo disattivato"
      unset scarachan
    }
    nl_killutimer diecisecondi
    nl_killutimer stop_match
    set stopped 1
}


proc scarabeostart {chan} {
     global vocabolario risposte paroleok stopped maxmanche manche pvalore caos
      if {[info exist stopped]} {return 0}
      if {![info exist manche]} {set manche 0}
      incr manche
      if {$manche > $maxmanche} { 
      finegioco $chan
      return 0
      }
      set paroleok ""
      set file [open $vocabolario]
      set lettere [do_lettere]
      while {![eof $file]} {
       set parola [gets $file]
       set pcon $parola
        foreach l $lettere {
         if {[string match *$l* $pcon]} {
         regsub $l $pcon "" pcon
         }
        }
       if {[string length $pcon] == 0} {
       lappend paroleok " $parola"
       set pvalore($parola) [pval $parola]
       }
     }
     regsub -all (\{|\}) $paroleok "" paroleok
      do_match $lettere $paroleok $chan 
     utimer 90 [list diecisecondi $chan]
}
proc diecisecondi {chan} {
       global pmatch botnick caos 
       set gmatch [array names pmatch]
     if {$caos == 1} {
       foreach g $gmatch {
        if {$g != $botnick} {
         putserv "PRIVMSG $g :\002 \0034 Mancano 10 secondi"
        }
       }
     } 
    putserv "PRIVMSG $chan :\002 \0034 Mancano 10 secondi"

}

proc do_match {lettere paroleok chan} {
    global started manche maxmanche mlettere rmatch botnick pmatch rmatch pvalore caos botj botd
    set mlettere $lettere
    set started 1
    if {[info exist rmatch]} {unset rmatch}
    putserv "PRIVMSG $chan :\0031,11Round $manche\\$maxmanche LE LETTERE SONO :\002 $mlettere"
    if {[info exist botj] && [info exist botd]} {
      set ri [expr [rand $botd] + 4]
      set pmatch($botnick) 0
      for {set i 0} {$i <= $ri} {incr i} {
        set text [lindex $paroleok [rand [llength $paroleok]]]
          if {[info exist rmatch($botnick)]} {
            foreach p $rmatch($botnick) {
             if {$p == $text} {
             continue
             }
            }
           }
         set pmatch($botnick) [expr $pmatch($botnick) + $pvalore($text)]
         lappend rmatch($botnick) $text
       }
    }
    utimer 100 [list stop_match $chan]
}

proc stop_match {chan} {
    global pmatch started punti rmatch
    unset started 
    putserv "PRIVMSG $chan :TEMPO SCADUTO"
    if {[info exist pmatch]} {
      set gmatch [array names pmatch]
     foreach g $gmatch {
       if {[info exist punti($g)]} {
        set punti($g) [expr $punti($g) + $pmatch($g)]
       } else {
        set punti($g) $pmatch($g)
       }
      if {[info exist rmatch($g)]} {
      putserv "PRIVMSG $chan :\002 \0034 $g \002 \0034 ha riposto \002 \0034 $rmatch($g) \002 \0034 punti \002 \0034 $pmatch($g) \002 \0034"
#      unset rmatch($g)
      }
     }
    unset pmatch
    }
    utimer 4 [list classifica $chan]
    utimer 5 [list putserv "PRIVMSG $chan:\0033 sta per iniziare il prossimo round"]
    utimer 20 [list scarabeostart $chan] 
}

bind msgm - * msg_scarabeo

proc msg_scarabeo {nick host hand text} {
     global paroleok pmatch started rmatch pvalore caos mlettere botnick
     if {![info exist started]} {return 0} 
     set text [lindex $text 0]
     if {$nick == $botnick} {return 0}
    if {$caos == 0 } {
     if {[info exist pmatch($nick)]} {
     return 0
     }
     if {[string match "* $text *" $paroleok]} {
      set pmatch($nick) $pvalore($text)
      set rmatch($nick) $text
      return 0
     }
     set pmatch($nick) 0
     set rmatch($nick) $text
     return 0
    }
    if {[info exist rmatch($nick)]} {
     foreach p $rmatch($nick) {
      if {$p == $text} {
      return 0
      }
     }
    }

    if {![info exist pmatch($nick)]} {
    set pmatch($nick) 0
    puthelp "PRIVMSG $nick :\002 $mlettere"
    }
   if {[string match "* $text *" $paroleok]} {
       putlog "accettata"     
       set pmatch($nick) [expr $pmatch($nick) + $pvalore($text)]
       lappend rmatch($nick) $text
       return 0
     }
} 


proc lvalori {l} {
     if {$l == "a" || $l == "c" || $l == "e" || $l == "i" || $l == "o" || $l == "r" || $l == "s" || $l == "t" } {return 1}
     if {$l == "l" || $l == "n" || $l == "m" } {return 2}
     if {$l == "p"} {return 3}
     if {$l == "b" || $l == "d" || $l == "f" || $l == "g" || $l == "u" || $l == "v" }  {return 4}
     if {$l == "h" || $l == "z" } {return 8}
     if {$l == "q" } {return 10}
     return 0
}

proc pval {parola} {
    set val 0
    for {set i 0} { $i < [string length  $parola]} {incr i} {
    set val [expr $val + [lvalori [string index $parola $i]]]
    }
    return $val
}
proc classifica {chan} {
      global punti pos npos
      set cnick [array names punti]
      foreach n $cnick {
       if {[info exist punti($n)]} {
        lappend cpunti $punti($n)
       }
      }
      if {[info exist npos]} {unset npos}
      if {[info exist pos]} {unset pos}
      set cpunti [lsort -decreasing -integer $cpunti]
      set potition "p s t"
      set pos(p) [lindex $cpunti 0]
      set comp $pos(p)
      set p s
      for {set i 0} { $i <= [llength $cpunti]} {incr i} {
       if {[lindex $cpunti $i] == $comp} {
        continue
         }
        set pos($p) [lindex $cpunti $i]
        if {$p == "t" } {break}
        set p t
        set comp $pos(s)
       }
      foreach n $cnick {
       foreach c $potition {
          if {[info exist pos($c)]} {
      
            if {$punti($n) == $pos($c)} {
             lappend npos($c) $n
            }
          }
       }
      }
     putserv "PRIVMSG $chan :\002 CLASSIFICA"
     putserv "PRIVMSG $chan :In 1° Posizione Con $pos(p) Punti ... $npos(p)"
      if {[info exist pos(s)] && [info exist npos(s)]} {
       putserv "PRIVMSG $chan :In 2° Posizione CoN $pos(s) Punti ... $npos(s)"
      }
      if {[info exist pos(t)] && [info exist npos(t)]} {
       putserv "PRIVMSG $chan :In 3° Posizione CoN $pos(t) Punti... $npos(t)"
      }
}

proc finegioco {chan} {
     global pos npos  manche maxmanche punti
     if {[llength $npos(p)] > 1} {
     set verb "Vincono"
     } else {
     set verb "Vince"
     }

     putserv "PRIVMSG $chan :DOPO [expr $manche - 1] Rounds, Con $pos(p) punti $verb: \0034 $npos(p) "
     unset npos; unset pos ;unset manche; unset maxmanche;unset punti
     scarabeostop
}



putlog "Scarabeo.tcl $vers caricata"
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Hi,

replace the:

Code: Select all

bind pub Q
with a "-" (without ") if you wish to have it be active for ALL channel members (not eggdrop users), or any other flag you wish.
Once the game is over, the king and the pawn go back in the same box.
s
sky6419
Voice
Posts: 23
Joined: Fri Jan 17, 2014 5:31 am

Post by sky6419 »

Thanks caesar excellent ...
very well know scripting tcl?
Post Reply