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 ➜ General ➜ Organizing contents of a container

Organizing contents of a container

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


Pages: 1 2  

Posted by Whisk3rz   (17 posts)  Bio
Date Sun 24 Apr 2011 08:57 PM (UTC)
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?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Sun 24 Apr 2011 09:38 PM (UTC)

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
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #2 on Sun 24 Apr 2011 09:43 PM (UTC)

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Sun 24 Apr 2011 09:46 PM (UTC)
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
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #4 on Sun 24 Apr 2011 09:52 PM (UTC)
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:
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #5 on Sun 24 Apr 2011 10:00 PM (UTC)
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
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #6 on Sun 24 Apr 2011 10:23 PM (UTC)
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!
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #7 on Mon 25 Apr 2011 12:44 AM (UTC)
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
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #8 on Fri 29 Apr 2011 04:23 AM (UTC)
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?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #9 on Fri 29 Apr 2011 06:14 AM (UTC)

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
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #10 on Fri 29 Apr 2011 01:46 PM (UTC)
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.
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #11 on Fri 29 Apr 2011 01:56 PM (UTC)
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?
Top

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

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Whisk3rz   (17 posts)  Bio
Date Reply #13 on Sat 30 Apr 2011 02:07 AM (UTC)
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. :-/
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #14 on Sat 30 Apr 2011 03:00 AM (UTC)
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
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.


74,166 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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.