mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2007
Posts: 5
G
Gwydion Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Jan 2007
Posts: 5
Not knowing much of scripting I wonder if there is a way to let a .txt file be put out line by line instead of random.
This can be useful for e.g. quit or join messages or if you have a on join message (when the different messages are saved in a txt file).
I so far only know that it is done randomly - can it be done in another way? I think it's difficult but maybe by reading the first line and then deleting it from the file? So next time, line 2 would be on top etc. ..

Joined: Jul 2006
Posts: 242
H
Fjord artisan
Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
from the help file

//echo $read(funny.txt, 24)
Reads line 24 from the file funny.txt


Newbie
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If you want the entire file put out (displayed), then use the /play command
/play <channel/nick> <file>

If you only want sections displayed, then the /play command is still a good option, but you'll need to look in the help file to decide which switches you want/need.

/help /play

Joined: Jun 2003
Posts: 994
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Jun 2003
Posts: 994
I use this for changing the topic in a channel (234 is the number of lines in the text file):

Code:
rtopic {
  if (%lasttopic < 0) || (%lasttopic > 234) { %lasttopic = 1 }
  topic $chan $read(topicfile.txt, %lasttopic)
  inc %lasttopic
}


increments the line by one each time it's used until it reaches the last line, then resets and reads the top line next time.

Last edited by CtrlAltDel; 01/01/07 09:41 PM.

I refuse to engage in a battle of wits with an unarmed person. wink
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Well neccesarly if you use the on JOIN msg example you don't have too delete the lines from file I would just increment the value if you want to go down in list. example...
Code:
On *:JOIN:#:{
if (!%xup) { msg $nick $read(file.txt,1) | %xup = 2 }
else { 
if (%xup <= $lines(file.txt)) { msg $nick $read(file.txt,%xup) | inc %xup }
}
}


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Oct 2004
Posts: 14
C
Pikka bird
Offline
Pikka bird
C
Joined: Oct 2004
Posts: 14
off the top of my head this would read the entire file in order
Code:
var %file <yourfilehere>
var %lines $lines( %file )
var %i 1
while ( %i <= %lines ) {
  echo -a $read( %file ,n, %i )
  inc %i 1
}


unless you wanted every iteration in a new commmand

Code:
set %file <yourfilehere>
set %lines $lines(%file)
set %i 1
if ( %i > %lines ) { %i = 1 }
echo -a $read( %file ,n, %i )
inc %i 1


everytime the code is executed it will read the next line. Once it reaches the end of the file, it starts over. If you doin't want it to start over, remove the "if" line

or this would work for your case

Code:
$read(<yourfile>,n, $lines(<yourfile>) )

reads the last line of the file, which would be the last line written with the write command if no switches are used.

Last edited by CakerX; 02/01/07 12:49 PM.
Joined: Jan 2007
Posts: 5
G
Gwydion Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Jan 2007
Posts: 5
Thanks .. confusing but promising. .)
However, I think there is another problem with my plan .. I thought about doing custom greetings (inistead of the automatised by e.g. UPP which are random) but for that I have to identify the nick and read out the txt file for each nick.
I thought I could do something like e.g.

if Bob joins chan #home
then msg #home
joinBob.txt <hello bob - textline1>

and next time nickA joins again it would be "hello bob - textline2" etc.
Simply put.

However, I have seen in the help that you apparently can not set on join for a certain nick but only for either all or the level ..
Seems to be more complicated than I thought.

Nevertheless knowinig how to read out a txt file line by line will certainly come handy some time, so thank you all. smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Yes, you can set on JOIN for specific nicks. You just have to do the check inside the on JOIN.

Code:
on *:JOIN:#yourchannel: {
  if ($nick == Nick1) { msg $nick This is your on join message }
  elseif ($nick == Nick2) { msg $nick This is another on join message }
}

..etc.

Or, if you want to have the messages in a text file, it would be better (shorter) to do this:

Code:
on *:JOIN:#yourchannel: {
  if ($read(joinmessages.txt,s,$nick -)) {
    msg $nick $v1
  }
}


Then, in your joinmessages.txt file, you would put:

Riamus - This is my on join message.
Gwydion - This is your on join message.

..etc.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard