Alright, completed.
I noticed something today that I hadn't noticed before. One line is being omited from the output - the first wait.match.
here's the entire thing:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, May 02, 2010, 3:37 PM -->
<!-- MuClient version 4.51 -->
<!-- Plugin "PlayerList_Miniwindow_Demo" generated by Plugin Wizard -->
<muclient>
<plugin
name="PlayerList_Miniwindow_Demo"
author="Nick Gammon, mod by Curtis_D"
id="e49156f49854904ea8b90223"
language="Lua"
purpose="Shows list of players in a miniwindow"
save_state="y"
date_written="2010-05-02 15:35:51"
requires="4.51"
version="1.0"
>
<description trim="y">
<![CDATA[
Type "WHO" to see player list in a miniwindow.
]]>
</description>
</plugin>
<!-- Aliases -->
<aliases>
<alias
match="WHO"
enabled="y"
send_to="12"
sequence="100"
>
<send>
require "wait"
wait.make (function () -- coroutine starts here
local win = GetPluginID () .. ":players"
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 online player list
Send "WHO"
-- wait for list to start
local x = wait.match ("Player Name*", 10, trigger_flag.OmitFromOutput)
if not x then
ColourNote ("white", "blue", "No data received within 10 seconds")
return
end -- if
local data = {}
local max_width = WindowTextWidth (win, font, "Players")
-- loop until end of data
while true do
local line, wildcards, styles = wait.match ("*", trigger_flag.OmitFromOutput)
-- see if end of data
if string.match (line, "%d+ players are connected. %(Max was %d+%)") then
break
end -- if
-- save data line
table.insert (data, 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 * (#data + 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, "Players", 5, 5, 0, 0, ColourNameToRGB "yellow")
-- draw each data line
local y = font_height * 2 + 5
for i, styles in ipairs (data) 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 data item
WindowShow (win, true)
end) -- end of coroutine
</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
require "wait" -- for waiting for inventory lines
require "movewindow" -- load the movewindow.lua module
win = GetPluginID () .. "_inventory"
font = "f"
function OnPluginInstall ()
-- install the window movement handler, get back the window position
windowinfo = movewindow.install (win, 6) -- default to 6 (on top right)
-- make window so I can grab the font info
WindowCreate (win, 0, 0, 0, 0, 1, 0, 0)
-- add the font
WindowFont (win, font, "Lucida Console", 9)
end -- OnPluginInstall
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
end -- function OnPluginSaveState
]]>
</script>
</muclient>
|