mIRC Home    About    Download    Register    News    Help

Print Thread
#13665 01/03/03 03:45 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
Lets say I have a text file that looks like this:
Code:
ed said hi to kat this morning
john waved at ed this afternoon
bill saw kat last night :x
kat wasn't amused


Is there a way to make $read(file.txt, s, kat) to be randomized, so that on the first $read, it gives 'ed said hi to kat this morning', but on the second it would give 'kat wasn't amused' ...?

Example two: $read(file.txt, s, this) would return a line (randomly?) with the word 'this' in it.

Thanks,
-ed

Last edited by acemiles_ed; 01/03/03 04:13 PM.
#13666 01/03/03 03:47 PM
Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
//echo $read(funny.txt)

Reads a random line from the file funny.txt.

ah nevermind i see you have happy and sad in the file using the -s switch is going to scan the file for a line with happy assuming that it prolly scans from top to bottom it will hit the same line each time you might try using the $readn value to exclude that line in the next call ? or simply make more than one .txt file happy.txt sad.txt etc..

Last edited by Cheech; 01/03/03 03:54 PM.
#13667 01/03/03 04:03 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
Well... it would actually be used for a quotes script, and I was hoping that users would be able to type !quote <anything> and it would randomly search for a line with the <word> in it.

#13668 01/03/03 04:07 PM
Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
well it takes a little longer but you could still seperate it into catagories happy, sad, silly, etc.. just type !quote *whatver* then go to the coresponding file ?

#13669 01/03/03 04:11 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
Well.. I guess my text file example was not very specific... I *could* split it into a bunch of categories, but some may fall in both, and I could end up having 400 txt files with all the possible search terms... I will edit my first post with a better text file example..

#13670 01/03/03 05:01 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
My suggestion, but havent tested for bugs...:
Code:
on *:TEXT:!quote*:#:{
  var %l = 1
  var %c = 0
  while ( $read([color:green]quote.txt[/color],w,* $+ $2 $+ *,%l) != $null ) {
    inc %l
    inc %c
  }
  msg $nick $read([color:green]quote.txt[/color],w,* $+ $2 $+ *,$rand(1,%c))
}


#13671 01/03/03 06:36 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
A much faster way (and this is important, since it's a remotely triggered routine) is to use /filter to grab all lines and dump them to a hidden custom window, then select a random line from that window.
Code:
on *:text:!quote ?*:#:{
  window -h @@
  filter -fwc quotes.txt @@ * $+ $2*
  if $filtered { msg $nick $line(@@,$rand(1,$ifmatch)) }
  close -@ @@
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#13672 01/03/03 07:10 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
Thanks to everyone for their help!


Link Copied to Clipboard