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 ➜ Miniwindows ➜ Group info miniwindow

Group info miniwindow

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


Posted by Uberelf   (2 posts)  Bio
Date Mon 23 Mar 2020 08:18 PM (UTC)

Amended on Tue 24 Mar 2020 04:43 AM (UTC) by Nick Gammon

Message
Hi. I've attempted to adjust Nick's inventory window (http://www.gammon.com.au/forum/?id=9965) to work with group data so I can permanently monitor group stats. I've had trouble gathering the group info though. Here is the raw data i'd like to capture:


-------------------------------------------------------------------------------
##| Level   Name         Pos   HitPoints   ManaPoints  MovePoints  TNL    Align
-------------------------------------------------------------------------------
 1|383 Lord September    Sleep 54202/54202 1141/1141   18481/18481 499    1000
 2|999 Lord Someone      Sleep 23635/23635 31040/31040 32480/32960 713    1000
 3|999 Lord Alrin        Sleep 29012/29012 70599/70599 30760/30760 1247   1000
 4| 66 Lord Notea        Sleep 5963/5963   24261/34420 6660/6660   554   -1000
 5| 26 Lord Eiri         Stand 3503/3503   30864/30864 6303/6303   1463   1000
 6|132 Lord Urecht       Sleep 15731/15731 11499/11499 18711/18711 465    1000
 7| 98 Lord Djat         Sleep 19521/19521 2867/2867   7057/7057   1335   1000
 8|441 Lord Sith         Stand 16303/16303 21690/21690 10961/10961 1238   -999
 9|999 Lord Mundegaarde  Sleep 14186/14186 35494/35494 13340/13340 544    1000
10|202 Lord Meista       Sleep 11450/11450 21297/21297 9216/9246   489    1000
11|416 Lord Victim       Sleep 13654/13654 26003/26003 6744/6744   1018   -999 



Here is the alias i set up in an attempt to capture it:


require "wait"

wait.make (function ()  -- coroutine starts here


local win = GetPluginID () .. ":group"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if

-- request group

Send "group"


-- wait for group to start

local x = wait.match ("*|*", 10)

if not x then
  ColourNote ("white", "blue", "No group received within 10 seconds")
  return
end -- if

local grp = {}
local max_width = WindowTextWidth (win, font, "Group")

-- loop until end of inventory

while true do
  local line, wildcards, styles = wait.match ("*|*")

  -- see if end of inventory

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

  -- save group line
  table.insert (grp, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))

end -- while loop


local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#grp + 2) + 10

-- make window correct size

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Group", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

for i, styles in ipairs (grp) do

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

end -- for each inventory item

WindowShow (win, true)


end)   -- end of coroutine



I'm sure i have more than one problem. I can't find a good way to end the loop. And it doesn't seem to be capturing the lines I've asked it to.
THanks for any help you can give.
Top

Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 24 Mar 2020 05:11 AM (UTC)
Message
First:


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


This is a Lua pattern, not a wildcard, so it won't work. You want:


  if not string.match (line, "^[ 0-9][0-9]") then
    break
  end -- if


That will match on a digit or a space, followed by a digit (which is what your test data was).

Second:

You didn't skip the line with the hyphens.

Third, you didn't have a timeout on your next wait:


  local line, wildcards, styles = wait.match ("*|*")


So that will wait indefinitely for a match on *|*.

So you probably want to just wait for "*" which will be anything, including not the group.

This modified alias worked, but you may want to improve the formatting of the output:


<aliases>
  <alias
   match="test"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

wait.make (function ()  -- coroutine starts here


local win = GetPluginID () .. ":group"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if

-- request group

Send "group"


-- wait for group to start

x = wait.match ("*|*", 10)

if not x then
  ColourNote ("white", "blue", "No group received within 10 seconds")
  return
end -- if

-- skip the hyphens

x = wait.match ("-----*", 10)
if not x then
  ColourNote ("white", "blue", "No hyphens received within 10 seconds")
  return
end -- if

local grp = {}
local max_width = WindowTextWidth (win, font, "Group")

-- loop until end of inventory

while true do

  line, wildcards, styles = wait.match ("*", 5)

  -- see if end of inventory


  if not string.match (line, "^[ 0-9][0-9]") then
    break
  end -- if

  -- save group line
  table.insert (grp, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))


end -- while loop

local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#grp + 2) + 10

-- make window correct size

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Group", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

for i, styles in ipairs (grp) do

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

end -- for each inventory item

WindowShow (win, true)


end)   -- end of coroutine</send>
  </alias>
</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- Nick Gammon

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

Posted by Uberelf   (2 posts)  Bio
Date Reply #2 on Tue 24 Mar 2020 04:04 PM (UTC)
Message
You are the master, 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.


11,563 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.