[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Getting Started
. . -> [Subject]  Video showing how to make an inventory alias
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Video showing how to make an inventory alias

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


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

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Sat 02 Jan 2010 03:00 AM (UTC)  quote  ]

Amended on Tue 26 Nov 2013 02:19 AM (UTC) by Nick Gammon

Message
I have made a 2-part series of videos showing how to make an alias that requests your inventory and shows it in miniwindow on the top right-hand corner of your screen.

This illustrates something that is often asked: "how do I capture multiple lines?".

The alias uses the "wait" module described here:

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

More details about the various miniwindow functions are here:

http://www.gammon.com.au/mw

The videos are here:



The alias shown in the videos is 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 ("You are carrying:", 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, "^     ") then
    break
  end -- if

  -- save inventory line
  table.insert (inv, 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 * (#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

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.


The second alias (to hide the window) is as follows:


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

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

WindowShow (win, false)

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


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


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 02 Jan 2010 03:12 AM (UTC)  quote  ]

Amended on Tue 26 Nov 2013 02:20 AM (UTC) by Nick Gammon

Message
Part 1 embedded copy below:




Part 2 embedded copy below:





- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 03 Jan 2010 01:02 AM (UTC)  quote  ]

Amended on Sun 03 Jan 2010 08:34 PM (UTC) by Nick Gammon

Message
You can modify the alias shown to omit the inventory from the main window. To do this you need to modify the supplied wait.lua file in the lua folder of you MUSHclient installation.

Near the end of the file, change "match" and "regexp" as shown below (you can just replace them) ... the changes are in bold:


-- ----------------------------------------------------------
-- 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.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 


This lets you pass down extra flags to the trigger generated by the "match" function. The extra flags can be used to turn on "omit from output".

Then in the alias shown in the earlier post, change the two places it calls wait.match to add in the omit-from-output flag, like this:


local x = wait.match ("You are carrying:", 10, trigger_flag.OmitFromOutput)


...


  local line, wildcards, styles = wait.match ("*", 0, trigger_flag.OmitFromOutput)


Now when you type "inv" only the miniwindow refreshes, and you don't see the inventory scroll by.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 03 Jan 2010 01:13 AM (UTC)  quote  ]
Message
I mentioned in the video that you may need to detect when your inventory changes. Here is a partial way of doing that:


<triggers>
  <trigger
   enabled="y"
   match="^You (drop|get|buy) .+\.$"
   regexp="y"
   send_to="10"
   sequence="100"
  >
  <send>inv</send>
  </trigger>
</triggers>


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


This simple trigger detects when the MUD says you drop (or get, or buy) something, and then does "inv" which forces the alias to re-obtain your inventory.


Also, further testing reveals that sometimes the alias doesn't work, if a prompt appears before the inventory, like this:


<24hp 145m 110mv> <#21043> You are carrying:
     (Magical) a finely honed sword
     (Magical) a pitch-black longsword which flames brightly
     (Magical) (Glowing) a rune-covered bag
     a loaf of bread
     a big chunk of beef
     a cooked turkey
     a slice of salami
     a chocolate cake
     an iron bracer
     an iron shield
     an iron visor
     a bottle of milk
     a cup of lemonade
     a wheel of cheese
     a steel dagger


The extra stuff before "You are carrying:" stops the trigger match. One way around that is to add a wildcard, like this:


local x = wait.match ("*You are carrying:", 10)


Now extra stuff at the front, like a prompt, won't cause the match to fail.





- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Onoitsu2   USA  (246 posts)  [Biography] bio
Date Reply #4 on Mon 04 Jan 2010 07:49 AM (UTC)  quote  ]
Message
Now to get the Widget Framework working to the point that each item in the list is clickable, and draggable, to allow for 'put X in Y'.

-Onoitsu2
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Mon 04 Jan 2010 07:57 AM (UTC)  quote  ]
Message
That's something I'd love to do, but it will probably require a fair bit of extra infrastructure. Even better would be some way for one plugin to supply widgets, and another to use those widgets. But that's a fair ways off.

I'm really glad to see someone else hopeful about the framework. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Holliday   USA  (3 posts)  [Biography] bio
Date Reply #6 on Wed 20 Jan 2010 03:47 PM (UTC)  quote  ]

Amended on Wed 20 Jan 2010 03:52 PM (UTC) by Holliday

Message

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


When playing Aard items get joined together and this actually breaks the loop a little early,

For example

     (K) (Magic) (Glow) (Hum) <(=Misc=)> (47)
     (K) (Magic) (Glow) (Hum) <(=Portals=)> (47)
     (K) (Magic) (Glow) (Hum) <(=AardEq=)> (47)
     (K) (Magic) (Glow) (Hum) <(=Potions=)> (47)
( 4) (K) (Magic) (Glow) (Hum) Testament of the <(=Watchmen=)> (121)

only puts the following in the window

     (K) (Magic) (Glow) (Hum) <(=Misc=)> (47)
     (K) (Magic) (Glow) (Hum) <(=Portals=)> (47)
     (K) (Magic) (Glow) (Hum) <(=AardEq=)> (47)
     (K) (Magic) (Glow) (Hum) <(=Potions=)> (47)

My question is would it be possible to change the condition to line, "^ " OR "^(*) "then
Im sure thats not the proper syntax, but the idea is there
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Wed 20 Jan 2010 07:15 PM (UTC)  quote  ]

Amended on Wed 20 Jan 2010 07:16 PM (UTC) by Nick Gammon

Message
Aardwolf actually makes it very easy, because you can get the MUD to send you special tags around your inventory for this exact reason. To turn it on type:


tags inv on


Once you have turned inventory tags on, you see this:


{inventory}
     a short stabbing sword (44)
     (K) (Glow) (Hum) a long sleeved Aard Zoo tshirt (21)
( 2) (>Whispers of the Earth<) (41)
     (K) (Glow) (Hum) -)Mask of Prediction(- (41)
( 3) (Glow) a bright ball of light (0)
( 3) henchman's leather vest (54)
( 5) a six shot rifle (54)
     henchman's leather vest (56)
     the scorpion style (39)
     the centipede style (41)
     (K) the iron head style (44)
     (K) chin kang palm (35)
( 2) (K) a small bag (0)
     (K) ashnod's Battlegear (35)
     (Glow) a heavy slab of granite (36)
     (K) (Hum) Vladia's Shopping List (1)
     (K) a hemp bracelet (20)
{/inventory}


Then all you have to do is change the way you find the start and the end of your inventory. For example, change:


-- wait for inventory to start

local x = wait.match ("You are carrying:", 10)


to:


-- wait for inventory to start

local x = wait.match ("{inventory}", 10, trigger_flag.OmitFromOutput)


and:


-- see if end of inventory

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


to:


-- see if end of inventory

  if string.match (line, "{/inventory}", trigger_flag.OmitFromOutput) then
    break
  end -- if


Note that the word "not" is gone from my second example, as we now match for finding something to see the end of the inventory, rather than not finding something.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Drindra   (3 posts)  [Biography] bio
Date Reply #8 on Wed 20 Jan 2010 08:55 PM (UTC)  quote  ]
Message
hi ,

love your tutorial vids.

i just tried this one tho put when i copy pasted it and tried typing inv it gave an error, says 'required' is a nil value ?

how can i repair this error ?

thank you :)
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Wed 20 Jan 2010 09:51 PM (UTC)  quote  ]
Message
Can you please copy and paste the actual error? That will help sort it out.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Holliday   USA  (3 posts)  [Biography] bio
Date Reply #10 on Thu 21 Jan 2010 12:11 AM (UTC)  quote  ]
Message
I have turned inventory tags on and altered the by copy/paste the changes you suggested
display is
{inventory}
     (K) (Magic) (Glow) (Hum) a demon school backpack (158)
     (K) (Magic) (Glow) (Hum) a Bag of Aardwolf (47)
     (K) (Magic) (Glow) (Hum) <(=Misc=)> (47)
     (K) (Magic) (Glow) (Hum) <(=Portals=)> (47)
     (K) (Magic) (Glow) (Hum) <(=AardEq=)> (47)
     (K) (Magic) (Glow) (Hum) <(=Potions=)> (47)
( 4) (K) (Magic) (Glow) (Hum) Testament of the <(=Watchmen=)> (121)
     (K) (Magic) (Hum) Aarianna's Testament (100)
{/inventory}


Does not gag, or create window for 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, 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 (win, font, "Inventory")

-- loop until end of inventory

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

-- see if end of inventory

  if string.match (line, "{/inventory}", trigger_flag.OmitFromOutput) then
    break
  end -- if

  -- save inventory line
  table.insert (inv, 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 * (#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

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>
    <alias
   match="noinv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

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

WindowShow (win, false)

</send>
  </alias>
</aliases>
<triggers>
  <trigger
   enabled="y"
   match="^You (drop|get|buy) .+\.$"
   regexp="y"
   send_to="10"
   sequence="100"
  >
  <send>inv</send>
  </trigger>
</triggers>


Seems simple, also tried \{inventory\} but that didnt help either
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Thu 21 Jan 2010 02:03 AM (UTC)  quote  ]
Message
Oops. I made a mistake on the second change.

I meant:


-- loop until end of inventory

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

-- see if end of inventory

  if string.match (line, "{/inventory}") then
    break
  end -- if



Here is the whole alias, it seems to work OK for me now:


<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, 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 (win, font, "Inventory")

-- loop until end of inventory

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

-- see if end of inventory

  if string.match (line, "{/inventory}") then
    break
  end -- if

  -- save inventory line
  table.insert (inv, 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 * (#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

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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Drindra   (3 posts)  [Biography] bio
Date Reply #12 on Tue 26 Jan 2010 04:23 PM (UTC)  quote  ]
Message
Nick Gammon said:

Can you please copy and paste the actual error? That will help sort it out.


hi , sorry for the late reply.

this is the error that pops up.

C:\MUDS\aardwolf\MUSHclient\lua\wait.lua:153: [string "Alias: "]:11: attempt to call global 'WindowInfo' (a nil value)
stack traceback:
[C]: ?
C:\MUDS\aardwolf\MUSHclient\lua\wait.lua:153: in function 'make'
[string "Alias: "]:5: in main chunk



does it has something to do with the client i downloaded ? it was the one Aardwold offered on their website ? i downloaded that since it was already configured with lots of stuff like stats , map and chat.

but then this error pops up when i want to make that miniwindow on Materia Magica...

anyway , i hope this helps.

cheers
[Go to top] top

Posted by Nick Gammon   Australia  (19,628 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Tue 26 Jan 2010 08:49 PM (UTC)  quote  ]

Amended on Wed 27 Jan 2010 12:01 AM (UTC) by Nick Gammon

Message
Yes, probably you have a client that doesn't support miniwindows. The Aardwolf client plugins were pretty specific to their tags, you are better off downloading the latest one from this site. You can install on top of the Aardwolf one, it is basically the same program, you just have an earlier version.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Drindra   (3 posts)  [Biography] bio
Date Reply #14 on Thu 28 Jan 2010 08:04 PM (UTC)  quote  ]
Message
oh i c,

thanks :)
[Go to top] 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.


66,548 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]