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.
Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sat Apr 22, 2006 3:35 pm
I've done a search, not got far.. i did find this so i tried to sort it out, but because i cant code TCL alot yet, it obviously it isnt working.
Any ideas? Would help alot
By The way, its to read from a file called sex.txt and to choose a random line on !sex to say into the #chan.
Code: Select all
set sex "./sex.txt"
set sexmsg [string range [randomline $sex] 0 end]
bind pub - !sex randomline
proc randomline {nick uhost hand chan arg} {
# !sex triggers this procedure.
proc randomline { sex } {
set position [rand [expr [file size $filename] - 1024]]
set fd [open $filename r]
catch {
seek $fd $position
set text [read $fd 1024]
}
close $fd
set lines [split $text \n]
set lineno [randrange 1 [expr [llength $lines] - 1]]
return [lindex $lines $lineno]
}
}
Last edited by
DjBeNNeTT on Sat Apr 22, 2006 5:44 pm, edited 1 time in total.
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Sat Apr 22, 2006 4:18 pm
- you have pasted the code twice
- you define a proc within a proc
- you define two procs with the same name
- you unncessarily open the file twice (use gets twice, instead of read and second open)
- you define the random message globally... it will stay the same until rehash/restart
thats about all I can say about that code which will never work as itented like it is
.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under
The MIT License
Love hurts, love strengthens...
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sat Apr 22, 2006 5:45 pm
Well as i said, i know little. So i was wondering of some help.
Sorry for pasting twice, its now just once.
I had guessed that the 2 proc was wrong.. the first one was which causing the error.
Thanks for noticing tho's... Hope someone can point me in the right (coding) direction
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Sat Apr 22, 2006 6:05 pm
Code: Select all
set sex "./sex.txt"
bind pub - !sex sex:msg
proc sex:msg {nick uhost hand chan arg} {
global sex
set sexmsg [string range [randomline $sex] 0 end]
puthelp "privmsg $chan :$sexmsg"
}
proc randomline { filename } {
set position [rand [expr [file size $filename] - 1024]]
set fd [open $filename r]
catch {
seek $fd $position
set text [read $fd 1024]
}
close $fd
set lines [split $text \n]
set lineno [randrange 1 [expr [llength $lines] - 1]]
return [lindex $lines $lineno]
}
proc randrange { lowerbound upperbound } {
return [expr {int(($upperbound - $lowerbound + 1) * rand() + $lowerbound)}]
}
Add [SOLVED] to the thread title if your issue has been.
Search |
FAQ |
RTM
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sat Apr 22, 2006 6:33 pm
Your a god for loads of stuff i want if this works!!!
Just the one prob i find atm...
on !sex...
[23:30:51] [BooByBoT] [22:30] Tcl error [sex:msg]: random limit must be greater than zero
I've changed both "set sexmsg [string range [randomline $sex] 0 end] " and "* rand()" to (3) and still nothing...
I'm turning blind (must be tired) lol
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Sat Apr 22, 2006 7:27 pm
change:
to
.. making certain the file (sex.txt) actually exists and you have added the lines of text you want (using pico).
I tested on a Windrop and it worked 100%.
Add [SOLVED] to the thread title if your issue has been.
Search |
FAQ |
RTM
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sat Apr 22, 2006 7:39 pm
Mines windrop and Still getting same message...
my sex.txt file has:
Ohhh babeh!
Hmmmm!
YES YES YEEESSHHHH!!!!
With You? [censored] off!
Send Me Your Pic First
Get Away From Me With That Filthy Anaconda!
All as it looks there..
What you mean "using pico"?
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sat Apr 22, 2006 7:43 pm
Code: Select all
set sex "./sex.txt"
bind pub - !sex sex:msg
proc sex:msg {nick uhost hand chan arg} {
global sex
set sexmsg [string range [randomline $sex] 0 end]
puthelp "privmsg $chan :$sexmsg"
}
proc randomline f {
set data [split [read [set file [open $f]]][close $file] \n]
set position [rand [llength $data]]
lindex $data $position
}
But the best solution would be to read the file into a list and use the list instead of the file everytime the command is called. Try to search the forum about how that can be implemented, it has been implemented 100 times here.
Last edited by
Sir_Fz on Sat Apr 22, 2006 7:48 pm, edited 1 time in total.
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Sat Apr 22, 2006 7:48 pm
Excellent Sir_Fz.
I concur. I should have thought of that in the first place.
DjBeNNeTT wrote: What you mean "using pico"?
pico is a *nix text editor. I was unaware you were using a Windrop in which case you'd be using notepad/EditPlus to edit scripts.
Add [SOLVED] to the thread title if your issue has been.
Search |
FAQ |
RTM
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sat Apr 22, 2006 8:11 pm
Thank you both for your time. Sir_Fz worked perfectly! Thanks
And i actually use WordPad for scripts... as Notepad likes to bugger up most the time and not set out the next lines properly making it unreadable... Bugger thing.
Ah well
Thanks both again
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sat Apr 22, 2006 8:32 pm
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sun Apr 23, 2006 3:21 am
Thanks, i'll give it a try.
Is there a way that if it has $nick in the .txt file it will say the nickname who did the command? Or can that only be done in the code itself to say for each message?.
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sun Apr 23, 2006 4:40 am
use
instead of just $sexmsg.
DjBeNNeTT
Voice
Posts: 27 Joined: Sat Feb 18, 2006 6:40 pm
Location: Telford, Shropshire, UK
Contact:
Post
by DjBeNNeTT » Sun Apr 23, 2006 5:29 am
where
LoL sorry :p
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sun Apr 23, 2006 1:01 pm
How many $sexmsg s are there in that code?