Minor help with a bot script. reddit / irc ---------------------------------------------------------------------- Frtipachi · 2014-10-27 08:51 Hey all, I'm fairly new to irc and have been tinkering with a bot to run in a channel I run(not a moderation bot, just a goofy 'for fun' bot). I've been successful in setting up basic notifications and 'on *:TEXT:!' remote commands , but have run into a small road block in my most recent addition. I am trying to make a timer function that displays a random message from a list of pre-selected items every 300 secs or so. I am using a :JOIN: and /timer function, but can't seem to figure out where the problem lies in my code between the timer starting on joining a channel and the random timed messages not displaying. Here is the code I am using, any help would be greatly appreciated. on *:JOIN:#:{ /timer 0 300 /var %r = $rand(1,50) if (%r == 1) msg $chan Sample text 1 . if (%r == 2) msg $chan Sample text 2 . etc...... if (%r == 50) msg $chan Sample text 50 . } Thank you very much in advance for any insight you can give this newbie. **EDIT**: Got it to work as desired! Thanks for all the help here. <3 ---------------------------------------------------------------------- tavaryn · 2014-10-27 13:26 The mIRC ON JOIN event triggers when *anyone* joins. Try changing the first line to "ON ME:JOIN:#:{". Edit: Also, you can put all 50 lines of text in a txt file, generate your random number and read it in one line. Edit 2: Just went ahead and wrote the whole thing out. Hope this works, I'm on my phone so I can't test it right this second. on ME:JOIN:#channel:{ timer 0 300 $read(file.txt, n, $rand(1,50)). } ---------------------------------------------------------------------- [deleted] · 2014-10-27 13:42 [deleted] ---------------------------------------------------------------------- iNeo19 · 2014-10-27 13:43 on ME:JOIN:#channel:{ This part only gets triggered when you join (the client) joins the channel. Change ME to * and it will trigger for everyone joining the channel. on *:JOIN:#channel:{ ---------------------------------------------------------------------- tavaryn · 2014-10-27 14:30 Yeah, that was in his original script. But he wants it to start when his bot joins the channel, not on every single join. ---------------------------------------------------------------------- phate408 · 2014-10-27 16:30 It's been a while since I've used mSL, but shouldn't that be: timer 0 300 msg $chan $read(file.txt, n, $rand(1,50)) Though, I'm also not sure about when the statement will be evaluated. It's possible that will pick a random message, and then use that same message for each loop of the timer. I could very well be misremembering, but if I am, I'd suggest making an alias and calling that each time. So, if that ends up using the same message each time, try: on ME:JOIN:#channel:{ timer 0 300 /randmessage $chan } alias randmessage { msg $1 $read(file.txt, n, $rand(1,50)) } Again, it's been a while, this may be slightly to entirely flawed. ---------------------------------------------------------------------- tavaryn · 2014-10-27 16:36 You're right on both counts. Admittedly I switched to HexChat quite some time ago. :) ---------------------------------------------------------------------- Frtipachi · 2014-10-27 20:18 Thanks, this helped a lot but I still have one final question. I made a txt flie and added the 50 lines to it, but how do I get mIRC to acknowledge the existence of said file. I looked around and can't seem to find out how to import the txt file into some sort of resource bank for it to reference. I discovered the /write command as well. I tried using this command to manually 'write' in each line, but it doesn't seem to be working. Any knowledge you can shed on me about this? EDIT: Nvm, I figured it out!!! God coding can be so stressful, but when you finally reach the finish it's so satisfying! My rage has subsided until my next endeavor. Once again thanks for all the help ---------------------------------------------------------------------- phate408 · 2014-10-27 21:27 Haha, that's a very accurate statement about coding. Congrats on getting it working and now that I'm home and have access to the mIRC docs, I can make another suggestion if you didn't discover it already. If you want to make your random messages easily modifiable through bot commands, it'll make your life easier to use $read(file.txt, n, $rand(1,$lines(file.txt)) as that will determine the number of lines available in the file for you and will adjust as the file changes. ---------------------------------------------------------------------- Frtipachi · 2014-10-28 01:31 Ah I see, this way if I add anything to it I won't have to go back and change the 1-X part. That's a good note.