mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: May 2015
Posts: 5
So I am essentially attempting to script a bot so every 5 minutes it displays a random fact from a textfile.

I achieved that with:

on me:*:join:#:{
.timerfacts 0 $rand(240,300) msg $chan $!read(facts.txt,n)
}

however often times it will repeat the same fact within a 15 minute time period (by pure luck of course) but I am wondering if there is a way to set it up so that it will not repeat a line until all of the lines from the file have been read.

http://www.mirc.org/mishbox/tutorials/readworepeat.htm
I saw that mIRC has a topic about this but after copying the code everytime i try to call the alias it gives me an unknown command error and nothing will display.

I'm quite new to the mIRC language and still dont fully understand its complexities any help would be appreciated.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
The idea of that script is to store the line that are read and to check that the line hasn't been read before validating

It uses a variable which is a bit too simple and will end up being wrong if you have too many lines, a quick hash table with the $hash of the line will work better:

Code:
alias randomline {
  var %h randomline $+ $hash($1,32),%ok
  if ($2 == clear) hfree %h
  else {
    var %r $read($1,$2),%l $hash(%r,32)
    while ($hget(%h,%l)) var %r $read($1,$2),%l $hash(%r,32)
    if (!$hget(%h,%l)) {
      hadd -m %h %l 1
      %ok = 1
    }
    if ($hget(%h,0).item == $lines($1)) hfree %h
    if (%ok) returnex %r
  }
}
and just use $randomline(file,<clear|tn>) if you pass clear as the second parameters, it will clear the table and forget the lines already read, to start again. This process is done automatically if it detects that you read all the lines, (this might not work if you edit the file without clearing the table), otherwise you can use this parameter to pass the 't' or 'n' switch to the $read call, which is recommended.

Last edited by Wims; 09/05/15 08:29 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: May 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: May 2015
Posts: 5
Ok thanks a ton for that alias model. I understand most of what's going on besides some of the syntax of how its actually happening.

However i still do have a question. Using this with my current code i get a message insufficient parameters error. From what i gather from the code this should return the line that I would then want to display in chat.

my code that actually calls the alias is such:

on: me:*:join:#:{
.timerfacts 0 $rand(240,300) msg $chan $randomline(facts.txt,n)
}

i think where it is failing is that i am not calling alias properly with (facts.txt,n) < -- the "n" here or "tn" / clear parameter as you described it. what am i supposed to pass in here? Sorry if this is a dumb question. I only really knew to use (facts.txt,n) in my first bit of code from some googling but didnt understand why the "n" part was necessary.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Well i tried the code and it worked for me, you are calling it correctly, the second parameter is either 'clear' to indicate you want to clear or it's the optional parameter passed to $read, like 't' or 'n'. Do you get any error ? Do you have empty lines in the file ? I can't try it at the moment..

Last edited by Wims; 10/05/15 11:25 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: May 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: May 2015
Posts: 5
Whenever I try to run it with the alias that you provided and the call that I showed above it gives a "/msg: insufficient parameters" error which makes me believe that the alias is not returning a value otherwise it would print that return value. As to why its not working for me, i have no idea.

EDIT: I also have no blank lines in the textfile.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
I tested it again, it works.
Which version of mIRC are you using?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: May 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: May 2015
Posts: 5
7.41 it says its all upto date

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
What is the content of the file you are trying this with?
If you create a new, simple file, in your $mircdir like 'test_random.txt' and you put 4 lines like A B C and D, does it work? Eventually you can join the channel in my signature because it should work and if it doesn't it could be almost anything, solving this over a forum is difficult.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: May 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: May 2015
Posts: 5
I understand the difficulty of trying to solve these things over a forum, and all of your help is greatly appreciated. It still however gives me a /msg insufficient parameters error if i run it with a new text file just containing ABCDE on different lines. I think ill just tinker around with the code and try to solve it myself (maybe in the not most efficient way) but it will be more rewarding and will help me learn the mIRC language better. Again thanks for all your help.


Link Copied to Clipboard