mobs from scan to miniwin

Posted by Mahony on Mon 13 Oct 2014 01:10 PM — 7 posts, 27,457 views.

#0
Hi
I altered invetory miniwin example from this thread
http://www.gammon.com.au/forum/bbshowpost.php?id=9965&page=10
to capture mobs in my room from scan to miniwin. It works but has a little flaw. It doesn't work if the room is empty because there is no "trigger message" "Right here you see:"
I would like to clear the win or put there "Nothing here".
So I think I know where is the problem but I don't see how to fix it. I see the only way is completely different approach. I din't see easy fix to this code. Or is it possible?
Thanx for help

Here is the code:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, October 08, 2014, 3:49 PM -->
<!-- MuClient version 4.93 -->

<!-- Plugin "mahony_scan_win" generated by Plugin Wizard -->

<muclient>
<plugin
   name="mahony_scan_win"
   author="Mahony"
   id="c6dcb8a0fc4043d4a19fdcd7"
   language="Lua"
   save_state="y"
   date_written="2014-10-08 15:48:20"
   requires="4.93"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Aliases  -->

<aliases>
  <alias
   match="noscan"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
   local win = GetPluginID () .. "_scan"
   WindowShow (win, false)
</send>

  </alias>
  <alias
   match="scan_win"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

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

-- request scan

Send "scan"

-- wait for scan to start

local x = wait.match ("Right here you see:", 10)

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

local scant = {}
local max_width = WindowTextWidth (win, font, "Scan")

-- loop until end of inventory

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

  -- see if end of scan

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

  -- save scan line
  table.insert (scant, 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 * (#scant + 2) + 10

-- make window correct size

WindowCreate (win, 
                 windowinfo.window_left, 
                 windowinfo.window_top, 
                 window_width, window_height,              -- width, height
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#373737") 

WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)
  
-- heading line

WindowText (win, font, "Scan here", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each scan line

local y = font_height * 2 + 5

for i, styles in ipairs (scant) 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 scan 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 () .. "_scan"
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>
USA Global Moderator #1
What if you clear it every time you scan and then refill it when the trigger fires?
#2
Oh crap. Beauty of simplicity. Trying to code that but because I just altered this scipt and I still don't know exactly how it works may I ask for the code that would fix it?
Thank you!
USA Global Moderator #3
This is the line that clears the window:
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)


Maybe change
-- request scan

Send "scan"

-- wait for scan to start


to

-- request scan

Send "scan"
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- wait for scan to start
#4
It seems it is not enough. It does nothing. May be recreate the window or run WindowShow?
USA Global Moderator #5
You're right. I didn't read carefully, sorry.

You'll need to move the part where it creates the window

local font_height = WindowFontInfo (win, font, 1)

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

-- make window correct size

WindowCreate (win, 
                 windowinfo.window_left, 
                 windowinfo.window_top, 
                 window_width, window_height,              -- width, height
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#373737") 

WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)
  
-- heading line

WindowText (win, font, "Scan here", 5, 5, 0, 0, ColourNameToRGB  "yellow")


to happen before you ask for the mob list.
Amended on Mon 13 Oct 2014 08:25 PM by Fiendish
#6
Sooo. Here is to code that works "somehow". I do feel that it is not optimal and efficient code. When there ARE mobs in my room I still see the first window with "Nothing here!" flick and then it is redrawn. It would need some optimalization. :)
Thanx very much anyway.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, October 08, 2014, 3:49 PM -->
<!-- MuClient version 4.93 -->

<!-- Plugin "mahony_scan_win" generated by Plugin Wizard -->

<muclient>
<plugin
   name="mahony_scan_win"
   author="Mahony"
   id="c6dcb8a0fc4043d4a19fdcd7"
   language="Lua"
   save_state="y"
   date_written="2014-10-08 15:48:20"
   requires="4.93"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Aliases  -->

<aliases>
  <alias
   match="noscan"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
   local win = GetPluginID () .. "_scan"
   WindowShow (win, false)
</send>

  </alias>
  <alias
   match="scan_win"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

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

-- request scan

Send "scan"
local scant = {}
local font_height = WindowFontInfo (win, font, 1)
local max_width = WindowTextWidth (win, font, "Nothing here!")
local window_width = max_width + 10
local window_height = font_height * (#scant + 2) + 10

-- make window correct size

WindowCreate (win, 
                 windowinfo.window_left, 
                 windowinfo.window_top, 
                 window_width, window_height,              -- width, height
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#373737") 

WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)
  
-- heading line

WindowText (win, font, "Scan here", 5, 5, 0, 0, ColourNameToRGB  "yellow")
WindowText (win, font, "Nothing here!", 5, 20, 0, 0, ColourNameToRGB  "red")
WindowShow (win, true)

-- wait for scan to start

local x = wait.match ("Right here you see:", 10)

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



-- loop until end of inventory

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

  -- see if end of scan

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

  -- save scan line
  table.insert (scant, 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 * (#scant + 2) + 10

-- make window correct size

WindowCreate (win, 
                 windowinfo.window_left, 
                 windowinfo.window_top, 
                 window_width, window_height,              -- width, height
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#373737") 

WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)
  
-- heading line

WindowText (win, font, "Scan here", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each scan line

local y = font_height * 2 + 5

for i, styles in ipairs (scant) 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 scan 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 () .. "_scan"
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>