Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Mass gag and redirect into a miniwindow, using Lua

Mass gag and redirect into a miniwindow, using Lua

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by BBAlpha   (10 posts)  Bio
Date Mon 04 Jan 2010 06:51 AM (UTC)
Message
After a long hiatus from MUDs, I'm diving into Lua coming from VBScript/JScript.

I have two triggers which frame a block of incoming text that I would like to capture, gag, and then display in a miniwindow while retaining style. I've created the miniwindow. I have the triggers firing quite nicely. From here, I get somewhat lost as to how to proceed.

I've done this sort of mass text collection before (minus the miniwindow part), and I know from past experience that I'd have performance issues on this ancient PC I'm using that prevent it from working reliably. I suspect my approach is just clunky.

It seems like I should have three triggers. On my first trigger, I should be enabling a catchall trigger (^.*$) which calls a function in my Lua script file. That function would build the block of text to be output to the miniwindow, the block of text being stored back into a MUSHclient variable in between calls. The ending trigger would disable the catchall trigger and paint the miniwindow.

Speed is an issue, however, and I'd like to ensure that I'm going about this in the most resource-friendly way. Anyone have recommendations or advice to share?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 04 Jan 2010 06:53 AM (UTC)
Message
First, did you see this?

Template:post=9965 Please see the forum thread: http://gammon.com.au/forum/?id=9965.


That shows gagging a bunch of lines (inventory in this case) and redirecting to a miniwindow. I see no particular reason why something designed along similar lines should be particularly slow.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #2 on Mon 04 Jan 2010 07:00 AM (UTC)

Amended on Mon 04 Jan 2010 07:02 AM (UTC) by Twisol

Message
The three-stage process you described is actually quite common, and has no real speed issues as far as I know.

If you have the data-collecting bit done, and you have the miniwindow itself, it seems to me that you'd simply need to draw to the miniwindow on trigger #3, the ending trigger. I wrote a MapWindow plugin that works basically how you describe, that was designed to work for Achaea. You can find it at my website [1], but be warned that there's a lot of disorder on those pages - it's a bit like Aladdin's Cave of Wonders, don't touch anything but the lamp!

EDIT: Well, I sure lol'd. I completely forgot that MUSHclient's icon actually IS a lamp. *laughs*

[1] http://www.jonathan.com/achaea/plugins

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by BBAlpha   (10 posts)  Bio
Date Reply #3 on Mon 04 Jan 2010 07:48 PM (UTC)
Message
Thank you both. I'm actually trying to piece together what Twisol's plugin accomplishes, though I didn't realize someone had published a map window plugin for IRE games. Using Nick's video tutorial, I've got mine working more or less how I originally imagined it. Very smooth, clean and elegant. I like.

Only now, I see Twisol's ATCP plugin and the benefit it brings to his mapwindow plugin (map update regardless of method of travel), and I need figure out how to steal or duplicate that for myself. =P
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #4 on Mon 04 Jan 2010 07:59 PM (UTC)
Message
Heheh. If you're playing an IRE game (particularly Achaea; I don't know how well the ATCP plugin works for others), feel free to use the ATCP plugin yourself, and base your plugins off it. That's what it's for!

If not, though, you're in a bit of a bind. The ATCP plugin works so well because the server itself sends bits of tagged data, which the plugin picks up on. Aardwolf also provides a similar tagging mechanism, which I believe many of Nick's plugins take advantage of. So if your MUD isn't conducive to that sort of approach - a "push" methodology instead of "pulls" by queries - an ATCP-esque plugin won't be very easy to write.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by BBAlpha   (10 posts)  Bio
Date Reply #5 on Sat 30 Jan 2010 10:17 AM (UTC)
Message
So, I'm revisiting this map window thing I was working on. It works and works well. But I'm not savvy enough with what's going on to figure out what I need to do to make the change I'm after.

<triggers>
<trigger
enabled="y"
match="^\-\-\-.+? v\d+ \-\-\-+$"
name="MapWindow"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>require "wait"

wait.make (function ()

local win = "MapWindow"
local font = "body"
local map = {}

if not WindowInfo (win, 1) then
WindowCreate (win, 670, 0, 380, 400, 6, 2, ColourNameToRGB("black"))
WindowFont (win, font, "Courier New", 10)
end

while true do
local line, wildcards, styles = wait.regexp ("^(.*)$", 0, trigger_flag.OmitFromOutput)

if string.match (line, "^(-)(-)(-)") then
break
end

table.insert (map, styles)
end

local font_height = WindowFontInfo (win, font, 1)

WindowCreate (win, 670, 0, 380, 400, 6, 2, ColourNameToRGB "black")

local y = font_height * 2

for i, styles in ipairs (map) do
local x = 0
for _, style in ipairs (styles) do
x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
end
y = y + font_height
end

WindowShow (win, true)

end)</send>
</trigger>
</triggers>

This is what I came away with after watching Nick's tutorial. Right or wrong, it works.

Two things I'd like to know how to do:

First, I'd like to have the lines being matched on at start and end to also show up in the miniwindow, retaining style. Right now they don't show up in either the main window or the miniwindow.

Second, for a related map (aetherspace in Lusternia), I would like to capture background color as well as the font style.

The first one seems a minor matter of dealing with code that I'm just not familiar enough with. My best guess with the second one is that styles doesn't carry background color information, and I'll have to draw in the colors manually. I'm hoping I'm wrong about that.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Sat 30 Jan 2010 07:06 PM (UTC)

Amended on Sat 30 Jan 2010 07:34 PM (UTC) by Nick Gammon

Message
For the first and last line, you need to do two things. For the first line, this is the one the trigger matched, which you are omitting. Change the "send to" box from "script" to "script (after omit)". This makes MUSHclient create an extra global variable "TriggerStyleRuns" which contain the matching line's style runs.

So, basically the first few lines can change from:


local win = "MapWindow"
local font = "body"
local map = {}


to:


local win = "MapWindow"
local font = "body"
local map = {}
table.insert (map, TriggerStyleRuns)


That gives you the first line. For the last line, change the order around:


if string.match (line, "^(-)(-)(-)") then
  break
end

table.insert (map, styles)


becomes:


table.insert (map, styles)

if string.match (line, "^(-)(-)(-)") then
  break
end


Now you have saved the last line *before* you exit the loop.

As for the background colours, the styles have those, you just have to draw rectangles the right size. This illustrates the technique:


local top = font_height * 2

for i, styles in ipairs (map) do
  local left = 0
  for _, style in ipairs (styles) do
    local width = WindowTextWidth (win, font, style.text) -- get width of text
    local right = left + width
    local bottom = top + font_height
    WindowRectOp (win, 2, left, top, right, bottom, style.backcolour)  -- draw background
    WindowText (win, font, style.text, left, top, right, bottom, style.textcolour)  -- draw text
    left = left + width  -- advance horizontally
  end -- for each style run        
  top = top + font_height  -- advance vertically
end  -- for each line




- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by BBAlpha   (10 posts)  Bio
Date Reply #7 on Sun 31 Jan 2010 11:06 AM (UTC)
Message
Perfect, my map works as well as I can hope for now. I'll still need to scratch around with the ATCP for that one last benefit, but it's currently working exactly as I'd imagined it.

As for the background color, that's for something I'll be working on in the near future. But it seems like it should work by plugging that in, more or less, to my existing map trigger and editing the trigger lines.

Thank you!
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.


29,349 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.