Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ Aardwolf Inventory List in mini with serial references.

Aardwolf Inventory List in mini with serial references.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Blainer   (191 posts)  Bio
Date Thu 18 Jun 2009 11:23 AM (UTC)
Message
This is not finished but I thought the inventory list with serials matched and one serial for stackable items was cool and wanted to share it.

The serial is just used as a hotspot id at the moment but you can see how easy 'wear <serial>' commands are to make instead of finding the key words by parsing the 'id <item keyword>' command or the 'inventory' output (don't even know how you can do that with inv list) for each item. One limitation is the 'sacrifice' command won't work with serials and as I see it this is one of the more useful commands to use with serials because you can loot then drop and sacrifice with a click without doing an 'id <item keyword> to get keywords, however the 'get <serial>' does work after you drop an item so maybe it's unfinished.

My plan is to make the mouse over display a window with the id command output displayed for the item but I can send the commands to get that data if and when I want it and store it in my database and use serials to reference the items for MUD commands.

The test for checking if an item is stackable just uses the item description and level at the moment. This worked for my inventory at the moment. I had a lot of trouble with this algorithm and Lua code, I ended up with three tables. At the moment only description and level is used to test if item is stacked, I think this is enough but will find out.

One thing I am not sure about this idea is that at one point the 'invdata' output and the 'inventory' output did not match. I did a 'give all.potion <player name>' command and it all synced up ok so not sure how to silently put this in or maybe I'll make a test for it if I can re-make the problem.

Once I have all commands and windows working I'll move on to containers. That being the main reason I want a clickable inventory list.

Forgive the bad code if anyone wants to tell me why it's bad please do. :)

Use 'inw' to display the window.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 18 Jun 2009 10:13 PM (UTC)
Message
I have amended your forum profile to allow you to make longer posts, Blainer, so you may want to try again putting the whole thing into a single post.

Also, to avoid problems with forum tags, copy the entire plugin to the clipboard, then go to MUSHclient's Edit menu (with a world open) and select "Convert Clipboard Forum Codes" (Shift+Ctrl+Alt+Q) - that will stop various things being rendered incorrectly. Then paste the result into the forum message (putting the code tags around it).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Blainer   (191 posts)  Bio
Date Reply #2 on Fri 19 Jun 2009 02:49 AM (UTC)

Amended on Fri 19 Jun 2009 12:25 PM (UTC) by Blainer

Message

<?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>
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 19 Jun 2009 06:15 AM (UTC)
Message
Did you hit "convert forum codes" twice? It looks like too many backslashes there.

I see in your post:


<script>
<!\[CDATA\[


... when I normally see:


<script>
<![CDATA[



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Blainer   (191 posts)  Bio
Date Reply #4 on Fri 19 Jun 2009 12:26 PM (UTC)
Message
Must have, fixed now. Stand back genius at work.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #5 on Tue 23 Jun 2009 09:08 AM (UTC)
Message
This managed to not do anything when I installed it. It does show a list of my inventory, but not in a miniwindow. The only two other miniwindow plugins I have are the Aardwolf_Map_V2 and the Aardwolf_Campaign_Noter (which was hidden at the time). Doesn't look like they will interfere with each other, since the window for this plugin is in the lower right.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #6 on Tue 23 Jun 2009 10:05 AM (UTC)
Message
Ah, I see what the issue was. The plugin requires the inv tags to use instead of using the invdata command like I had expected. Now it works.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Blainer   (191 posts)  Bio
Date Reply #7 on Wed 24 Jun 2009 07:46 AM (UTC)
Message
Yeah I took the telnet_options.lua out of this one. I just wanted to show the serials from the new tags matched with the output of the inventory command. And I wasn't sure what was going to work on other peoples MUSH installs. I am pretty sure telnet_options.lua is part of the default install. I never planned to make this plugin for anyone else but when I get it working I will try to make it stable and post it. But I am using a file to hold the initial sql for db setup and a lua file the db front end which makes plugins annoying for most people I would think.
I am half way through the next version. I have it storing the list in a database, I find that simpler than working with tables (tables do my head in), and I can search for something with three lines of code. This will allow me to store the items permanently with their id command output to use as a mouseover popup and reference a spell list for spell details from item mods. I am using invdata this time.
The plan goes like this:
User does “inw” script command
Script captures invdata output
Clear the inventory table in the db
Enter the inventory list into the db
Get the inventory list
Display the inventory
Add item to items table if not already there
Search the items for data relevant to each items properties
Send MUD commands to get any missing data
User mouseover item and properties are displayed

At the moment I am working on getting the invdetails, I have all the code to capture it just a case of storing it without duplicates like potions and then retrieving it. I will have to process the id command output to get the keywords though because not all the commands work with serials. I am not sure at the moment weather to just process the id commands and leave the invdetails until Lasher finishes it.

I am a little confused as to the best way to do this. I want the inventory list to appear as fast as possible after I enter “inw” but I want all the properties to be displayed as well. So if I kill 25 mobs and then refresh my inventory the script is going to need to send and receive a lot of id commands which will mean I will have to wait for all that to send and receive before I can send other MUD commands. I thought I might search the database for the properties, if not found send id command only when the item is mouseovered.

If there is anyone with experience with this type of plugin I would appreciate any advice.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 24 Jun 2009 09:47 AM (UTC)
Message
My approach when writing a similar plugin was to do this:


  • Display the minimal information available from the standard inventory (ie. item name and type)

  • If you mouse-over an item, it looks up in its internal cache to see if invdetails was available for that item already, if so, it was shown in a "hover over" window.

    See: http://www.gammon.com.au/forum/?id=8936

  • If not, the hover-over window showed something like "details being downloaded", and at the same time a request for the details for this particular item was sent.

  • When the details were received, and if the mouse was still hovering over that window, the hover-over details were refreshed with the full information. In any event, the full details for that item ID was cached in memory.


This meant that the inventory itself could be shown almost instantly, and as the mouse was moved over items, they gradually "fleshed out" to the full details. This actually worked pretty well, as you normally want details on one item, not all of them at once. Also, once the full details were received, as they were cached, the hover-over details worked faster and faster in future.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #9 on Fri 26 Jun 2009 09:21 AM (UTC)
Message
Just noticed something. You may want to set the OnPluginClose function to clear out the window made by the plugin. I removed the plugin after poking at it again today, and noticed the window was left there. I was able to remove it by opening and closing the plugin again without checking my inventory at all.

Something simple like this should work
function OnPluginClose()
  WindowShow (GetPluginID() .. "background",  false)
end

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Blainer   (191 posts)  Bio
Date Reply #10 on Fri 26 Jun 2009 11:20 AM (UTC)
Message
Thanks Shaun. I've abandoned all this code now. It was terrible.

I'll have a better version to post here soon...
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


34,650 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.