Need help with a simple trigger.

Posted by Deacla on Mon 05 Jul 2010 05:29 PM — 25 posts, 89,802 views.

USA #0
How can i create a trigger for this string:

     a glossy lime scroll (new)

That appends the name of the spell that is scribed on that scroll just behind the word 'scroll' and in front of '(new)', thusly:

     a glossy lime scroll ARMOR (new)

I would like this effect to be in-line in the output window without messing with the lines default colors. As i have it now, i have made a simple trigger that just sends a note to the output window with the spell name but it is on the next line and becomes annoying.

A gnomish miner's bag contains:
     a glossy lime scroll (new)
           ARMOR
(  2) an unusual swamp flower
     a nightshade mushroom
     an ivory-yellow papyrus scroll (new)
           BLINDNESS
     a charcoal lambskin scroll (new)
           REVEAL
( 20) a blackjack voucher notated with a little '500' (new)
(  7) a copper-colored scroll (new)
           IDENTIFY

Any help is greatly appreciated.



edit: small grammar fix
Amended on Mon 05 Jul 2010 05:34 PM by Deacla
USA #1
Try This... It shows the concept, it compiles, but I didn't actually test it out. (Coded on faith!)



<triggers>
  <trigger
   enabled="y"
   match="^(?: \([\s\d]+\))?\s+a ([\w\s-]+) scroll \(new\)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>ScrollTypes = {
["glossy lime"] = "ARMOR",
["ivory-yellow papyrus"] = "BLINDNESS",
["charcoal lambskin"] = "REVEAL",
["copper-colored"] = "IDENTIFY",
}
if ScrollTypes["%1"] then
  ColourNote(TriggerStyleRuns[1].textcolour, TriggerStyleRuns[1].backcolour,
     "a %1 scroll " .. ScrollTypes["%1"] .. " (new)")
else
  ColourNote(TriggerStyleRuns[1].textcolour, TriggerStyleRuns[1].backcolour,
     "%0")
end</send>
  </trigger>
</triggers>
Amended on Mon 05 Jul 2010 06:01 PM by WillFa
USA #2
I changed the code a little to this:

<triggers>
  <trigger
   enabled="y"
   match="^(?: \([\s\d]+\))?\s+([\w\s-]+) scroll \(new\)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >

<send>ScrollTypes = {
	["a glossy lime"] = "ARMOR",
	["an ivory-yellow papyrus"] = "BLINDNESS",
	["a charcoal lambskin"] = "REVEAL",
	["a copper-colored"] = "IDENTIFY",
	}

  if ScrollTypes["%1"] then
    ColourNote(TriggerStyleRuns[1].textcolour, TriggerStyleRuns[1].backcolour,
     "%0 " .. ScrollTypes["%1"])

  else
    ColourNote(TriggerStyleRuns[1].textcolour, TriggerStyleRuns[1].backcolour,
     "%0")
  end
</send>

  </trigger>
</triggers>


The placement is great but none of the original line colors come through. That would be excellent.
USA #3
Give this a try. Written on faith, just like WillFa's.


<triggers>
  <trigger
   enabled="y"
   match="^(?: \([\s\d]+\))?\s+([\w\s-]+) scroll \(new\)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >

<send>ScrollTypes = {
	["a glossy lime"] = "ARMOR",
	["an ivory-yellow papyrus"] = "BLINDNESS",
	["a charcoal lambskin"] = "REVEAL",
	["a copper-colored"] = "IDENTIFY",
	}
  for _,v in ipairs(TriggerStyleRuns) do
    ColourTell(v.textcolour, v.backcolour, v.text)
  end
  
  if ScrollTypes["%1"] then
    local last = TriggerStyleRuns[#TriggerStyleRuns]
    ColourNote(last.textcolour, last.backcolour, " " .. ScrollTypes["%1"])
  end
</send>

  </trigger>
</triggers>
Amended on Mon 05 Jul 2010 06:56 PM by Twisol
USA #4
Same exact result. Trigger works and appends the spell name, but it's stuck in the normal world note color. none of the original comes through.
USA #5
That's very odd. As you can probably tell, we're actually accessing the style runs the original line had.

Only thing that comes to mind is, make sure you delete old versions of the trigger before you import the new one.
Amended on Mon 05 Jul 2010 07:17 PM by Twisol
USA #6
well i placed the trigger code in it's own little plugin and deleted all the previous simple triggers i had. i even restarted MUSH. Am i supposed to have the code somewhere else?

I can see what's supposed to be happening and looked up the commands for clarification. It's just not working as advertised. I'm running version 4.43 if that matters.
USA #7
Deacla said:
well i placed the trigger code in it's own little plugin and deleted all the previous simple triggers i had. i even restarted MUSH. Am i supposed to have the code somewhere else?

That should probably work...

Deacla said:
I can see what's supposed to be happening and looked up the commands for clarification. It's just not working as advertised. I'm running version 4.43 if that matters.

I don't remember any style-run changes from 4.43 on, but it's not out of the question...

One moment, I'm going to test this trigger out.
USA #8
Looking into it, the trigger wasn't even matching. But I just realized a new problem. It'll be a bit.. complex to figure out how to "splice" some content into a line without throwing off the line styles. If we didn't have to worry about the line styles, we could have two more captures in the trigger - one for stuff before the insertion point, and one for stuff after it - and just Note it out. But we're relying on the styles list to re-print the line, and there's no shared context between it and the trigger matches.

If you're okay with the line being one solid color, that's very easy.


Also, I rewrote the match pattern. Seems to work fine now.

<triggers>
  <trigger
   enabled="y"
   match="^((?:\(\s*\d+\))?\s*(.*?) scroll) (\(new\))$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>ScrollTypes = {
  ["a glossy lime"] = "ARMOR",
  ["an ivory-yellow papyrus"] = "BLINDNESS",
  ["a charcoal lambskin"] = "REVEAL",
  ["a copper-colored"] = "IDENTIFY",
}

if ScrollTypes["%2"] then
  ColourNote("white", "black", "%1 " .. ScrollTypes["%2"] .. " %3")
else
  for _,v in ipairs(TriggerStyleRuns) do
    ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), v.text)
  end
  Note() -- finish the line
end</send>
  </trigger>
</triggers>


EDIT: Fixed an issue that was, in retrospect, a bit obvious: the textcolour and backcolor items are numbers in RGB format, but ColourTell only accepts color names. Fixed above.
Amended on Mon 05 Jul 2010 07:48 PM by Twisol
USA #9
made a couple changes thinking that it may make it easier with this format to keep the colors also changed the textcolour to match my main text colour in case an actual matching can't be worked out..

<triggers>
  <trigger
   enabled="y"
   match="^((?:\(\s*\d+\))?\s*(.*?) scroll) (\(new\))$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>ScrollTypes = {
  ["a glossy lime"] = "ARMOR",
  ["an ivory-yellow papyrus"] = "BLINDNESS",
  ["a charcoal lambskin"] = "REVEAL",
  ["a copper-colored"] = "IDENTIFY",
}

if ScrollTypes["%2"] then
  ColourNote("silver", "black", "%1 " .. " %3    " .. ScrollTypes["%2"])
else
  for _,v in ipairs(TriggerStyleRuns) do
    ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), v.text)
  end
  Note() -- finish the line
end</send>
  </trigger>
</triggers>

If it would make it easier to keep the styles by appending the spellname all the way to the end as in this example:

A gnomish miner's bag contains:
(  7) a copper-colored scroll  (new)    IDENTIFY
( 20) a blackjack voucher notated with a little '500' (new)
     a glossy lime scroll  (new)    ARMOR
(  2) an unusual swamp flower
     a nightshade mushroom
     an ivory-yellow papyrus scroll  (new)    BLINDNESS
     a charcoal lambskin scroll  (new)    REVEAL
USA #10
Deacla said:
If it would make it easier to keep the styles by appending the spellname all the way to the end as in this example:

A gnomish miner's bag contains:
(  7) a copper-colored scroll  (new)    IDENTIFY
( 20) a blackjack voucher notated with a little '500' (new)
     a glossy lime scroll  (new)    ARMOR
(  2) an unusual swamp flower
     a nightshade mushroom
     an ivory-yellow papyrus scroll  (new)    BLINDNESS
     a charcoal lambskin scroll  (new)    REVEAL


Yeah, that makes it much easier:

<triggers>
  <trigger
   enabled="y"
   match="^((?:\(\s*\d+\))?\s*(.*?)\s*scroll)\s*(\(new\))$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>ScrollTypes = {
  ["a glossy lime"] = "ARMOR",
  ["an ivory-yellow papyrus"] = "BLINDNESS",
  ["a charcoal lambskin"] = "REVEAL",
  ["a copper-colored"] = "IDENTIFY",
}

for _,v in ipairs(TriggerStyleRuns) do
  ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), v.text)
end

if ScrollTypes["%2"] then
  ColourTell("silver", "black", "\t" .. ScrollTypes["%2"])
end

Note() -- finish the line</send>
  </trigger>
</triggers>
USA #11
That's it right there Twisol. thx very much.

Also i will post a copy of the full code when i get all the scrolls programmed in.
USA #12
As promised, here is the Materia Magica Scroll to Spell Translator for Mushclient.

https://docs.google.com/leaf?id=0B9VJQA8iYaroYjY2MzY0NTYtNTFkOC00YWRlLWIwYjQtMWUwZWE3ODFkZjA5&sort=name&layout=list&num=50
USA #13
One last thing. I'm having trouble turning this string into regexp so that it also fires the scroll trigger.

AUCTION: Deacla has put a luminescent mother-of-pearl scroll up for auction. Minimum bid is 100 gp.

I've tried myself and can get it to install but it never fires. any help would be great.

Also how can i put both strings into one trigger so it says either fire on this or this.... or this potentially?

edit: this is what i have so far to show you the variable aspects of the string.

^AUCTION\:\s*(.*?)\s*has put(\s*(.*?)\s*scroll) up for auction\. Minimum bid is (.+) gp\.$
Amended on Wed 07 Jul 2010 02:52 AM by Deacla
Australia Forum Administrator #14
That regexp fired for me on your test string.

If you want to fire both, make sure they both have "keep evaluating" set.
Australia Forum Administrator #15
Deacla said:

Also how can i put both strings into one trigger so it says either fire on this or this.... or this potentially?


Match on: (this|that)
USA #16
Is that line wrapped/split into two lines when you see it in MUSHclient? If it is, do you know if the server is splitting it, or if MUSHclient is doing the wrapping?

If the server is splitting the line and sending it out that way, then MUSHclient gets it as two separate lines, meaning you need two separate triggers (or one multiline trigger) to match it. If possible, disable the server-side wrapping (you can always configure client-side wrapping in Game -> Configure -> Output) so MUSHclient gets it as one line.
USA #17
It's all one line. It's Mush doing the wrapping.

@Nick: It is firing the trigger but I don't think the correct data is being sent to the ScrollTypes variable. so it doesn't append anything to the end.
Australia Forum Administrator #18

<triggers>
  <trigger
   enabled="y"
   match="^AUCTION\:\s*(.*?)\s*has put(\s*(.*?)\s*scroll) up for auction\. Minimum bid is (.+) gp\.$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Fired!
%%1 = %1
%%2 = %2
%%3 = %3
%%4 = %4</send>
  </trigger>
</triggers>


I get:


Fired!
%1 = Deacla
%2 =  a luminescent mother-of-pearl scroll
%3 = a luminescent mother-of-pearl
%4 = 100



Note that %2 has a leading space.
USA #19
Thank you for showing me where i was making the mistake. I changed the trigger to:

^AUCTION\:\s*(.*?)\s*has put\s*(.*?)\s*scroll up for auction\. Minimum bid is (.+) gp\.$

and now it works great. had to remove that leading space. thank you again.
USA #20
Thinking on this further I found I could make it much simpler. I'm trying to get it to match on basically any string with the word scroll in it and match it against the database. this is what i got.

^(.*?)\s*((a|an)\s*(.*?))\s*scroll(.*)$

This still works in the inventory screen, and in bags as it did originally but no where else. How can I describe the following:

^(anything) ((a|an)scrolltype) scroll(anything)$


edit: it does work in some other strings, bot not all other strings.
Amended on Wed 07 Jul 2010 04:51 AM by Deacla
USA #21
Deacla said:
This still works in the inventory screen, and in bags as it did originally but no where else. How can I describe the following:

^(anything) ((a|an)scrolltype) scroll(anything)$


\b((?:a|an).*? scroll)\b

That'll match and capture "a foo scroll". I'm using a non-capturing group for the a|an, signified by the ?: at the start.

The ^ and $ are start and end anchors. Remove them, and it'll check for it anywhere in a line.

I'm also using \b here, so that it doesn't match "bara foo scrollbaz", for example. The \b stands for 'word boundary'.
Amended on Wed 07 Jul 2010 04:57 AM by Twisol
USA #22
\ban? (.+?) scroll\b


Would be a simpler pattern.
USA #23
Thank you all for the help. i ended up changing it again so that it matches on any scroll anywhere that is spelled correctly. I also had to change the data a bit so that I could match a, an, A, and An. didn't realize mush was so case-sensitive. here is the final

(?:.*|)\b(?:an|a|A|An)\b\s*\b(.*? scroll)\b

for the entire updated Materia Magica Scroll to Spell Translator please go here:

https://docs.google.com/leaf?id=0B9VJQA8iYaroM2U2Y2JmOTAtMjg1NS00ZjczLWI3NGMtZjU5YzU0MWQyMmM4&sort=name&layout=list&num=50
Australia Forum Administrator #24
Deacla said:

I also had to change the data a bit so that I could match a, an, A, and An. didn't realize mush was so case-sensitive.


It is the PCRE that is case-sensitive. However you can turn it off (in the trigger dialog) or in the pattern, eg.


(?:(?i)an|a)


The (?i) turns off case-sensitivity inside the brackets.