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.
 Entire forum ➜ MUSHclient ➜ Getting Started ➜ Video showing how to make an inventory alias

Video showing how to make an inventory alias

Posting of new messages is disabled at present.

Refresh page


Pages: 1  2  3  4  5  6  7  8  9 10  

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #120 on Sun 06 Apr 2014 08:44 PM (UTC)
Message
The wait.lua file should look like this (in part):


-- ----------------------------------------------------------
-- wait.regexp: we call this to wait for a trigger with a regexp
-- ----------------------------------------------------------
function regexp (regexp, timeout, flags)
  local id = "wait_trigger_" .. GetUniqueNumber ()
  threads [id] = assert (coroutine.running (), "Must be in coroutine")
            
  check (AddTriggerEx (id, regexp, 
            "-- added by wait.regexp",  
            bit.bor (flags or 0, -- user-supplied extra flags, like omit from output
                     trigger_flag.Enabled, 
                     trigger_flag.RegularExpression,
                     trigger_flag.Temporary,
                     trigger_flag.Replace,
                     trigger_flag.OneShot),
            custom_colour.NoChange, 
            0, "",  -- wildcard number, sound file name
            "wait.trigger_resume", 
            12, 100))  -- send to script (in case we have to delete the timer)
 
  -- if timeout specified, also add a timer
  if timeout and timeout > 0 then
    local hours, minutes, seconds = convert_seconds (timeout)

    -- if timer fires, it deletes this trigger
    check (AddTimer (id, hours, minutes, seconds, 
                   "DeleteTrigger ('" .. id .. "')",
                   bit.bor (timer_flag.Enabled,
                            timer_flag.OneShot,
                            timer_flag.Temporary,
                            timer_flag.ActiveWhenClosed,
                            timer_flag.Replace), 
                   "wait.timer_resume"))

    check (SetTimerOption (id, "send_to", "12"))  -- send to script

    -- if trigger fires, it should delete the timer we just added
    check (SetTriggerOption (id, "send", "DeleteTimer ('" .. id .. "')"))  

  end -- if having a timeout

  return coroutine.yield ()  -- return line, wildcards
end -- function regexp 

-- ----------------------------------------------------------
-- wait.match: we call this to wait for a trigger (not a regexp)
-- ----------------------------------------------------------
function match (match, timeout, flags)
  return regexp (MakeRegularExpression (match), timeout, flags)
end -- function match 


Important parts in bold. The "flags" argument (in your case trigger_flag.OmitFromOutput) should be passed to "match" which is then passed to "regexp". That then gets passed to AddTriggerEx.

- Nick Gammon

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

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #121 on Sat 20 Sep 2014 06:39 PM (UTC)
Message
I have been trying to get the original alias to work with the game that I play but have not had any success. It only shows a very small Inventory miniwindow with no text. Here is what my inventory looks like.

Inventory:
a rugged iron-buckled leather haversack (45.0 lbs)
 a canvas scavenger's pack (9.0 lbs)
 a bundle of maple (11.0 lbs)
 a bundle of applewood (11.0 lbs)
 a bundle of willow (43.0 lbs)
 a bundle of hickory (79.0 lbs)
 a small quiver of cypress arrows (0.0 lbs)
 a small quiver of beechwood arrows (0.0 lbs)
 a small quiver of bamboo arrows (0.0 lbs)
 
Carrying: 550 items (205.0 | 316.0) lbs.


You will notice that the first item of the inventory is not indented by one space like all of the others. Items can start with "a", "an", "some", " a", etc. How do I change the following code to allow for additional matches:

  -- see if end of inventory

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


Addtionally, I would like to group like items together as the mud I play does not do that automatically. I have no idea on where to start with that.

Thanks for reading.
Top

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #122 on Sat 20 Sep 2014 08:11 PM (UTC)
Message
Ok, I got the window to work by changing it to this:

  -- see if end of inventory

  if not string.match (line, "^%a") then
    if not string.match (line, "^% a") then
      if not string.match (line, "^%an") then
        if not string.match (line, "^% an") then
          if not string.match (line, "^%some") then
            if not string.match (line, "^% some") then
              break
            end -- if
          end -- if
        end -- if
      end -- if
    end -- if
  end -- if


Now, how do I go about sorting the inventory by item if the description matches exactly, including the weight as crafting items can have the same description but different weights?
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #123 on Sat 20 Sep 2014 08:45 PM (UTC)

Amended on Sat 20 Sep 2014 08:46 PM (UTC) by Nick Gammon

Message

    if not string.match (line, "^% a") then


That doesn't look right, there is no "% " in string.match.

You know you can have optional things, eg.


  if not string.match (line, "^%an?") then


Matches "a" and "an".




Quote:

Now, how do I go about sorting the inventory by item if the description matches exactly, including the weight as crafting items can have the same description but different weights?


Write a custom sort function. It has to return true if a is less than b, so it would be like:


function my_sort_function (a, b)

  -- name less than?
  if a.name < b.name then return true end

  -- name greater than?
  if a.name > b.name then return false end
  
  -- names the same, compare weights ...

  -- weight less than
  if a.weight < b.weight then return true end

  -- not less than
  return false

end -- function

- Nick Gammon

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

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #124 on Sat 20 Sep 2014 09:29 PM (UTC)

Amended on Sat 20 Sep 2014 09:56 PM (UTC) by Shady Stranger

Message
Quote:

if not string.match (line, "^% a") then


That doesn't look right, there is no "% " in string.match.

You know you can have optional things, eg.


I realized that I do not have to include "%" at all for it to work. When I had initially tested it out, I had a trigger to omit blank lines. In order to account for it being turned off, I had to ad an additional if statement at the end. This is what it looks like:

  -- see if end of inventory

  if not string.match (line, "^an?") then
    if not string.match (line, "^some") then
      if not string.match (line, "^ an?") then
        if not string.match (line, "^ some") then
          if not string.match (line, "^$") then
            break
          end -- if
        end -- if
      end -- if
    end -- if
  end -- if


Thanks for the tip about multiple about including optional things. It forced me to do some research on regular expressions, much appreciated.

As far as the function to sort the items, that is far beyond my capabilities. I tried copying and pasting your example at the end of the alias but it doesn't work. I get the feeling that there is more that I'm supposed to do with it.

Edit: I figured a few things out between the time I originally posted this and now.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #125 on Sun 21 Sep 2014 12:25 AM (UTC)

Amended on Sun 21 Sep 2014 09:43 PM (UTC) by Nick Gammon

Message
OK, this demonstrates the sorting. Modified code in bold. You can test for an optional space by doing " ?" as shown below.


<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

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


local win = GetPluginID () .. ":inventory"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if

-- request inventory

Send "inventory"


-- wait for inventory to start

local x = wait.match ("Inventory:", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")

-- loop until end of inventory

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


 -- see if end of inventory

  if not string.match (line, "^ ?an?") then
    if not string.match (line, "^ ?some") then
      if not string.match (line, "^$") then
        break
      end -- if
    end -- if
  end -- if

  if styles [1] then
    styles.line = Trim (line)
    styles.weight = tonumber (string.match (line, "%%(([0-9.]+) lbs?%%)"))
    styles [1].text = string.gsub (styles [1].text, "^ ", "")

    -- save inventory line
    table.insert (inv, styles)
    -- work out max width
    max_width = math.max (max_width, WindowTextWidth (win, font, line))
  end -- if at least one style


end -- while loop

local font_height = WindowFontInfo (win, font, 1)

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

-- make window correct size

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Inventory", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5


-- sort them

function my_sort_function (a, b)
  -- name less than?
  if a.line &lt; b.line then return true end
  -- name greater than?
  if a.line &gt; b.line then return false end
  -- names the same, compare weights ...
  -- weight less than
  if a.weight and b.weight then
    if a.weight &lt; b.weight then return true end
  end -- if
  -- not less than
  return false
end -- function

table.sort (inv, my_sort_function)


for i, styles in ipairs (inv) 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 inventory item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </alias>
</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


[EDIT] Allowed for blank lines.

[EDIT] Allowed for "lb" and "lbs" in weight.

- Nick Gammon

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

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #126 on Sun 21 Sep 2014 01:35 AM (UTC)

Amended on Sun 21 Sep 2014 01:36 AM (UTC) by Shady Stranger

Message
I copied and pasted the alias and got several errors (or one long one) when attempting to use the alias.

Inventory:
Error raised in trigger function (in wait module)
stack traceback:
        [string "Alias: "]:51: in function <[string "Alias: "]:5>
Run-time error
World: Shattered Isles
Function/Sub: wait.trigger_resume called by trigger
Reason: processing trigger "wait_trigger_15190"
C:\Program Files\MUSHclient\lua\wait.lua:67: [string "Alias: "]:51: attempt to index field '?' (a nil value)
stack traceback:
        [C]: in function 'error'
        C:\Program Files\MUSHclient\lua\wait.lua:67: in function <C:\Program Files\MUSHclient\lua\wait.lua:59>
a rugged iron-buckled leather haversack (31.0 lbs)
 a canvas scavenger's pack (10.0 lbs)
 
Currency: 1 doubloon

Carrying: 599 items (68.0 | 316.0) lbs.


Edit: Version 4.84
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #127 on Sun 21 Sep 2014 03:12 AM (UTC)
Message
I hadn't allowed for the blank line, so I amended the post above which should now work.

- Nick Gammon

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

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #128 on Sun 21 Sep 2014 02:17 PM (UTC)
Message
Thank you so much. This works great!

I am going to take this and attempt to consolidate the inventory by displaying multiple items on one line. The inventory for the game I'm playing doesn't do this already and the inventory can go on forever as it isn't capped at a certain number of items. Either that, or I will add a scrolling option to the window as I have seen others do.

Thanks again!
Top

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #129 on Sun 21 Sep 2014 06:38 PM (UTC)

Amended on Sun 21 Sep 2014 11:49 PM (UTC) by Shady Stranger

Message
I am getting an error now when I have more than one item in my inventory with matching description and weight.

Inventory:

a pearl-imbedded tin ATC supporter button (1.0 lb)
 a canvas scavenger's pack (10.0 lbs)
 a smooth bloodstone flame necklace (1.0 lb)
 a long lead scepter (1.0 lb)
 a long lead scepter (1.0 lb)
 
Error raised in trigger function (in wait module)
stack traceback:
        [string "Alias: "]:91: in function <[string "Alias: "]:84>
        [C]: in function 'sort'
        [string "Alias: "]:98: in function <[string "Alias: "]:5>
Run-time error
World: Shattered Isles
Function/Sub: wait.trigger_resume called by trigger
Reason: processing trigger "wait_trigger_12348"
C:\Program Files\MUSHclient\lua\wait.lua:67: [string "Alias: "]:91: attempt to compare two nil values
stack traceback:
        [C]: in function 'error'
        C:\Program Files\MUSHclient\lua\wait.lua:67: in function <C:\Program Files\MUSHclient\lua\wait.lua:59>

Carrying: 600 items (70.0 | 316.0) lbs.


EDIT: I removed the weight portion (in bold) of the function below and it seems to be working now.


-- sort them

function my_sort_function (a, b)
  -- name less than?
  if a.line &lt; b.line then return true end
  -- name greater than?
  if a.line &gt; b.line then return false end
  -- names the same, compare weights ...
  -- weight less than
  if a.weight &lt; b.weight then return true end
  -- not less than
  return false
end -- function

table.sort (inv, my_sort_function)
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #130 on Sun 21 Sep 2014 09:42 PM (UTC)
Message
Ach, I hadn't spotted that weight could be "lb" or "lbs".

I changed the regular expression to be "lb?s" so it allows for an optional "s".

Code above modified. Also changed to allow for a line with no weight on it (by checking that the "a" and "b" weight are both not nil).

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #131 on Sun 21 Sep 2014 10:20 PM (UTC)

Amended on Sun 21 Sep 2014 10:25 PM (UTC) by Nick Gammon

Message
You can get a bit fancier if you like. This amended version breaks your inventory into categories, by matching on keywords in the inventory.


<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
require "wait"

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


local win = GetPluginID () .. ":inventory"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if

-- request inventory

Send "inventory"


-- wait for inventory to start

local x = wait.match ("Inventory:", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")

default_category = "Other"

inventory_type = {

  Containers = { "pack", "bag", "sack", },
  Weapons    = { "scepter", "sword", },
  Ammo       = { "arrows", "bullets", },
  Jewels     = { "necklace", "bangle", "bracelet", },

  [default_category] = { },   -- default
} -- end of inventory_type


category_count = 0
for name in pairs (inventory_type) do
  category_count = category_count + 1
end -- for

-- loop until end of inventory

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


 -- see if end of inventory

  if not string.match (line, "^ ?an?") then
    if not string.match (line, "^ ?some") then
      if not string.match (line, "^$") then
        break
      end -- if
    end -- if
  end -- if

  if styles [1] then
    styles.line = Trim (line)
    styles.weight = tonumber (string.match (line, "%%(([0-9.]+) lbs?%%)"))
    styles [1].text = string.gsub (styles [1].text, "^ ", "")

    for category, keywords in pairs (inventory_type) do
      if styles.category then
        break
      end -- if
      for _, item in ipairs (keywords) do
        if string.find (line, item, 1, true) then
          styles.category = category
          break
        end -- if found
      end -- for each item
    end -- for each category

    if not styles.category then
        styles.category = default_category
    end -- if
    
    -- save inventory line
    table.insert (inv, styles)
    -- work out max width
    max_width = math.max (max_width, WindowTextWidth (win, font, line))
  end -- if at least one style


end -- while loop

local font_height = WindowFontInfo (win, font, 1)

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

-- make window correct size

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Inventory", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

-- sort them

function my_sort_function (a, b)

  -- category less than?
  if a.category &lt; b.category then return true end
  -- category greater than?
  if a.category &gt; b.category then return false end
  -- name less than?
  if a.line &lt; b.line then return true end
  -- name greater than?
  if a.line &gt; b.line then return false end
  -- names the same, compare weights ...
  -- weight less than
  if a.weight and b.weight then
    if a.weight &lt; b.weight then return true end
  end -- if
  -- not less than
  return false
end -- function

table.sort (inv, my_sort_function)

old_category = nil

for i, styles in ipairs (inv) do

  if styles.category ~= old_category then
    y = y + font_height
    WindowText (win, font, styles.category, 5, y, 0, 0, ColourNameToRGB  "mediumorchid")
    old_category = styles.category
    y = y + font_height
  end -- if new category
  
  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 inventory item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </alias>
</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Example output:



The part in bold above is the table of keywords. You can add more categories, and inside a category you have one or more words which, if matching, cause the item to go into that category. Once one match is found it stops looking. The default category is "Other" into which all un-matching things go.

- Nick Gammon

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

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #132 on Mon 22 Sep 2014 12:33 AM (UTC)

Amended on Mon 22 Sep 2014 12:38 AM (UTC) by Shady Stranger

Message
Thank you. I always end up looking for something complex and I should know better to look for the simple fixes first. Good news is that I am now reading a beginner's guide to Lua so I can figure this stuff out on my own.

That being said, I do have another question(s). How do I remove duplicate items and show them like this:


FROM THIS:

a long lead scepter (1.0 lb)
a canvas scavenger's pack (30.0 lbs)
a small quiver of beechwood arrows (0.0 lbs)
a canvas scavenger's pack (12.0 lbs)
a long lead scepter (1.0 lb)
a small quiver of beechwood arrows (0.0 lbs)
a canvas scavenger's pack (12.0 lbs)
a canvas scavenger's pack (12.0 lbs

TO THIS:

a canvas scavenger pack (12.0 lbs) x3
a canvas scavenger pack (30.0 lbs)
a long lead scepter (1.0 lb) x2
a small quiver of beechwood arrows (0.0 lbs) x2


I have tried something like this but it seems to have no effect:


if a.line and a.weight == b.line and b.weight then
  table.remove (inv)
end


It's probably clear from this example that I do not have a clear understanding of Lua. What value represents the completed inventory list that prints in the miniwindow?

I was able to look back in previous posts and got the omit from output to work. Now, I'd like to display the inventory in both the miniwindow as well as the output window.

I've tried:


print (inv)


but that's obviously wrong as well.

Any insight you can give is greatly appreciated.

p.s. I love the option to sort into categories. Thank you.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #133 on Mon 22 Sep 2014 03:47 AM (UTC)

Amended on Mon 22 Sep 2014 03:51 AM (UTC) by Nick Gammon

Message
Yes, reading the Lua tutorials will help you make future changes. :)

Your idea of quantities is a good one. This seems to work:


<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
require "wait"

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


local win = GetPluginID () .. ":inventory"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if

-- request inventory

Send "inventory"


-- wait for inventory to start

local x = wait.match ("Inventory:", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")

default_category = "Other"

inventory_type = {

  Containers = { "pack", "bag", "sack", },
  Weapons    = { "scepter", "sword", },
  Ammo       = { "arrows", "bullets", },
  Jewels     = { "necklace", "bangle", "bracelet", },

  [default_category] = { },   -- default
} -- end of inventory_type


category_count = 0
for name in pairs (inventory_type) do
  category_count = category_count + 1
end -- for

-- for duplicates
existing_items = { }

-- loop until end of inventory

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


 -- see if end of inventory

  if not string.match (line, "^ ?an?") then
    if not string.match (line, "^ ?some") then
      if not string.match (line, "^$") then
        break
      end -- if
    end -- if
  end -- if

  if styles [1] then
    line = Trim (line)
    styles.line = line
    styles.weight = tonumber (string.match (line, "%%(([0-9.]+) lbs?%%)"))
    styles [1].text = string.gsub (styles [1].text, "^ ", "")

    for category, keywords in pairs (inventory_type) do
      if styles.category then
        break
      end -- if
      for _, item in ipairs (keywords) do
        if string.find (line, item, 1, true) then
          styles.category = category
          break
        end -- if found
      end -- for each item
    end -- for each category

    if not styles.category then
        styles.category = default_category
    end -- if
    
    -- look for a duplicate
    item_number = existing_items [line]
    -- if found, increase its quantity
    if item_number then
      inv [item_number].quantity = inv [item_number].quantity + 1
    else
      styles.quantity = 1  -- start with one of them
      existing_items [line] = #inv + 1  -- remember its new position
      -- save inventory line
      table.insert (inv, styles)
      -- work out max width
      max_width = math.max (max_width, WindowTextWidth (win, font, line))
    end -- if
    
  end -- if at least one style


end -- while loop

local font_height = WindowFontInfo (win, font, 1)

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

-- make window correct size

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Inventory", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

-- sort them

function my_sort_function (a, b)

  -- category less than?
  if a.category &lt; b.category then return true end
  -- category greater than?
  if a.category &gt; b.category then return false end
  -- name less than?
  if a.line &lt; b.line then return true end
  -- name greater than?
  if a.line &gt; b.line then return false end
  -- names the same, compare weights ...
  -- weight less than
  if a.weight and b.weight then
    if a.weight &lt; b.weight then return true end
  end -- if
  -- not less than
  return false
end -- function

table.sort (inv, my_sort_function)

old_category = nil

for i, styles in ipairs (inv) do

  if styles.category ~= old_category then
    y = y + font_height
    WindowText (win, font, styles.category, 5, y, 0, 0, ColourNameToRGB  "mediumorchid")
    old_category = styles.category
    y = y + font_height
  end -- if new category
  
  local x = 5
  for _, style in ipairs (styles) do
    x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
    if styles.quantity &gt; 1 then
      WindowText (win, font, string.format (" x%i", styles.quantity), x, y, 0, 0, ColourNameToRGB  "lightgreen")
    end -- if
  end -- for
  y = y + font_height

end -- for each inventory item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </alias>
</aliases>



Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Modified code in bold. I used a separate table (existing_items) to detect duplicates. Since the weight is part of the line we don't have to test for that separately. If a line is a duplicate of an existing one, we just add one to the quantity for the existing item. Otherwise we create a new one and assign a quantity of one.

Then in the printing section we print any quantities greater than one.


- Nick Gammon

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

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #134 on Mon 22 Sep 2014 10:13 PM (UTC)

Amended on Mon 22 Sep 2014 10:34 PM (UTC) by Shady Stranger

Message
This is phenomenal. I made a change to allow for the quantity. It was cutting off before.


local window_width = max_width + 40


It's also printing the quantity twice which is odd because it doesn't look like it should be.

[img]http://i60.tinypic.com/jkd6de.jpg[/img]

As you can see by the amount of items that I have in my inventory at the moment, this is a massive help without having to scroll through it to find items.

Edit: Image isn't showing. The quantities are at the end where they should be but they are also mixed in with the items at the very beginning of each line.
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.


434,502 views.

This is page 9, subject is 10 pages long:  [Previous page]  1  2  3  4  5  6  7  8  9 10  [Next page]

Posting of new messages is disabled at present.

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.