Picks a word at random, then scrambles the letters, displaying the scrambled word. Keeps track of the total number of guesses and how long it takes to guess each word
To start: !Scramble
To Guess:!Scramble word
Random word coding compliments of another scripter. Would love to be able to give proper credit to this person, but they didn't include their name in the code that I got, and I don't recall where I got the code from.
on *:text:!scramble*:#:{
if (!$2) {
unset %guess_count
unset %output
while !%word {
set %word $lower($randword)
while $numtok(%word,32) > 1 { set %word $lower($randword) }
var %letter = 1
while %letter <= $len(%word) {
if $mid(%word,%letter,1) !isletter unset %word
inc %letter 1
}
}
var %remain = %word
var %d $len(%word)
while %d > 0 {
var %f = $rand(1,%d)
var %output = %output $+ $right($left(%remain,%f),1)
var %remain = $+($left(%remain,$calc(%f - 1)),$right(%remain,$calc(%f - $calc(%f * 2))))
dec %d
}
set %start $ctime
describe # 5The scrambled word is %output
}
elseif $len($2) > $len(%word) .notice $nick Sorry but you have $calc($len($2) - $len(%word)) letters too many
elseif $len($2) < $len(%word) .notice $nick Sorry but you have $calc($len(%word) - $len($2)) letters too few
elseif $lower($2) == %word {
inc %guess_count 1
describe # Congratulates $nick for $iif(%guess_count > 1 ,guessing the correct word 4 $upper(%word) in 5 %guess_count tries and 12 $duration($calc($ctime - %start)) ,figuring out the correct word 4 $upper(%word1) in 5 1 try and 12 $duration($calc($ctime - %start)) )
unset %word
}
else {
inc %guess_count 1
var %d = 1
while %d <= $len(%word1) {
if $mid($2,%d,1) !isin %word1 {
.notice $nick 4 Invalid letters detected
halt
}
inc %d
}
var %d = 1
while %d <= $len(%word1) {
if $mid($2,%d,1) == $mid(%word1,%d,1) { var %output = $+(%output,$upper($mid($2,%d,1))) }
else { var %output = $+(%output,$lower($mid($2,%d,1))) }
inc %d
}
describe # 5The scrambled word is %output
}
}
; Generate initial word list (not necessary, but recommended)
on *:LOAD:{
randword -r
}
alias randword {
if ($sock(randomword) != $null) { sockclose randomword }
sockopen randomword dict.org 2628
set %rand.file $+(",$scriptdir,randword.txt,")
; Identifier
if ($isid) {
if ($read(%rand.file) != $null) && ($1 != -r) { return $read(%rand.file) }
; If the file's empty it returns blah
; This is mainly for first time you use this
if ($read(%rand.file) == $null) && ($1 != -r) { return blah }
}
; Alias
else {
if ($read(%rand.file) != $null) && ($1 != -r) { echo $color(info) -a $read(%rand.file) }
if ($read(%rand.file) == $null) && ($1 != -r) { echo $color(info) -a blah }
}
}
on *:sockopen:randomword:{
write -c %rand.file
sockwrite -n $sockname m substring $+($rand(a,z),$rand(a,z),$rand(a,z))
sockwrite -n $sockname quit
unset %rand.match
unset %rand.wcount
}
on *:sockread:randomword:{
if ($sockerr > 0) return
:next
inc %rand.wcount
sockread %rand.temp
if ($sockbr == 0) return
if (!%rand.temp) { goto next }
if ($gettok($remove(%rand.temp,"),2-,32) isupper) { goto next }
if ($gettok(%rand.temp,1,32) !isnum) {
write %rand.file $gettok($remove(%rand.temp,"),2-,32)
}
goto next
}
on *:sockclose:randomword:{
if ($lines(%rand.file) == 0) {
.timer -m 1 250 randword -r
}
}
If the script has found a word, then the word does exist. There is no guarantee that the word will be from a particular language, or won't be a contraction, short form, slang, etc.
As to resetting the file, this has to be done using the client that is running the code and can be re-generated by typing /randword -r
Regretfully I've been too busy with real life to do any scripting. The only thing that I can think of that would stop this script from working is if the website that supplies the code gets the words from has changed their coding. If this is the case, then there's nothing I can do, as that section of the code was written by someone else, as stated in the introduction.
If someone else wants to take a crack at checking, and, if necessary, recoding that section of the script, be my guest. I don't have the time.
I've tried to reset this several times and all it gives me is a word made of "sppp". May I suggest a word list file on the bot itself? I maintain a channel bot with different games and I would really like to have a reliable Scramble game. To be honest, I don't have the scripting skill yet to make the changes. I'm gonna take a look at it anyway but I thought maybe the script author would prefer to make the change first.