Everything seems to be working great now, I even added a few more windows, but, I have one question.
I have a window for the inventory, the pack, and spells I'm sustaining. But if there's nothing in the pack, or I'm not carrying anything, or not sustaining spells, none of the windows work until I put something in inv/pack/sustain a spell. Is there a way to fix that?
I'm using:
require "wait"
wait.make (function () -- coroutine starts here
local win = GetPluginID () .. ":inventory"
local font = "f"
if not WindowInfo ("1", 1) then
WindowCreate ("1", 0, 0, 0, 0, 6, 0, 0)
WindowFont ("1", font, "Lucida Console", 9)
end -- if
-- request inventory
Send "inventory"
-- wait for inventory to start
local x = wait.match ("*You are carrying:", 10, trigger_flag.OmitFromOutput)
if not x then
ColourNote ("white", "blue", "No inventory received within 10 seconds")
return
end -- if
local inv = {}
local max_width = WindowTextWidth ("1", font, "Inventory")
-- loop until end of inventory
while true do
local line, wildcards, styles = wait.match ("*", 0, trigger_flag.OmitFromOutput)
-- see if end of inventory
if line == "" then
break
end -- if
-- save inventory line
table.insert (inv, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth ("1", font, line))
end -- while loop
local font_height = WindowFontInfo ("1", font, 1)
local window_width = max_width + 10
local window_height = font_height * (#inv + 2) + 10
-- make window correct size
WindowCreate ("1", 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#000000")
WindowRectOp ("1", 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- heading line
WindowText ("1", font, "Inventory", 5, 5, 0, 0, ColourNameToRGB "red")
-- draw each inventory 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 ("1", font, style.text, x, y, 0, 0, style.textcolour)
end -- for
y = y + font_height
end -- for each inventory item
if not WindowInfo ("2", 1) then
WindowCreate ("2", 0, 0, 0, 0, 7, 0, 0)
WindowFont ("2", font, "Lucida Console", 9)
end -- if
-- request inventory
Send "look in pack"
-- wait for inventory to start
local x = wait.match ("*a Blackhawk(TM) X-3 R.A.P.T.O.R. pack (used): ", 10, trigger_flag.OmitFromOutput)
if not x then
ColourNote ("white", "blue", "No inventory received within 10 seconds")
return
end -- if
local pack = {}
local max_width = WindowTextWidth ("2", font, "a Blackhawk(TM) X-3 R.A.P.T.O.R.")
-- loop until end of inventory
while true do
local line, wildcards, styles = wait.match ("*", 0, trigger_flag.OmitFromOutput)
-- see if end of inventory
if line == "" then
break
end -- if
-- save inventory line
table.insert (pack, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth ("2", font, line))
end -- while loop
local font_height = WindowFontInfo ("2", font, 1)
local window_width = max_width + 10
local window_height = font_height * (#pack + 2) + 10
-- make window correct size
WindowCreate ("2", 0, 0, window_width, window_height, 7, 0, ColourNameToRGB "#000000")
WindowRectOp ("2", 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- heading line
WindowText ("2", font, "a Blackhawk(TM) X-3 R.A.P.T.O.R. pack", 5, 5, 0, 0, ColourNameToRGB "Red")
-- draw each inventory line
local y = font_height * 2 + 5
for i, styles in ipairs (pack) do
local x = 5
for _, style in ipairs (styles) do
x = x + WindowText ("2", font, style.text, x, y, 0, 0, style.textcolour)
end -- for
y = y + font_height
end -- for each inventory item
if not WindowInfo ("3", 1) then
WindowCreate ("3", 0, 0, 0, 0, 7, 0, 0)
WindowFont ("3", font, "Lucida Console", 9)
end -- if
-- request inventory
Send "status"
-- wait for inventory to start
local x = wait.match ("*You are sustaining:", 10, trigger_flag.OmitFromOutput)
if not x then
ColourNote ("white", "blue", "No inventory received within 10 seconds")
return
end -- if
local sus = {}
local max_width = WindowTextWidth ("3", font, "Sustained Spells")
-- loop until end of inventory
while true do
local line, wildcards, styles = wait.match ("*", 0, trigger_flag.OmitFromOutput)
-- see if end of inventory
if line == "" then
break
end -- if
-- save inventory line
table.insert (sus, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth ("3", font, line))
end -- while loop
local font_height = WindowFontInfo ("3", font, 1)
local window_width = max_width + 10
local window_height = font_height * (#sus + 2) + 10
-- make window correct size
WindowCreate ("3", 0, 0, window_width, window_height, 7, 0, ColourNameToRGB "#000000")
WindowRectOp ("3", 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- heading line
WindowText ("3", font, "Sustained Spells", 5, 5, 0, 0, ColourNameToRGB "red")
-- draw each inventory line
local y = font_height * 2 + 5
for i, styles in ipairs (sus) do
local x = 5
for _, style in ipairs (styles) do
x = x + WindowText ("3", font, style.text, x, y, 0, 0, style.textcolour)
end -- for
y = y + font_height
end -- for each inventory item
WindowShow "1"
WindowShow "2"
WindowShow "3"
end) -- end of coroutine
|