|
Joined: Dec 2004
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2004
Posts: 5 |
Hello, not sure if the topic describes this as well as i could. But here's the script with an explanation of what i am in need of:
on *:join:#:{
set %random $time(ss)
$read(quotesubmitter.txt, w, * $+ $nick $+ *, %random)
if ($readn = 0) {
/msg # Autoquote function error! (no quotes for user/buggy coding)
halt
}
else {
/msg # Random Quote Submitted by: $nick
/msg # Quote $chr(35) $+ $readn $+ : $read(quotes.txt, $readn)
}
}
as you can see when somone joins a channel it searches a text file (quotesubmitter.txt) to find the nick of the user who just joined. when it finds a match, it uses $readn to call the same line from quotes.txt which corresponds to quotesubmitter.txt. now the problem: what i don't want is for it to print the same quote every time the same person joins. So i need a way to make it start on a random line, so it will print basicly a random quote (submitted by that user) every time they join. The way i have done it was quick but buggy, ie, it returns 0 alot. So if somone could come up with something tricky to make this less buggy and more effecient, i would gladly steal it thanks in advance.
|
|
|
|
Joined: Aug 2003
Posts: 314
Fjord artisan
|
Fjord artisan
Joined: Aug 2003
Posts: 314 |
Here's a custom identifier you can use to get a random line from a file based on a wildmatch:
; $getrline(<file>,<wildmatch>)
alias getrline {
if ($0 = 1) set -u %tmp %tmp $gettok($1,1,32)
else {
%tmp =
filter -nfk " $+ $1" getrline $2
return $read($1,nt,$gettok(%tmp,$r(1,$numtok(%tmp,32)),32))
}
}
So in your case you'd use $getrline(quotesubmitter.txt,* $+ $nick $+ *)
|
|
|
|
Joined: Dec 2004
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2004
Posts: 5 |
sorry i'm not too familiar with the /filter command. But i seem to be getting this error when I use your alias.
* /filter: invalid window (line 7, quotes.mrc)
I added the alias to the top of my "quotes.mrc" remote script and changed the required aliases. Am I doing something wrong?
|
|
|
|
Joined: Aug 2003
Posts: 314
Fjord artisan
|
Fjord artisan
Joined: Aug 2003
Posts: 314 |
Forgot to mention, you need mIRC version 6.15 or newer to use that (since the 'k' switch of /filter was only implemented recently)
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
That's a nice alias, I like the recursion. It would become a problem (as you know) when there are too many matching lines in the file, giving /set string too long error. One could also use this approach: alias getrline {
window -h @@
filter -fw " $+ $1" @@ $$2
var %a = $iif($filtered,$line(@@,$r(1,$ifmatch)))
close -@ @@
return %a
}
If there's something I like about mIRC, it's that you can achieve the same things, using different techniques. Cya Sigh EDIT: Post #666 evil grin
Last edited by FiberOPtics; 06/01/05 03:06 PM.
|
|
|
|
Joined: Dec 2004
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2004
Posts: 5 |
With either of those aliases, how would i get the line number that $getrline called, like with the $readn command. Since all $getrline seems to be able to return is the actual contents of a line.
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
alias getrline {
window -n @@
filter -fw[color:red]n[/color] " $+ $1" @@ $$2
var %a = $iif($filtered,$line(@@,$r(1,$ifmatch)))
close -@ @@
return %a
}
By adding the n switch, the numbers that are filtered to the hidden window are preceeded by their line number. In other words, if there are matches, the variable %a will hold the following: %a --> $1 = line number, $2- = quote Greets
Gone.
|
|
|
|
Joined: Dec 2004
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2004
Posts: 5 |
ah, but how can i seperate that into two different variables, or make it return either $1 or $2?
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Just parse the result.
Example:
//tokenize 32 $getrline(quotes.txt,*hello*) | echo -a Line number: $1 ** Quote: $2-
//var %full = $getrline(quotes.txt,*hehe*), %number = $gettok(%full,1,32), %quote = $gettok(%full,2-,32)
...
Greets
Gone.
|
|
|
|
|