Capturing Lines and printing them to a file

Posted by Dpw3868 on Fri 11 Dec 2009 10:14 PM — 5 posts, 21,720 views.

#0
I want to be able to capture information from the mud and print it to a text file. I know that Mushclient has this ability built in, but i want to be able to send certain lines to different files ect.

Once i understand how this is done i think i can work on making all the other ones I need/want.

To do this will I need to trigger off the text and pass the line to a script? I am guessing lua has some built in input/output functions i will need to open a file and write to it?

The pattern is

Joe tells you 'hello'

Trigger --> * tells you '*'

I want to capture this line to a file called tells.txt
and i do not want to omit it from the output to the screen.

Thanks in advanced

Australia Forum Administrator #1
Have you looked at logging? Or "send to notepad"?

You just make a trigger, send the matching text to "notepad" and one or more notepad windows can be written (you have to save them yourself).

Or, using logging, it is saved on-the-fly.

Or if you want to script the whole thing, see:

http://www.gammon.com.au/scripts/doc.php?lua=io.output

You could use f:write to write data on a matching trigger, making sure you open the file at some point.
#2
Okay, so i started to work on this and i set something up that will log chat (says,tells,group tells, clan tells, shouts, ect.) to a notepad.

I also made another trigger that outputs gear worn by characters and mobs, as well as gear i have that decays into another notepad.

Finally I created a notepad that receives group information. If someone gets effected by something in a fight and gets lost in spam ect its output the the notepad.

I than made a script to resize all the windows, it worked.

The problem is my output to the notepads was not adding a new line.

This is what the trigger and code looks like for one example.

Trigger : <(@!gear_slot)>\s+(.+) -- matches a gear slot and whats worn i have a variable gear_slot with all the gear slots listed

Script:
AppendToNotepad("Gear_stuff","<","%1",">","\\t","%2","\\n")

This however does not print a newline.

When trying to resolve this I noticed some people use dummy worlds to receive output. I tried this and it takes care of the newline issue. However i am at a loss on how to resize multiple world windows in lua scripting.

Thanks
Dan
Australia Forum Administrator #3
Notepad windows need \r\n to make a new line (or in send-to-script it would be \\r\\n).
#4
Thank you Nick.

Worked perfectly, now I don't need to worry about resizing and moving multiple worlds.

-Dan