<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, May 29, 2009, 11:34 PM -->
<!-- MuClient version 4.40 -->
<!-- Plugin "Inventory_List" generated by Plugin Wizard -->
<muclient>
<plugin
name="Inventory_Display"
author="Blainer"
id="6dbbeddda02ed2390b58ccd9"
language="Lua"
purpose="List Inventory in Inventory Mini Window"
date_written="2009-05-29 23:33:41"
requires="4.40"
version="1.0"
save_state="y"
>
<description trim="y">
Displays inventory in a mini window.
</description>
</plugin>
<triggers>
<trigger
enabled="n"
name="catch_inventory"
lines_to_match="1"
keep_evaluating="y"
match="^(\{inventory\}$)"
multi_line="n"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
script="inventory_parse"
><!-- capture Inventory command output -->
</trigger>
<trigger
enabled="n"
name="catch_all"
lines_to_match="1"
keep_evaluating="n"
match="*"
multi_line="n"
omit_from_output="y"
send_to="12"
sequence="10"
script=""
><!-- capture all untill disabled -->
</trigger>
<trigger
enabled="n"
name="invdata_catch"
lines_to_match="1"
keep_evaluating="y"
match="^(\{invdata\})"
multi_line="n"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
script="invdata_parse"
><!-- catch inventory data output -->
</trigger>
</triggers>
<aliases>
<alias
script="proc_alias"
match="inw *"
enabled="y"
send_to="12"
sequence="100"
>
<send></send>
</alias>
<alias
script="proc_alias"
match="inw"
enabled="y"
send_to="12"
sequence="100"
>
<send></send>
</alias>
</aliases>
<script>
<![CDATA[
require "tprint"
WindowCreate(GetPluginID() .. "background", 0, 0, 1, 1, 8, 0, ColourNameToRGB("white"))
WindowFont (GetPluginID() .. "background", "inv_f", GetInfo(20), 8, false, false, false, false)
font_height = WindowFontInfo(GetPluginID() .. "background", "inv_f", 1)
line_count = 0 -- holds number of lines in inv display
max_width = 0 -- holds max line width of inv display
t={} -- styles to pass to Display_Styled_Line
desc={} -- capt from indata to get serial for ref
serial={} -- capt from indata to get serial for ref
lvl={} -- capt from inv data used for comparison
function tsearch(tdesc, desc, ilvl) -- iterate table comparing it to current descritpion
for i, v in ipairs (tdesc) do
if v == desc and lvl[i] == ilvl then
return true
end
end
return false
end -- tsearch
function proc_alias (name, line, wildcards, styles) -- process command line
--SendNoEcho("give all.potion <player name>") -- used this to sybc invdata and inv, only happened once though
EnableTrigger("invdata_catch", true) -- enable trigger to catch invdata
EnableTrigger("catch_inventory", true) -- enable trigger to catch inventory
wait_for_invdata = coroutine.create(function ()
SendNoEcho("invdata")
coroutine.yield (wait_for_invdata) -- wait for invdata processing
SendNoEcho("in")
end)
coroutine.resume (wait_for_invdata)
end
function invdata_parse (name, line, wildcards) -- process the catch all trigger
EnableTrigger("invdata_catch", false) -- release {invdata} for other plugins
if line == "{invdata}" then -- set trigger to catch all lines
SetTriggerOption("catch_all", "script", "invdata_parse")
EnableTrigger("catch_all", true)
return
elseif line == "{/invdata}" then -- turn of trigger catch all
EnableTrigger("catch_all", false)
SetTriggerOption("catch_all", "script", "")
coroutine.resume (wait_for_invdata) -- done with invdata continue
return
else
local inv_serial, inv_shortflags, inv_description, inv_level, inv_type, inv_unique, inv_wear,
inv_unknown = string.match (line, "^(%d+)%,(.*)%,(.+)%,(%d+)%,(%d+)%,(%d+),(-?%d+),(-?%d+)$")
if not serial[1] then -- put first vals in table
table.insert(serial, inv_serial)
table.insert(desc, inv_description)
table.insert(lvl, inv_level)
return
elseif not tsearch(desc, inv_description, inv_level) then -- if desc is not already in table put it in
table.insert(serial, inv_serial)
table.insert(desc, inv_description)
table.insert(lvl, inv_level)
end
end
end -- invdata_parse
function inventory_parse (name, line, wildcards, styles)
if line == "{inventory}" then -- set trigger to catch all lines
SetTriggerOption("catch_all", "script", "inventory_parse")
EnableTrigger("catch_all", true)
EnableTrigger("catch_inventory", false) -- disable trigger to catch inventory
WindowShow (GetPluginID() .. "background", false) -- hide window
return
elseif line == "{/inventory}" then -- turn off trigger catch all
EnableTrigger("catch_all", false)
SetTriggerOption("catch_all", "script", "")
win_back_set (max_width, ((line_count + 2) * font_height) + 5) --create window to the size of the longest line in inv
WindowShow (GetPluginID() .. "background", true) -- show window
Display_Styled_Line (line_count, t, GetPluginID() .. "background") -- pass t with styles to create text for window
t={} -- zero tables and vars
serial={}
desc={}
lvl={}
line_count = 0
max_width = 0
return
else
table.insert(t, styles) -- put styles for this line in table
max_width = math.max (max_width, WindowTextWidth (GetPluginID() .. "background", "inv_f", line) + 5) -- calc max line width of inv
line_count = line_count + 1 -- add up number of lines in inv
end
end -- inventory_parse
function win_back_set (width, height) -- create background window
WindowCreate(GetPluginID() .. "background", 0, 0, width, height, 8, 0, ColourNameToRGB("black"))
end -- win_back_set
function Display_Styled_Line (line, styles, id) -- use styles from table t to creat text with hotspots
local left = 5 -- set indent for text
local top = (line - 1) * font_height -- set starting position for first line
for i, _ in ipairs (styles) do
left = 5 -- after line is finished reset to default indent
text = "" -- var for full name no styles
for a, v in ipairs (styles[i]) do
top = i * font_height + 2 -- calc top position for line
left = left + WindowText (id, "inv_f", v.text, left, top, 0, 0, v.textcolour) -- calc left pos for this style section
text = text .. v.text -- make line with no styles
end -- for each style run
Note(serial[i]..": "..text) -- prints testing data
--WindowRectOp (GetPluginID() .. "background", 1, 5, top, left, top + font_height, ColourNameToRGB("gray")) -- draw rectangles around text, for testing
WindowAddHotspot(GetPluginID() .. "background", serial[i] .. ": " .. text, -- make hotspots
5, top, left, top + font_height, -- rectangle
"mouseover",
"cancelmouseover",
"mousedown",
"cancelmousedown",
"mouseup",
"tooltip text", -- tooltip text
1, 0) -- hand cursor
end -- Display_Style_Lines
end -- Display_Styled_Line
function mouseover (flags, hotspot_id)
--Note("mouseover")
Note(hotspot_id)
end
function cancelmouseover (flags, hotspot_id)
--Note("cancelmouseover")
end
function mousedown (flags, hotspot_id)
--Note("mousedown")
end
function cancelmousedown (flags, hotspot_id)
--Note("cancelmousedown")
end
function mouseup (flags, hotspot_id)
--Note("mouseup")
end
]]>
</script>
</muclient>
|