This is still kinda being tested. It puts the scan
command output in miniwindow and trys to make menu commands
for things like Kill, Examine etc.
The triggers are not so good sometimes it will get the wrong
lines.
"sw" will do scan and update window.
There is a timer you can turn it on with "sw on/off" and set the seconds with
"sw <seconds>, however the triggers are bad and will catch the wrong lines atm.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, July 16, 2009, 9:58 PM -->
<!-- MuClient version 4.42 -->
<!-- Plugin "Scan_Window" generated by Plugin Wizard -->
<muclient>
<plugin
name="Scan_Window"
author="Blainer"
id="73766b7b4dfab1cd1ce9494d"
language="Lua"
purpose="put scan in miniwindow"
date_written="2009-07-16 21:58:17"
requires="4.42"
version="1.0"
save_state="y"
>
</plugin>
<triggers>
<trigger
enabled="n"
group="scan"
lines_to_match="1"
keep_evaluating="y"
match="^(.*)$"
multi_line="n"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
script="process_triggers"
>
</trigger>
</triggers>
<timers>
<timer name="scan" script="DoScan" enabled="n" second="5.00" offset_second="0.00" send_to="12"
></timer>
</timers>
<aliases>
<alias
script="swCmd"
match="^sw(.*)$"
regexp="y"
enabled="y"
send_to="12"
ignore_case="y"
sequence="100"
></alias>
<alias
script="runCmd"
match="^s ([A-Za-z]+) (\d+)$"
regexp="y"
enabled="y"
send_to="12"
ignore_case="y"
sequence="1"
></alias>
</aliases>
<script>
<![CDATA[
require "tprint"
require "getworld"
require "getstyle"
font = "fn"
FontName = GetInfo(20) -- Font for window, i.e. "Times New Roman", GetInfo(20) is current window font.
BackgroundColour = GetInfo (271)
TitleColour = "dimgray" -- Colour of title text
LFontSize = 4 -- List font size.
TFontSize = 8 -- Title font size.
FontName = GetInfo(20) -- Font for window, i.e. "Times New Roman", GetInfo(20) is current window font.
TitleText = "scan" -- Window Title
BorderWidth = 1 -- Line thickness for display boxes, border width for popups is set in mw.lua.
ButtonGap = 10 -- Space between buttons.
Indent = 5
LineSpace = 2
OffSet = BorderWidth + 4 -- Objects offset from window edge.
WinWidth = 0
WinHeight = 0
ShowBorders = true
win = GetPluginID ()
tm = "scan"
seconds = 5
scanT = {}
targetsT = {}
TitleFont = "tfn"
ListFont = "fn"
function swCmd (name, line, wildcards, styles)
s = wildcards[1]:sub(2, wildcards[1]:len())
--turn to send window off
if line:match ("off") then
EnableTimer (tm, false)
Note ("scan off")
return
end
--turn send to window on
if line:match ("on") then
EnableTimer (tm, true)
Note ("echo on")
return
end
if line:match("%d") then
iTimer = tonumber (wildcards[1])
SetTimerOption (tm, "seconds", iTimer)
return
end
DoScan ()
end --swCmd
--run command by line number
function runCmd (name, line, wildcards, styles)
if targetsT[1] == nil then
DoScan ()
return
end
if not wildcards[1] then
return
end
s = wildcards[1] .. " " .. targetsT[tonumber(wildcards[2])]
Send (s)
end --runCmd
function DoScan (name, line, wildcards, styles)
EnableTriggerGroup ("scan", true)
SendNoEcho ("scan")
scanT = {}
end --DoScan
function process_triggers (name, line, wildcards, styles)
if line:match("^%<%d.*") then
EnableTriggerGroup ("scan", false)
ShowScan ()
return
end
t = { ["(Translucent)"] = "(Trans.)",
["(White Aura)"] = "(W.Aura)",
["(Animated)"] = "(Anim.)"
}
for i,v in ipairs (styles) do
v.text = v.text:gsub ("%([%a ]+%)",
function (str)
return t [str]
end)
end
table.insert (scanT, styles)
end --process_triggers
--write table to scan window
function ShowScan ()
LFontHeight = WindowFontInfo(win, TitleFont, 1) --list font height
TFontHeight = WindowFontInfo(win, TitleFont, 1) --title font height
drag_hotspot = "drag_hotspot"
targetsT = {}
window_left, window_top, window_mode, window_flags =
tonumber (GetVariable ("windowx")) or 0,
tonumber (GetVariable ("windowy")) or 0,
tonumber (GetVariable ("windowmode")) or 8,
tonumber (GetVariable ("windowflags")) or 2
--get max line width
WinWidth = 0
for i,v in ipairs (scanT) do
s = ""
for j,w in ipairs (v) do
s = w.text .. s
WinWidth = math.max (WinWidth, WindowTextWidth (win, ListFont, s) + (Indent * 2))
end
end
--get window height
WinHeight = (#scanT * (LFontHeight + LineSpace)) + (TFontHeight * 2)
--create the window
WindowCreate (win, window_left, window_top, WinWidth, WinHeight, window_mode, window_flags, BackgroundColour)
--draw title
Twidth = WindowTextWidth (win, TitleFont, TitleText)
Left = (WinWidth / 2) - (Twidth / 2)
Right = Left + Twidth
Top = (TFontHeight / 2) - (TFontHeight / 2)
Bottom = Top + TFontHeight
WindowText (win, TitleFont, TitleText, Left, Top, 0, 0, TitleColour, false)
--make drag hotspot over title
WindowAddHotspot(win, drag_hotspot, Left, 0, Right, TFontHeight, "", "", "mousedown", "", "", "Move window", 10, 0)
WindowDragHandler(win, drag_hotspot, "dragmove", "dragrelease", 0)
--draw close button
BoxSq = 8
Left = OffSet
Top = (TFontHeight / 2) - (BoxSq / 2)
Right = Left + BoxSq
Bottom = Top + BoxSq
WindowCircleOp (win, 2, Left, Top, Right, Bottom, TitleColour, 0, BorderWidth, TitleColour, 0)
WindowAddHotspot(win, "CloseInv", Left, Top, Right, Bottom, "", "", "mousedownHideWin", "", "", "Minimize", 1, 0)
--draw refresh button
CircleSize = 9
Left = Right + ButtonGap
Right = Left + CircleSize
Bottom = Top + CircleSize
WindowCircleOp (win, 1, Left, Top, Right, Bottom, TitleColour, 0, BorderWidth, TitleColour, 0)
WindowAddHotspot(win, "RefreshLook", Left, Top, Right, Bottom, "", "", "RefreshLook", "", "", "Refresh Look", 1, 0)
--draw draw border
if ShowBorders then
WindowCircleOp (win, 2, 0, 0, WinWidth, WinHeight, TitleColour, 0, BorderWidth, TitleColour, 1, 5, 5)
end
t = { ["(Trans.) "] = "",
["(W.Aura) "] = "",
["(Linkdead) "] = "",
["(Charmed) "] = "",
["(Anim.) "] = "",
["An "] = ""
}
--write look to window
Top = TFontHeight + LineSpace
Left = 0
iLin = 0
for i,v in ipairs (scanT) do
iLin = iLin + 1
Bottom = Top + LFontHeight
Right = Indent + WindowTextWidth (win, ListFont, iLin)
Left = Indent
sHotSpot = ""
for j,w in ipairs (v) do
s = w.text
c = w.textcolour
Right = Left + WindowTextWidth (win, ListFont, s)
Left = Left + WindowText (win, ListFont, s, Left, Top, Right, Bottom, c, false)
sHotSpot = sHotSpot .. s
end
for k in sHotSpot:gmatch (" %- (.+)$") do
s = k:gsub ("(%(.+%) )",
function (str)
return t [str]
end)
if s:match(" ") then
s = s:match (" (%a+)$")
end
table.insert (targetsT, s)
s = s .. ":" .. iLin
WindowAddHotspot (win, s, Indent, Top, Right, Bottom, "", "", "", "", "Menu", "Left click for menu.", 1, 0)
end
Top = Top + LFontHeight + LineSpace
end
WindowShow (win)
end --ShowScan
function Menu (flags, hotspotid)
s = hotspotid:match("^(%a+):%d+$")
sMen = "^Action Menu|" .. "|Examine ".. s .. "|Look ".. s .. "|kill ".. s .. "|Kick ".. s .. "|Bash ".. s
result = WindowMenu (win, WindowInfo (win, 14), WindowInfo (win, 15), sMen)
if result ~= "" then
Send (result)
end
end --CopyLine
-- hide the inventory list and show the minimized button
function mousedownHideWin ()
window_left, window_top, window_mode, window_flags =
tonumber (GetVariable ("windowx")) or 0,
tonumber (GetVariable ("windowy")) or 0,
tonumber (GetVariable ("windowmode")) or 8,
tonumber (GetVariable ("windowflags")) or 0
BoxSq = 8 -- size of the close box
CirWidth = 10 -- size of circle move box
WinHeight = TFontHeight
WinWidth = OffSet + ButtonGap + BoxSq + WindowTextWidth (win, TitleFont, TitleText) + OffSet
if bit.band (window_flags, 2) then window_mode = 4 end
WindowCreate (win, window_left, window_top, WinWidth, WinHeight, window_mode, window_flags, BackgroundColour)
--draw close button
Left = OffSet
Top = (WinHeight / 2) - (BoxSq / 2)
Right = Left + BoxSq
Bottom = Top + BoxSq
WindowCircleOp (win, 2, Left, Top, Right, Bottom, TitleColour, 0, BorderWidth, TitleColour, 0, 5, 5)
WindowAddHotspot (win, "ShowLook", Left, Top, Right, Bottom, "", "", "ShowLook", "", "", "Show Inventory Window", 1, 0)
--draw title
Twidth = WindowTextWidth (win, TitleFont, TitleText)
Left = Right + ButtonGap
Right = Left + Twidth
Top = (WinHeight / 2) - (TFontHeight / 2)
Bottom = Top + TFontHeight
WindowText (win, TitleFont, TitleText, Left, Top, Right, Bottom, TitleColour, false)
WindowAddHotspot(win, drag_hotspot, Left, Top, Right, Bottom, "", "", "mousedown", "", "", "Move button", 10, 0)
WindowDragHandler(win, drag_hotspot, "dragmove", "dragrelease", 0)
WindowShow (win, true)
end -- mousedownHideWin
--http://www.gammon.com.au/forum/?id=9577
function mousedown (flags, hotspotid)
if hotspotid == drag_hotspot then
-- find where mouse is so we can adjust window relative to mouse
startx, starty = WindowInfo (win, 14), WindowInfo (win, 15)
-- find where window is in case we drag it offscreen
origx, origy = WindowInfo (win, 10), WindowInfo (win, 11)
end -- if
end -- mousedown
--http://www.gammon.com.au/forum/?id=9577
function dragmove(flags, hotspot_id)
-- find where it is now
local posx, posy = WindowInfo (win, 17),
WindowInfo (win, 18)
-- move the window to the new location - offset by how far mouse was into window
WindowPosition(win, posx - startx, posy - starty, 0, 2);
-- change the mouse cursor shape appropriately
if posx < 0 or posx > GetInfo (281) or
posy < 0 or posy > GetInfo (280) then
check (SetCursor ( 11)) -- X cursor
else
check (SetCursor ( 1)) -- hand cursor
end -- if
end -- dragmove
--http://www.gammon.com.au/forum/?id=9577
function dragrelease(flags, hotspot_id)
Repaint () -- update window location
-- find where window is now
local newx, newy = WindowInfo (win, 10), WindowInfo (win, 11)
-- don't let them drag it out of view
if newx < 0 or newx > GetInfo (281) or
newy < 0 or newy > GetInfo (280) then
-- put it back
WindowPosition(win, origx, origy, 0, 2)
return
end -- if out of bounds
window_left = newx -- remember for saving state
window_top = newy
window_mode = 0
window_flags = 2 -- absolute position
SaveState ()
end -- dragrelease
--http://www.gammon.com.au/forum/?id=9577
function check_map_position ()
-- check miniwindow visible
if window_left < 0 or window_left > GetInfo (281) or
window_top < 0 or window_top > GetInfo (280) then
window_left, window_top = 0, 0 -- reset to top left
window_mode = 7
window_flags = 0
end -- if not visible
WindowPosition (win, window_left, window_top, window_mode, window_flags)
end -- check_map_position
--http://www.gammon.com.au/forum/bbshowpost.php?id=9270
function OnPluginInstall ()
window_left, window_top, window_mode, window_flags =
tonumber (GetVariable ("windowx")) or 0,
tonumber (GetVariable ("windowy")) or 0,
tonumber (GetVariable ("windowmode")) or 8,
tonumber (GetVariable ("windowflags")) or 2
-- make miniwindow so I can grab the font info
WindowCreate (win, window_left, window_top, 1, 1, window_mode, window_flags, BackgroundColour)
-- give main world window time to stabilize its size and position
DoAfterSpecial (5, "check_map_position ()", sendto.script)
WindowFont (win, "fn", FontName, LFontSize, false, false, false, false, 0, 0, 0) -- list
WindowFont (win, "tfn", FontName, TFontSize, false, false, false, false, 0, 0) -- title
-- make colour lua code
if tostring (TitleColour):match ("%a") then
TitleColour = ColourNameToRGB(TitleColour)
end
SetTimerOption (tm, "seconds", seconds)
Note("Scan_Window.xml installed")
end -- OnPluginInstall
--http://www.gammon.com.au/forum/bbshowpost.php?id=9270
function OnPluginSaveState ()
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
SetVariable ("windowx", tostring (window_left))
SetVariable ("windowy", tostring (window_top))
SetVariable ("windowmode", tostring (window_mode))
SetVariable ("windowflags", tostring (window_flags))
end -- OnPluginSaveState
function OnPluginEnable ()
OnPluginInstall ()
end --OnPluginEnable
function OnPluginDisable ()
OnPluginClose ()
end -- OnPluginDisable
function OnPluginClose()
WindowShow (win, false)
end -- OnPluginClose
]]>
</script>
</muclient>
|