Who List Miniwindow

Posted by Aralia Faal on Sat 30 Jun 2012 06:12 PM — 13 posts, 44,428 views.

#0
I'm trying to make a plugin for a mud I play that takes the who list:

Accessing CDI Information...
...
..Found!

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ Immorts ]=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[1004 RANK] |PK| Immortal Name
[1007 RANK] |PPK| Immortal Name

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ Players ]=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[1170 Aus] |PPK| Player Name

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ Newbies ]=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[ 2 Ara] Player Name
Visible Players: 3/3 Max since reboot: 9 Max Ever: 65

Logging off..
...
..Disconnected.

And makes two seperate miniwindows. One for Immortals and the one for Players, (which combines both Players and Newbies).

(RANK and Names edited due to offensive terms)
USA Global Moderator #1
So what do you have so far?
#2
Knew I forgot something. Its not exactly a plugin yet, I've tried converting the Inventory Miniwindow Plugin into an alias to capture all of it just to see if I could get it to work without making more then one miniwindow:

require "wait"

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


local win = GetPluginID () .. ":who"
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 who list

Send "who"


-- wait for who list to start

local x = wait.match ("..Found!", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Who")

-- loop until end of who list

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

  -- see if end of who list

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

  -- save who list line
  table.insert (inv, 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 * (#inv + 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, "Who List", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each who list line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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 who list item

WindowShow (win, true)


end)   -- end of coroutine


10 seconds later I get "No Inventory received within 10 seconds"

I didn't edit much as you can see most of the functions still use inv. Once I get it working I'll end up changing them to whoImm or whoplayer.
Amended on Sat 30 Jun 2012 07:22 PM by Aralia Faal
Australia Forum Administrator #3
Aralia Faal said:



...
  ColourNote ("white", "blue", "No who list received within 10 seconds")
...


10 seconds later I get "No Inventory received within 10 seconds"



Oh? That message is not in the alias.
#4
Oh.. that was my mistake it does return "No who list received within 10 seconds" I scrolled up to get it just to be sure and I must have gone up to a point before I edited it.
Australia Forum Administrator #5
Can you double-click on the line with "Found!" on it, and then go to Display menu -> Text Attributes -> Line Info.

Then find the notepad window that will have opened underneath and copy and paste what you see? Like this:


Line 537 (537), Sunday, July 01, 5:07:20 PM
 Flags = End para: YES, Note: no, User input: no, Log: YES, Bookmark: no
 Length = 8, last space = -1
 Text = "..Found!"

1 style run

1: Offset = 0, Length = 8, Text = "..Found!"
 No action.
 Flags = Hilite: no, Underline: no, Blink: no, Inverse: no, Changed: no
 Foreground colour ANSI  : 7 (White)
 Background colour ANSI  : 0 (Black)

8 columns in 1 style run

------ (end line information) ------

#6
Line 108 (108), Sunday, July 01, 7:14:05 AM
 Flags = End para: YES, Note: no, User input: no, Log: YES, Bookmark: no
 Length = 8, last space = -1
 Text = "..Found!"

2 style runs

1: Offset = 0, Length = 2, Text = ".."
 No action.
 Flags = Hilite: YES, Underline: no, Blink: no, Inverse: no, Changed: no
 Foreground colour ANSI  : 5 (Magenta)
 Background colour ANSI  : 0 (Black)

2: Offset = 2, Length = 6, Text = "Found!"
 No action.
 Flags = Hilite: no, Underline: no, Blink: no, Inverse: no, Changed: no
 Foreground colour ANSI  : 5 (Magenta)
 Background colour ANSI  : 0 (Black)

8 columns in 2 style runs

------ (end line information) ------
Australia Forum Administrator #7
Hmmm. Can you now copy the actual alias please? Not just the contents of it.

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
#8
<aliases>
  <alias
   match="who"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

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

local win = GetPluginID () .. ":who"
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 who list

Send "who"

  -- wait for who list to start
local x = wait.match ("..Found!", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Who")

  -- loop until end of who list
while true do
  local line, wildcards, styles = wait.match ("*")

  -- see if end of who list
  if string.match (line, "^Logging off..") then
    break
  end -- if

  -- save who list line
  table.insert (inv, 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 * (#inv + 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, "Who List", 5, 5, 0, 0, ColourNameToRGB  "yellow")

  -- draw each who list line
local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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 who list item

WindowShow (win, true)

end) -- end of coroutine</send>
  </alias>
</aliases>
Australia Forum Administrator #9
I can reproduce your problem. However it goes away if you put it back into a plugin (not totally sure why).

For the moment I suggest you take the original Inventory Miniwindow Plugin, change the name and plugin ID here:


<plugin
   name="Inventory_Miniwindow_Demo"
   author="Nick Gammon"
   id="e49156f49854904ea8b90223"
   language="Lua"
   purpose="Shows Inventory in a miniwindow"
   save_state="y"
   date_written="2010-05-02 15:35:51"
   requires="4.51"
   version="1.0"
   >


eg.


<plugin
   name="Who_List_Miniwindow"
   author="Aralia Faal"
   id="78999ac6f6dcbbeb7c2ce6e0"
   language="Lua"
   purpose="Shows Who List in a miniwindow"
   save_state="y"
   date_written="2012-07-02"
   requires="4.51"
   version="1.0"
   >





And then make the few other changes you had to the alias. It worked for me as a plugin.
Amended on Mon 02 Jul 2012 08:50 AM by Nick Gammon
#10
I have to admit I'm not that.. "smart" when it comes to all this. I used the YouTube tutorials to create the alias. That being said.. How do I make it an actual plugin?
Amended on Mon 02 Jul 2012 05:30 PM by Aralia Faal
Australia Forum Administrator #11
You are right, it *should* work. And I just made a new empty world, pasted in your alias, and it worked. There must be something interfering with it.

For example, another trigger matching first.

Can you turn on Game menu -> Trace, and try the alias again? Paste what it shows. Thanks.
#12
The bad news:
I screwed something up because all my triggers and aliases disapeared...

The good news:
I copeid and pasted what I entered when you asked me to past the alias itself and it now works.

To do list:
I'd like to have it remove the display from the world.
Have it update when someone logs in and out
(GW:OM) Gibin Has Come To Play! 
(GW:OM) Gibin Decided To Rejoin The Real World.