mIRC Homepage
Posted By: AaronL Read 1file or another depending on nick added - 13/12/05 03:24 PM
Hi all
I hope i can make my problem clear. here goes.
I have a bot that checks a command like !beer
When someone type that without a nickname the bor reads file a, but is a nick is added like !beer pino it should read fil b
this is what i got sofar, but it does'nt work.

Code:
 
on *:text:!beer*:#:{ set %beernick $$2
 if (%beernick == '') {
 set %beer $read(drinks.txt, s, $$1
| /msg $chan %beer  
halt } 
 set %beer $read(beernick.txt, s, $$1 }
 


help is appriciated.
Aaron
Using $$2 means use $2 if it is there, else stop the script completely. You don't want this here. You don't want this often.

mIRC does not recognize ' or " as a string delimiter in most cases (only some file and window commands have their own parsing for that.)

Don't halt unless you really need to, the most common (and thus best) way to have a script stop is by having it reach the end of the script, in other words the last }

/set is not needed if don't need the %variable after the script ends.

You didn't close the ) in the $read() call. I'm also not sure why you want to search either file for the word !beer since that is $1. I suppose you just want a random line out of that either text file. Please let us know if the text file really has lines with nicks already filled in or if you want to include either the given or the requester's nickname in the line somewhere.

Here's a changed simple version
Code:
on *:text:!beer*:#:{
  if ($2 == $null) { 
    msg $chan $read(drinks.txt)
  }
  else {
    msg $chan $read(beernick.txt)
  }
}


Maybe search this forum for other scripts like this, such scripts can get much more complex for all kinds of situations. Make sure you set the date range to 5 years.
Hi Kelder.
Well problem is that it should'nt read a random line, but a line that starts with !beer and then shows de rest of the text on that line. In the txtfile i have the $nick etc..
With the ,s,$1 i tell the script it should search for !beer and then shows whats after !beer. according the helpfile i should write it down like $read(drinks, s, !beer) since $1 == !beer that should work. in fact that works fine, but... i have 2 txtfiles, one if no nick is used and one when is.

thnxs for the fast replay, but the short code you gave me did'nt do the job. Instead i get the error msg: insufficient parameters..

Aaron
Try this:
Code:
on *:text:!beer*:#: msg # $$read($iif($2,beernick.txt,drinks.txt),s,!beer)
thnxs qwert, for the fast and good solution
works fine now.

Aaron
© mIRC Discussion Forums