[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Capturing Multiline Data

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Capturing Multiline Data
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 23 Jun 2009 07:54 PM (UTC)  quote  ]
Message
Haha, yeah, I was just joking, I'll probably do ~30 seconds (its not terribly vital).
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 23 Jun 2009 08:00 AM (UTC)  quote  ]
Message
/cry for the MUD admins, if everyone does a "who" every second.

Also, you would complain if there is lag, yes?

Maybe check the who list every 10 seconds or so. :-)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 23 Jun 2009 07:54 AM (UTC)  quote  ]

Amended on Tue 23 Jun 2009 07:55 AM (UTC) by LupusFatalis

Message
Beautiful, got it working well. Needs a tiny bit of minor tweaking. I guess this means the mud will now have to put up with my 1 second who-list updates now. lol. I'd post it here, but its a bit long. So I'll just post the script bit. Anyone wanting to use it can easily piece together the rest from this thread.
winTMargin = 3			#Top Window Margin
winLMargin = 3			#Left Window Margin
yPos = 0				#Window Y Coordinate
xPos = 0				#Window X Coordinate
winHeight = 300			#Default Window Height
winWidth = 200			#Window Width
winColor = 0xFF0000		#Window Color
fontName = 'Dina'		#Font
fontHeight = 16			#Font Height
fontWidth = 8			#Font Width

#Char, Foreground, Bold
WhoList = [[],[],[]]

win = world.GetPluginID

def OnPluginConnect():
	world.EnablePlugin (world.GetPluginID, 0)
	
def OnPluginDisconnect():
	world.WindowShow (win, 0)

def OnPluginClose():
	world.WindowShow (win, 0)

def OnPluginDisable():
	world.WindowShow (win, 0)

def OnPluginEnable():
	world.WindowCreate (win, xPos, yPos, winWidth, winHeight, 7, 0, winColor)
	world.WindowShow (win, 1)

def ParseWhoList(TriggerName, trig_line, wildcards):
	#sFlag = wildcards[1]
	sID = wildcards[3].rstrip()
	xLine = world.GetLinesInBufferCount		#Line Number
	xStyle = world.GetLineInfo(xLine, 11)	#Number of Styles
	if xStyle == 1: xStyle = 2
	
	WhoList[0].append(sID)
	WhoList[1].append(world.GetStyleInfo(xLine, xStyle-1, 14))

	if world.GetStyleInfo(xLine, xStyle-1, 8):
		WhoList[2].append('1')
	else:
		WhoList[2].append('0')

def DisplayWho():
	
	world.WindowFont (win, 'body', fontName, 10, 0, 0, 0, 0, 1, 0)
	world.WindowFont (win, 'title', fontName, 10, 1, 0, 0, 0, 1, 0)
	winHeight = fontHeight * len(WhoList[0]) + 2 * winTMargin
	
	world.WindowCreate (win, xPos, yPos, winWidth, winHeight, 7, 0, winColor)
	world.WindowRectOp(win, 2, 2, 2, winWidth-2, winHeight-2, 0x000000, 0x000000)

	for i in range(0, len(WhoList[0])):	
		localTMargin = winTMargin + i * fontHeight	
		if WhoList[2][i] == '1':
			world.WindowText (win, 'title', str(WhoList[0][i]), winLMargin, localTMargin, 0, 0, WhoList[1][i], 1)
		else:
			world.WindowText (win, 'body', str(WhoList[0][i]), winLMargin, localTMargin, 0, 0, WhoList[1][i], 1)

	world.WindowShow (win, 1)


def CleanUp():
	for i in range(0, len(WhoList[0])):
		WhoList[0].pop(0)
	for i in range(0, len(WhoList[1])):
		WhoList[1].pop(0)
	for i in range(0, len(WhoList[2])):
		WhoList[2].pop(0)
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 22 Jun 2009 08:02 AM (UTC)  quote  ]
Message
Yes, that sounds right. See:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6554

You can work around that by doing "send to script" rather than calling a script function. The sequence is:


  • Do "send to" actions (including send to script)
  • Omit from output if requested
  • Do "send to script (after omit) scripts (in the send box)
  • Call scripts in the script file


Thus, doing what were doing in "send to script" will work (even if omitting) but not when you call the function in the script file.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Mon 22 Jun 2009 07:21 AM (UTC)  quote  ]
Message
Well, whenever I have it omit, the miniwindow I have now displays nothing. I think it has to do with the fact I'm trying to get a line that isn't actually drawn in the main window. Is that the case?
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 22 Jun 2009 06:10 AM (UTC)  quote  ]
Message
Quote:

Except when I omit the line with the data it screws everything up.


Can you be more specific? In what way?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Mon 22 Jun 2009 12:21 AM (UTC)  quote  ]

Amended on Mon 22 Jun 2009 07:26 AM (UTC) by LupusFatalis

Message
Alright guys, I've got it mostly working. Except when I omit the line with the data it screws everything up. The idea is to eventually have the alias triggered on a timer and completely stripped from my screen (aside from the miniwindow).

The trigger in question is here:
  <trigger
   enabled="n"
   group="WhoList"
   keep_evaluating="y"
   match="^(\s+)([\/\|][BH]|[DG]|[DK]|[HG]|[MG]|[SR])?(\s+)([A-Za-z\s]+) ([0-9mhs\s]+)?$"
   omit_from_output="n"
   regexp="y"
   send_to="12"
   script="ParseWhoList"
   sequence="100"
  >
  </trigger>

And here is the scripting portion:
winTMargin = 1			#Top Window Margin
winLMargin = 1			#Left Window Margin
yPos = 0				#Window Y Coordinate
xPos = 0				#Window X Coordinate
winHeight = 300			#Default Window Height
winWidth = 250			#Window Width
winColor = 0x000000		#Window Color
fontName = 'Dina'		#Font
fontHeight = 16			#Font Height

#Char, Foreground, Background, Bold, Line
WhoList = [[],[],[],[],[]]

win = world.GetPluginID

def OnPluginConnect():
	world.EnablePlugin (world.GetPluginID, 0)
	
def OnPluginDisconnect():
	world.WindowShow (win, 0)

def OnPluginClose():
	world.WindowShow (win, 0)

def OnPluginDisable():
	world.WindowShow (win, 0)

def OnPluginEnable():
	world.WindowCreate (win, xPos, yPos, winWidth, winHeight, 7, 0, winColor)
	world.WindowShow (win, 1)

def ParseWhoList(TriggerName, trig_line, wildcards):
	sFlag = wildcards[1]
	sID = wildcards[3].rstrip()
	sCompiled = sFlag.rjust(6) + ' ' + sID
	xLine = world.GetLinesInBufferCount		#Line Number
	xStyle = world.GetLineInfo(xLine, 11)	#Number of Styles

	#world.Note(sCompiled + ', ' + str(xStyle))
	
	for i in range(0, xStyle):
		xStyleLen = world.GetStyleInfo(xLine, i+1, 2)	#Length of Style
			
		WhoList[0].append(sCompiled[0:xStyleLen])
		sCompiled = sCompiled[xStyleLen:len(sCompiled)]
		
		WhoList[1].append(world.GetStyleInfo(xLine, i+1, 14))
		WhoList[2].append(world.GetStyleInfo(xLine, i+1, 15))
		
		if world.GetStyleInfo(xLine, i+1, 8):
			WhoList[3].append('1')
		else:
			WhoList[3].append('0')
		
		WhoList[4].append(str(xLine))


def DisplayWho():
	#for i in range(0, len(WhoList[0])):
	#	world.Note(str(WhoList[0][i]) + ', ' + str(WhoList[1][i]) + 
	#', ' +str(WhoList[2][i]) + ', ' +str(WhoList[3][i]) + ', ' + str(WhoList[4][i]))

	world.WindowFont (win, 'body', fontName, 10, 0, 0, 0, 0, 1, 0)
	world.WindowFont (win, 'title', fontName, 10, 1, 0, 0, 0, 1, 0)
	
	xLineLast = WhoList[4][0]
	xLineCount = 1
	
	for i in range(0, len(WhoList[4])):
		if not WhoList[4][i] == xLineLast:
			xLineCount = xLineCount + 1
			xLineLast = WhoList[4][i]
	
	winHeight = fontHeight * xLineCount + 3
	
	world.WindowCreate (win, xPos, yPos, winWidth, winHeight, 7, 0, winColor)
	localTMargin = winTMargin
	
	xLineLast = WhoList[4][0]
	xChars = 0
	for i in range(0, len(WhoList[0])):
		if not WhoList[4][i] == xLineLast:
			localTMargin = localTMargin + fontHeight
			xLineLast = WhoList[4][i]
			xChars = 0
		if WhoList[3][i] == '1':
			world.WindowText (win, 'title', str(WhoList[0][i]), winLMargin + (xChars + 1) * 8, localTMargin, 0, 0, WhoList[1][i], 1)
			xChars = xChars + len(str(WhoList[0][i]))
		else:
			world.WindowText (win, 'body', str(WhoList[0][i]), winLMargin + (xChars + 1) * 8, localTMargin, 0, 0, WhoList[1][i], 1)
			xChars = xChars + len(str(WhoList[0][i]))
		
	world.WindowShow (win, 1)


def CleanUp():
	for i in range(0, len(WhoList[0])):
		WhoList[0].pop(0)
	for i in range(0, len(WhoList[1])):
		WhoList[1].pop(0)
	for i in range(0, len(WhoList[2])):
		WhoList[2].pop(0)
	for i in range(0, len(WhoList[3])):
		WhoList[3].pop(0)
	for i in range(0, len(WhoList[4])):
		WhoList[4].pop(0)
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 18 Jun 2009 10:10 PM (UTC)  quote  ]
Message
Quote:

Theoretically each character could be a different color.


It is easier in Lua, because triggers get a fourth argument, which is the style runs for the matching line, which includes colour information.

In other languages, you can obtain the style runs using GetStyleInfo. The line number (if it is the last line) can be obtained from GetLinesInBufferCount, and the number of styles from GetLineInfo.

http://www.gammon.com.au/scripts/doc.php?function=GetStyleInfo

http://www.gammon.com.au/scripts/doc.php?function=GetLinesInBufferCount

http://www.gammon.com.au/scripts/doc.php?function=GetLineInfo

I agree with Hoax that three or so triggers are required - one to detect the start of the who list, one to detect the end, and one for the stuff in the middle.

Personally I wouldn't add or remove triggers all the time, simply enable and disable existing ones - that is easier to do.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Mm1mark   (23 posts)  [Biography] bio
Date Thu 18 Jun 2009 12:30 AM (UTC)  quote  ]
Message
you forgot RoE..just thought i'd point that out
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Wed 17 Jun 2009 09:05 PM (UTC)  quote  ]

Amended on Wed 17 Jun 2009 09:38 PM (UTC) by LupusFatalis

Message
Ok, I got the triggers and alias working, very clever. But I'm not sure what that script does... and the lines themselves are not all one color. Theoretically each character could be a different color. That isn't the case, usually the flags [HG] etc... are two colors, the name is one color, and the idle times are another. Not sure how the packets are sent. Is there some function I can call on to get the color, background color, and style of individual characters?

I work in python, so I'm also not sure how to modify the escape characters and such to work with Lua and all that, which I'll have to do for the trigger, but that's pretty minor, compared to the color portion.
[Go to top] top

Posted by Hoax   (14 posts)  [Biography] bio
Date Wed 17 Jun 2009 04:07 AM (UTC)  quote  ]
Message
I suppose you will call a script function with the trigger you created. Let say the trigger will call wholist function. In LUA:

function wholist(name,line,wc,styles)
for _, v in ipairs (styles) do
ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), v.text)
end --for
Note("")
end --function wholist

As for your second wish, I here grant you a solution. Create an alias who, which call a trigger. In that trigger, create another trigger with AddTrigger/AddTriggerEx, which capture anything and call a function. In the function, you will want to filter the output, capturing only what you want to capture (i.e. You may not want to capture the title/header, that is the line with 'name' and 'idle time'. And when the line captured by the trigger is "There are roughly * player* on", then you delete the trigger, to stop it triggering anything after that line, obviously.

Best of luck!
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 16 Jun 2009 10:37 PM (UTC)  quote  ]
Message
Ok, so here's the deal, I'd like to write a trigger that does a few things. I want to capture the 'who list' and output it to a miniwindow. Firstly... the who list may have different colors, and ideally I'd like to capture them as well. Now I wrote a trigger that would work on any of the players on the who list, but I have no idea how to capture colors, etc... Here is some sample output (minus the color)
       Name                                     Idle Time
       a blind seer                             12s
       a calm filly                             58s
       a determined swordsman                   32s
       a magical crafter                        30s
       Alissa the human                         48s
       an ebon charlatan                        12s
       Auril the human                          4s
  [HG] Donovan the troll                        
  [SR] Rhyandra the human                       24s
       Telthor the catfolk                      12s
  There are roughly 17 people on.  Only 11 of them are friendly, though.
    Estimated active characters: 180 this month, 70 today.
  Ferdarchi was last renewed 5 days 15 hours 6 minutes 24 seconds ago.
Here is my trigger:
<triggers>
  <trigger
   match="^(\s+)([\/\|\]|[BH]|[DG]|[DK]|[HG]|[MG]|[SR])?(\s+)?([A-Za-z\s]+)(\s)([0-9mhs\s]+)?$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Triggered</send>
  </trigger>
</triggers>


I'd also like to somehow include the first and last lines to ensure that this triggers only on the who list.

[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


2,499 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]