Name Trigger

Posted by Jdiddleymspot on Fri 13 Aug 2010 03:52 PM — 18 posts, 75,126 views.

#0
Hi, I don't have a clue about triggers or anything to do with how to code on MUSHclient.

Basically, what I want is for when a PC or NPC description is displayed on screen, it will put his/her/its name in brackets after the description. How do I do this?

Thanks for the help!
#1
could you give us an example of what your seeing. would be easier to help.
do you see something like?

name
A tall human, with blue eyes and red hair.

or something more complex?
#2
Hi, basically the mud sends ^me something like...

A blue eyed, tall man is here.

I want it to say....

A blue eyed, tall man is here (Barry)
#3
Please help :)
Australia Forum Administrator #4
Jdiddleymspot said:

Hi, basically the mud sends ^me something like...

A blue eyed, tall man is here.

I want it to say....

A blue eyed, tall man is here (Barry)


How do we know, from what you posted, to put the name Barry there?
#5
Can't it trigger on the description of the PC?
#6
If you need more information about what the MUD sends, then this is it:-

MUD said:

A Room is Here
Exits: North, East, South, West

Room description goes here. Roughly a paragraph in length.

A table is here.
An arrow is here (x3).
A blue eyed man with short hair is here.
Amended on Sat 14 Aug 2010 12:31 PM by Jdiddleymspot
#7
Can't it trigger on the description of the PC?
Australia Forum Administrator #8
Jdiddleymspot said:


Posted at Saturday, 02:52 AM Australian time

Basically, what I want is for when a PC or NPC description is displayed on screen, it will put his/her/its name in brackets after the description. How do I do this?


...

Jdiddleymspot said:

Please help :)


...

Jdiddleymspot said:


Posted at Saturday, 10:01 PM Australian time

Can't it trigger on the description of the PC?


...

Jdiddleymspot said:


Posted at Sunday, 06:11 AM Australian time

Can't it trigger on the description of the PC?


Making multiple posts won't get your questions answered faster. You asked a question at 10 PM my time, and then tried to hurry us up at 6 AM my time. Personally I was asleep.

When you made your initial post you were asked to supply, amongst other things, the scripting language you use, and the version of MUSHclient. You haven't done so.

I asked this:

Nick Gammon said:

How do we know, from what you posted, to put the name Barry there?


You haven't answered that.

Are you saying that every time you see this line:


A blue eyed man with short hair is here.


You want to replace it with:


A blue eyed man with short hair is here. (Barry)


Is that just because you happen to know that this person is Barry?

Is that description part of a longer description (like some MUDs do, with many people listed in one paragraph)?

It would help to know which MUD you are talking about.

If you are talking about a longer paragraph then an actual example would help too.

Are you planning to replace many descriptions with names, or just a single one (Barry)?

Sure, it can be done by triggering on the description, assuming you happen to know which name matches which description (which you didn't say).

But if you have hundreds of them there might be a better way. And if the descriptions are inside a big paragraph then the paragraph would have to be broken down into individual descriptions.

Have you read the FAQ?

The people who visit these forums are generally very helpful, and will be happy to help you tidy up an attempt that you have made. But they need information to work on, and generally like you to show you have tried to solve the problem yourself.
Amended on Sat 14 Aug 2010 10:14 PM by Nick Gammon
#9
Firstly, I'm sorry if I came across pushy. I really didn't mean to sound that way. I just thought that maybe my post would get lost amongst the others. I apologize.

Here is what I posted after I asked if a trigger can just trigger on a PC description:-

Jdiddleymspot said:

If you need more information about what the MUD sends, then this is it:-

MUD said:

A Room is Here
Exits: North, East, South, West

Room description goes here. Roughly a paragraph in length.

A table is here.
An arrow is here (x3).
A blue eyed man with short hair is here.



I'm sorry, but I don't know what scripting language I use. I AM really a total newbie at this sort of thing. If it helps, I'm trying to use the GAME>CONFIGURE>TRIGGERS box.

You are indeed correct that upon seeing this:-

A blue eyed man with short hair is here.

I want to see this:-

A blue eyed man with short hair is here (Barry).

The brackets part (Barry) I will input myself. There is no way for MUSHCLIENT to know his name is Barry, but I would like his name to show after I tell the program his name is barry.

I've tried using the FAQ, but it's not so easy. This is what I've figure out so far with the FAQ and just by messing around....

---------------------------------
Trigger: A blue eyed man with short hair *

Tick Ignore case & Omit from output

Send box:
A blue eyed man with short hair %1 (Barry)

Send to: Output
-------------------

It seems to work, but the output is always blue. The normal color for mobiles on the MUD is always purple.

I'm playing Shadows of Isildur (www.middle-earth.us) A Diku mud as far as I'm aware, though I don't actually know what that means :(

This is about as far as I've got. Once again, sorry for coming across pushy. I really didn't mean to.

John

Ps. I'm using MushClient v.4.43


Amended on Mon 16 Aug 2010 06:44 PM by Jdiddleymspot
Australia Forum Administrator #10
Jdiddleymspot said:

I've tried using the FAQ, but it's not so easy. This is what I've figure out so far with the FAQ and just by messing around....

---------------------------------
Trigger: A blue eyed man with short hair *

Tick Ignore case & Omit from output

Send box:
A blue eyed man with short hair %1 (Barry)

Send to: Output
-------------------

It seems to work, but the output is always blue.


It helps to use the Copy button:

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.



However you are on the right track. It is in blue because sending to output defaults to the world "note" colour.

To control the colour, you can script a short ColourNote instead, like this:


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="A blue eyed man with short hair *"
   omit_from_output="y"
   send_to="14"
   sequence="110"
  >
  <send>ColourNote ("purple", "", "%0 (Barry)")</send>
  </trigger>
</triggers>


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


I used %0 which will echo the entire original line, and then added (Barry) to the end.
#11
Thanks Nick, I'll try that later today! :)
#12
Hmm..I tried to find out myself, but I failed :(

What do I need to insert so that it would look like this...

[color=purple]A blue eyed man with short hair[/color] looks about shadily.

Hmm..I don't know the codes for this forum. But I would like the man's description in purple and the rest of the text in the normal format for the mud. Is that possible?
Amended on Wed 18 Aug 2010 07:15 AM by Jdiddleymspot
Australia Forum Administrator #13
Jdiddleymspot said:

Hmm..I don't know the codes for this forum. But I would like the man's description in purple and the rest of the text in the normal format for the mud. Is that possible?


There are no colour codes on the forum. :)

Anything is possible. You can use any colour you want in displays (there is an inbuilt colour-picker to help choose one). You could display %0 in one colour and "Barry" in another, like this:


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="A blue eyed man with short hair *"
   omit_from_output="y"
   send_to="14"
   sequence="110"
  >
  <send>

ColourTell ("purple", "", "%0 ")
ColourNote ("white", "", "(Barry)")

</send>
  </trigger>
</triggers>


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


The ColourTell leaves the text on the same line.

If you are still having problems please paste what you have:

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
Amended on Tue 17 Aug 2010 09:13 PM by Nick Gammon
#14
Is there a way to retain wildcard coloring?
<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="*funny looking clown*"
   send_to="14"
   sequence="110"
  >
  <send>
    Tell ("", "", "%1")
    ColourTell ("magenta", "", "funny looking clown")
    ColourTell ("white", "", "(Tom)")
    Tell ("", "", "%2")
  </send>
  </trigger>
</triggers>

eg. <white>All of a sudden, </white><magenta>a funny looking clown</magenta><white>(Tom) hurls </white><green>a red-nose</green><white> at you!</white>


Also is there a way to access the string between the asterisks?
For something like this.
ColourTell ("magenta", "", "<string between *s>")
ColourTell ("white", "", "(Tom)")
Amended on Wed 02 Feb 2011 03:24 PM by Skasi
Australia Forum Administrator #15
This is one way of doing the colours:


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="*funny looking clown*"
   omit_from_output="y"
   send_to="14"
   sequence="110"
  >
  <send>

-- show each style in its original colour

for i, style in ipairs (TriggerStyleRuns) do
  ColourTell (RGBColourToName (style.textcolour), RGBColourToName (style.backcolour), style.text)

  -- if person's description, append their name
  if style.text == "a funny looking clown" then
    ColourTell ("white", "", " (Tom)")
   end -- if
end

Note ""  -- start new line

</send>
  </trigger>
</triggers>


The appending of the name here depends on the description "a funny looking clown" being in its own style run (that is, all the same colour).

Skasi said:

Also is there a way to access the string between the asterisks?


You can do that if you make it a regular expression. Hit the "convert to regular expression" button, and then add brackets around the middle bit. This also lets you do a more general solution. eg.


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="^(.*?)(a funny looking clown|a sleepy fellow|a pretty girl)(.*?)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="110"
  >
  <send>

friends = {
 ["a funny looking clown"] = "Tom",
 ["a sleepy fellow"] = "John",
 ["a pretty girl"] = "Sarah",

-- more here

}

-- show each style in its original colour

for i, style in ipairs (TriggerStyleRuns) do
  ColourTell (RGBColourToName (style.textcolour), RGBColourToName (style.backcolour), style.text)

  -- if person's description, append their name
  if style.text == "%2" then
    ColourTell ("white", "", " (" ..
      (friends ["%2"] or "unknown") ..
       ")")
   end -- if
end

Note ""  -- start new line

</send>
  </trigger>
</triggers>


This keeps a table of friends, and then uses a regular expression to check for one of them.

You could improve this a bit by generating the matching names into a variable rather than having to repeat all the descriptions.
Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.



#16
That's more or less exactly what I needed, thanks! :)

Is it possible to use variables as arrays? Is there a way to use scripts in 'match'? I would like to do something like the following:

function getNames()
 local names = GetVariable("names")
 for i in ipairs(names) do
  print(i)
  if i < #names then print("|") end
 end
end

match="^(.*?)(getNames())(.*?)$"
Amended on Sat 05 Feb 2011 11:47 PM by Skasi
Australia Forum Administrator #17
You can't directly put tables into variables. However it is easy enough with serialization:

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

For example with this test data:



-- example table - in practice you would make an alias to add them

names = {
 ["a funny looking clown"] = "Tom",
 ["a sleepy fellow"] = "John",
 ["a pretty girl"] = "Sarah",

-- more here

}


Put this into the "on world save" callback:


require "serialize"

SetVariable ("saved_names", "names = " .. serialize.save_simple (names))


Now if you look at the (MUSHclient) variable "saved_names" (in the variables configuration dialog) you see this:


names = {
  ["a sleepy fellow"] = "John",
  ["a pretty girl"] = "Sarah",
  ["a funny looking clown"] = "Tom",
  }


This will now be saved as part of the world file, whenever you save that.

Next time (using the "world open" script callback) you put the names back like this:


assert (loadstring (GetVariable ("saved_names") or "")) ()


That converts the "string" table into an actual table.

So much for saving and loading.

Now to use in the trigger. Do the following whenever the list of names changes:


function getNames ()
 local t = {}
 for k, v in pairs (names) do
   table.insert (t, k)
 end
 SetVariable ("names_match", table.concat (t, "|"))
end


I use a second table here to convert the descriptions/names into a numerically-keyed table of just the descriptions. Then table.concat puts a "|" between each one.

Thus now names_match is:


a sleepy fellow|a pretty girl|a funny looking clown


Finally we can use the variable names_match in the trigger by putting it there with "expand variables" checked. Also note the use of the "!" which stops MUSHclient trying to put a backslash in front of the "|" characters ...


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   ignore_case="y"
   match="^(.*?)(@!names_match)(.*?)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="110"
  >
  <send>

-- show each style in its original colour

for i, style in ipairs (TriggerStyleRuns) do
  ColourTell (RGBColourToName (style.textcolour), RGBColourToName (style.backcolour), style.text)

  -- if person's description, append their name
  if style.text == "%2" then
    ColourTell ("white", "", " (" ..
      (names ["%2"] or "unknown") ..
       ")")
   end -- if
end

Note ""  -- start new line

</send>
  </trigger>
</triggers>