[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]  General
. . -> [Subject]  Organizing contents of a container

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Organizing contents of a container

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


Pages: 1 2  

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Sun 24 Apr 2011 08:57 PM (UTC)  quote  ]
Message
This is something someone posted that worked on ZMUD and I wanted to figure out how to make it work for MUSHClient...

This is what the game currently displays:

Inside the open large durable burlap travel pack you see: roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, half eaten roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf, roasted verbena leaf


I want it to display:

Inside the open large durable travel pack you see:
20 roasted verbena leaf(s)


I want this to work for all containers, though.

This is what he had for ZMUD:

#TRIGGER {Inside the (*) you see:(*)} {Item.Container=%1;Item.List=%2;#SUB {Inside the @Item.Container you see:};#LOOPDB %Countlist( %replace( %replace( %replace( @Item.List, ", ", "|"), " a ", " "), " an ", " ")) {#SHOW %Val %Key}}


How might this be worded for MUSHClient?
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #1 on Sun 24 Apr 2011 09:38 PM (UTC)  quote  ]

Amended on Sun 24 Apr 2011 09:45 PM (UTC) by Twisol

Message
<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^(Inside the (?:.*?) you see:)( (?:.*))$"
   omit_from_log="y"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>-- Display the container line
Note("%1")

-- Split the list into a table of items, and strip the leading space from each
local items = utils.split("%2", ",")
for i,v in ipairs(items) do
  items[i] = v:sub(2)
end

-- Tabulate a count of each item
local counts = {}
for _,v in ipairs(items) do
  counts[v] = (counts[v] or 0) + 1
end

-- Display each item with its count
for k,v in pairs(counts) do
  Note(("%i %s(s)"):format(v, k))
end</send>
  </trigger>
</triggers>


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


Output:
Inside the open large durable burlap travel pack you see:
1 half eaten roasted verbena leaf(s)
24 roasted verbena leaf(s)

'Soludra' on Achaea

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #2 on Sun 24 Apr 2011 09:43 PM (UTC)  quote  ]

Amended on Sun 24 Apr 2011 09:51 PM (UTC) by Whisk3rz

Message
Thank you.

One thing I did to change this was Checked Omit from Output, and changed "script" to "Script (after omit)" to avoid showing the inventory both ways.

Otherwise, this worked perfect. Much Appreciated.



EDIT! Oh, one more thing, when the container is empty, that space after what's in it is generally just empty. Any way to say if %2=nil, don't display 1 (s)?
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #3 on Sun 24 Apr 2011 09:46 PM (UTC)  quote  ]
Message
Yeah, you'll want to re-import the version from my post, I have a bad habit of editing things after the fact to polish them up. >_>

(The only difference right now is that I also checked Omit from Log and Keep Evaluating, so you could just do that yourself if you want.)

'Soludra' on Achaea

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #4 on Sun 24 Apr 2011 09:52 PM (UTC)  quote  ]
Message
Inside the open forged steel coffer you see:
1 (s)

How do i tell it to not say 1 (s) and maybe say "nothing" if nothing is in there? Normally when i look at a container with nothing it just says...

Inside the open forged steel coffer you see:
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #5 on Sun 24 Apr 2011 10:00 PM (UTC)  quote  ]
Message
Hmm. Change the match pattern to ^(Inside the (?:.*?) you see:)( (?:.+))$ . That makes the trigger not match at all if there's nothing inside.

'Soludra' on Achaea

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #6 on Sun 24 Apr 2011 10:23 PM (UTC)  quote  ]
Message
Perfect! Changed note to ColourNote and made it light gray, so it's not such a sore thumb. but other than that, it seems to work swimmingly.

Thank you once again!
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #7 on Mon 25 Apr 2011 12:44 AM (UTC)  quote  ]
Message
Yep, I just wanted to demonstrate the idea. Glad it works for you! :D

'Soludra' on Achaea

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #8 on Fri 29 Apr 2011 04:23 AM (UTC)  quote  ]
Message
Oh, is there any way to alter the format for when this is only 1 to leave off the count and (s), but still list it?
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #9 on Fri 29 Apr 2011 06:14 AM (UTC)  quote  ]

Amended on Fri 29 Apr 2011 06:17 AM (UTC) by Twisol

Message
for k,v in pairs(counts) do
  var plural = (v != 1 and "(s)" or "")
  Note(("%i %s%s"):format(v, k, plural)
end


This should work. Changes marked in bold.

The and/or trick there is almost (but not quite) identical to the traditional ?: ternary operator, if you have any experience with that. Otherwise, you can consider it similar to:

var plural
if v != 1 then
  plural = "(s)"
else
  plural = ""
end


[EDIT]: Oh, you also wanted to remove the count? I think that would make the output kind of ugly, but sure.
for k,v in pairs(counts) do
  if v == 1 then
    Note(k)
  else
    Note(("%i %s(s)"):format(v, k)
  end
end

'Soludra' on Achaea

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #10 on Fri 29 Apr 2011 01:46 PM (UTC)  quote  ]
Message
I only wanted to remove the count on 1, since some items are worded as "a pair of boots" "some soft linens" "Some marks"

When i look in a container and see "1 some marks" i keep confusing it for it saying there is only 1 mark in that container. That's the equivalent of a penny... haha.
[Go to top] top

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #11 on Fri 29 Apr 2011 01:56 PM (UTC)  quote  ]
Message
Twisol said:

for k,v in pairs(counts) do
  var plural = (v != 1 and "(s)" or "")
  Note(("%i %s%s"):format(v, k, plural)
end




Only tried this part so far, getting an error.

Compile error
World: Isles of Aedin
Immediate execution
[string "Trigger: "]:18: '=' expected near 'plural'

Have it sending to script after omit... could that be causing this?
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #12 on Fri 29 Apr 2011 04:48 PM (UTC)  quote  ]
Message
Nope, I'm just an idiot. Change != to ~=.

'Soludra' on Achaea

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

Posted by Whisk3rz   (17 posts)  [Biography] bio
Date Reply #13 on Sat 30 Apr 2011 02:07 AM (UTC)  quote  ]
Message
Twisol said:

Nope, I'm just an idiot. Change != to ~=.

<triggers>
  <trigger
   enabled="y"
   match="^(Inside the (?:.*?) you see:)( (?:.+))$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>-- Display the container line
ColourNote("lightgray", "black", "%1")

-- Split the list into a table of items, and strip the leading space from each
local items = utils.split("%2", ",")
for i,v in ipairs(items) do
  items = v:sub(2)
end

-- Tabulate a count of each item
local counts = {}
for _,v in ipairs(items) do
  counts[v] = (counts[v] or 0) + 1
end

-- Display each item with its count
for k,v in pairs(counts) do
 var plural = (v ~= 1 and "(s)" or "")
  ColourNote("lightgray", "black", ("%i %s(s)"):format(v, k, plural))
end</send>
  </trigger>
</triggers>


still getting the same error. The issue is with the = after "var plural", it would seem. :-/
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #14 on Sat 30 Apr 2011 03:00 AM (UTC)  quote  ]
Message
No, that's just the first place it noticed there was an error. The real problem is that I've been using Javascript far too much lately, and I used 'var' instead of 'local'. (Go ahead and change that. I promise it will work, or so help me...)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[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.


3,005 views.

This is page 1, subject is 2 pages long: 1 2  [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

[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]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]