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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  new to scripting
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

new to scripting

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


Pages: 1 2  

Posted by Barum   (5 posts)  [Biography] bio
Date Thu 01 Apr 2004 09:40 AM (UTC)

Amended on Thu 01 Apr 2004 09:42 AM (UTC) by Barum

Message
I've been looking over the forums the last couple of days, and I'm trying to get into scripting for MUSHclient.

A lot of the examples look like XML/HTML-style stuff, like:
<trigger
match="You eat a bloodroot leaf."
enabled="y"
sent_to="12">
<send>herbeaten = "bloodroot"</send>
</trigger>

I haven't been able to find documents on how to implement this sort of thing.

I guess what I'm asking for is advice on exactly which documents I should be reading to get a firm base on which to start scripting.

The first thing I'd like to learn how to do is have any incoming and outgoing tells re-coloured and have the "tells"/"tell" portion of the text changed to "TELLs"/"TELL".
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #1 on Thu 01 Apr 2004 06:17 PM (UTC)

Amended on Thu 01 Apr 2004 06:20 PM (UTC) by Shadowfyr

Message
Hmm. First off, triggers, timers and aliases are not part of the scripting as they tend to be in other clients. These things are inbuilt and handled differently. The reason they look like XML in the examples is because they are saved to your world file in that format *and*, in order to make posting and copying of them easier, Mushclient lets you 'copy' or 'paste' them to and from the editors in that format. This means you could open a world file with notepad, copy out a trigger, alias or timer and paste it into the list of a new world directly without changing anything. It also means you can paste one into the forum and someone else can directly copy and paste that into their own world.

Since world files and plugins are both entirely XML based, this also means that everything for a plugin, including the real scripts, can be placed on the forum and simply copied off, pasted into your favorite editor and saved as an XML file. All you have to do then is install the plugin. You could do the same with world files, except that the main script file is a seperate file for those, since it makes editing and reloading it easier. Plugins are supposed to be more or less already debugged and thus not something you edit a lot.

Anyway.. What you want to do is partly very easy, and partly frustrating. In the simplist terms you need a trigger that matches (I assume without an example):

^(You tell|.* tells you)\: .*

This is a regular expression, since a normal trigger can't match on more than one situation. The XML for it, if all you wanted was to change the color, would look something like:

<trigger
  match="^(You tell|.* tells you)\: .*"
  custom_colour="17"
  enabled="y"
  regexp="y"
  other_text_colour="gold"
  other_back_colour="black">
</trigger>

Again, this is just an easy copy-and-paste XML code. If it was actually done in script, it would look more like:

world.addtriggerex "telltrigger", "^(You tell|.* tells you)\: .*", "", 1057, -1, 0, "", "", 0, 100
world.settriggeroption "custom_colour", "17"
world.settriggeroption ""other_text_colour", "gold"

Needless to say that this would need to either be executed in the command window, in a script file or using the ctrl-I immediate mode input box. Unless you really are designing a script to change the trigger, you really don't want to mess with this. lol The XML is a lot easier and, even in scripting, there is now an import function that lets you import the XML, instead of using the 3 commands above.

Anyway. That would color it. Just one problem.. Currently triggers cannot 'replace' text, so your second need isn't directly possible. With a few changes you can sort of do it though.
<trigger
  match="^(You tell .*|.* tells you)\: (.*)"
  enabled="y"
  sent_to="12"
  regexp="y"
  omit_from_output="y"
  <send>telltemp = instr("%1", "tells")
telltemp2 = instr("%1", "tell")
if telltemp then
  tellname = left("%1", telltemp - 1)
  colourtell "gold", "black", tellname & " "
  colourtell "gold", "black", "TELLS you: "
  colournote "gold", "black", "%2"
else
  tellname = right("%1", len("%1") - (telltemp2 + 4))
  colourtell "gold", "black", "You TELL" & tellname & ": "
  colournote "gold", "black", "%2"
end if</send>
</trigger>

Note: I haven't tested this code, so the 'left' and 'right' commands may not work as intended. They could be off by one character, making the name retrieved incorrect. Just adjust how much gets added or subtracted (the - 1 and + 4 bits) to fix it.

This would do what you intend, more or less. Changing text in a line is problematic at best, while simply coloring it is very simple, changing it basically requires that you have to redisplay the line manually through script commands. Omit_from_output tends to complicated matters, since while you can read the original lines from the output window, omit_from_output erases them *before* this information can be retrieved. Also, if your mud automatically line wraps tells on there end, the situation become about 50 times more complex. The one I play on does and I need four triggers to color stuff properly. Even then, it fails about 10% of the time when something unexpected happens, like someone on the staff dump ansi graphics on the screen before the trigger that ends the coloring is triggered. Good luck if yours is like this too. ;)
[Go to top] top

Posted by Barum   (5 posts)  [Biography] bio
Date Reply #2 on Thu 01 Apr 2004 07:37 PM (UTC)
Message
Thank you for your reply.

Would it be equally as hard to color in just a specific word, or specific portion of any line?
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #3 on Fri 02 Apr 2004 12:26 AM (UTC)
Message
Yes and no. Coloring one word is simple if at the start or end of a line, since you can specifically tell it using regular expressions to look for the beginning or end of the line. Otherwise, you can use regular expression and just the word, but it will then match any and all instances of the word. In other words:

"^word" - Will only match if the word is at the start of a line.
"word$" - Will only match only if it is the last thing on a line.
"word" - Will match any time it is used.

So.. If you had a sentence like:

word is a word, but not the word

All three triggers would match. If you had:

word is a noun, but not a verb

the first trigger and the third would match, but not the second. If it was:

sam is a word, but not a verb

then only the third trigger would match. And so on. However, unless you turn on the setting for "repeat on same line", the third trigger would only color the first instance of 'word', like so:

word is a word, but not the word

Trying to match and color single words in 'specific' lines usually requires using the same omit_from_ouput option and colourtell trick I gave you in the last post to make it what you want. The drawback is that you lose whatever original colors you had, so you have to recolor everything yourself through colournote.
[Go to top] top

Posted by Barum   (5 posts)  [Biography] bio
Date Reply #4 on Fri 02 Apr 2004 05:55 AM (UTC)
Message
What about just coloring a specific word whenever it comes up? I can't figure it out.

It's a feature listed in the help file, so I assume I'm just missing something incredibly obvious.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #5 on Fri 02 Apr 2004 01:56 PM (UTC)

Amended on Fri 02 Apr 2004 01:59 PM (UTC) by Ked

Message
Just use Shadowfyr's second trigger to do that (slightly modified), you can copy and paste the following into the Triggers dialogue:


<triggers>
  <trigger
   custom_colour="1"
   enabled="y"
   keep_evaluating="y"
   match="(?:\s|\'|\"|\-|\:|^)word(?:\s|\,|\.|\:|\;|\-||\!|\?|\'|\"$)"
   regexp="y"
   repeat="y"
   sequence="100"
  >
  </trigger>
</triggers>


Once you've pasted this trigger, open it in the Triggers dialogue and replace the 'word' in the Match box with whatever word you want to have coloured, also change the colour to whatever you prefer. That trigger will match on:

You say a word.
word
It was a simple word, yet it possessed much power!

But won't match on:

A wordless language.
You begin to wield a sword.
[Go to top] top

Posted by Nick Gammon   Australia  (21,412 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 02 Apr 2004 11:15 PM (UTC)

Amended on Fri 02 Apr 2004 11:17 PM (UTC) by Nick Gammon

Message
Quote:

What about just coloring a specific word whenever it comes up? I can't figure it out.


Those replies give too complex a way of doing it. (Sorry guys!).

To colour a specific word simply do this (make a trigger and):


Match: the word or phrase
Regular expression: checked
Change colour to: the desired colour


If you want the same line to be matched against other words (ie. colouring *different* words) also do this:

Keep evaluating: checked

If you want to colour the *same* word more than once on a particular line also do this:

Repeat on same line: checked


- Nick Gammon

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

Posted by Barum   (5 posts)  [Biography] bio
Date Reply #7 on Sat 03 Apr 2004 01:02 AM (UTC)
Message
Thanks Nick!

Is there any easy way to have MUSHclient color in a word that occurs in certain sentence patterns? I'd like to color in the damage word in combat sentences, and have a different color for the word depending on whether or not I'm the person doing the damage.

These are the sentences:

Your pierce grazes the wooden soldier.
Barum's pierce grazes the wooden soldier.
The wooden soldier's bite misses you.
The wooden soldier's bite misses Barum.
Barum's stab injures the rabid beast.

Basically:
Your [attack type] [damage] [mob or player name].
[Mob or player name]'s [attack type] [damage] [mob or player name].
[Mob or player name]'s [attack type] [damage] you.

I only want to color the [damage] word.
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #8 on Sat 03 Apr 2004 02:56 AM (UTC)
Message
This is what I was trying to explain. The answer is 'NO'. At least not unless you capture the entire line, omit it from output and redisplay it in your script using colourtell and colournote. There is no existing way to tell Mushclient that it should 'only' effect a specific word or pattern, though a lot of us wish there was, especially since inserting information or replacing a word would be far easier if the client could be told:

Match: You hit giant.
Only change 'hit' by replacing it with 'clubbed' and making it gold.

There is no exclusionary method I am aware of (unless regular expressions have something to both 'match', but also 'exclude'). Anything that gets matched gets colored and actual replacement, like above isn't even allowed at all. :(
[Go to top] top

Posted by Nick Gammon   Australia  (21,412 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Sat 03 Apr 2004 02:59 AM (UTC)
Message
The simple thing would be if you only want to colour one of the forms, and have the other the default. For instance, if you want to colour:

Your [attack type] [damage] [mob or player name].

Then make a trigger that catches the other ones, give it a lower sequence, and do *not* check "keep evaluating". That way it will match, and the line will not be passed to the colouring trigger.

The other approach is to dissect the line and recolour it in a small script. For instance, the above line might match a trigger like:

Match: ^Your (kick|punch|hit) (wounds|eviscerates|misses) (.*)$

This gives you three wildcards, %1, %2, and %3, which you can then redisplay like in this small script:


sub OnMyAttack (name, line, wildcards)
  ColourTell "white", "black", "Your " & wildcards (1)
  ColourTell "red", "black", wildcards (2)
  ColourNote "green", "black", wildcards (3)
end sub


To make this work make the trigger call the script OnMyAttack and set it to "omit from output" so the new coloured line replaces the original one.

- Nick Gammon

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

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #10 on Sat 03 Apr 2004 03:55 AM (UTC)
Message
Quote:
There is no exclusionary method I am aware of (unless regular expressions have something to both 'match', but also 'exclude').
There is:

?:

For example:

^(You tell .*|.* tells you)\: (?:.*)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #11 on Sat 03 Apr 2004 04:05 AM (UTC)
Message
Coming back to colouring a single word in a line... For some reason I thought that this was Python's extension to regexp, but it seems to work:

\bword\b


\b is a word boundary and includes all punctuation, spaces, newline and endline, being a compressed version of those prefix and suffix groups in my trigger above.

[Go to top] top

Posted by Barum   (5 posts)  [Biography] bio
Date Reply #12 on Sat 03 Apr 2004 07:48 AM (UTC)

Amended on Sat 03 Apr 2004 07:51 AM (UTC) by Barum

Message
Thanks for the replies.

I got it to sort of work:

^Your (.*) (misses|
wounds|
MUTILATES|
DEMOLISHES|
scratches|
mauls|
EVISCERATES|
DEVASTATES|
grazes|
decimates|
DISMEMBERS|
OBLITERATES|
hits|
devastates|
MASSACRES|
ANNIHILATES|
injures|
maims|
MANGLES|
ERADICATES) (.*).$


sub OnMyAttack (name, line, wildcards)
ColourTell "white", "black", "Your " & wildcards (1)
ColourTell "red", "black", wildcards (2)
ColourNote "white", "black", wildcards (3)
end sub

Now there aren't any spaces between wildcard 1, 2, and 3.
I'm completely inexperienced in programming so I'm not sure how to fix it.

Nick, have you ever considered implementing an easy scripting system similar (or just support the "Z" scripting) as the "Z" client? It's very useful, and a lot of dumb people like myself would really appreciate it.

edit: broke up the matching so the message wouldn't break tables.
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #13 on Sat 03 Apr 2004 01:47 PM (UTC)
Message
sub OnMyAttack (name, line, wildcards)
ColourTell "white", "black", "Your " & wildcards (1) & " "
ColourTell "red", "black", wildcards (2) & " "
ColourNote "white", "black", wildcards (3)
end sub

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #14 on Sat 03 Apr 2004 07:19 PM (UTC)
Message
Yeah Magnum. I am aware of that exclusion option, however from the standpoint of coloring lines or words, Mushclient has a serious flaw. It colors *everything* it matched and ignores the exclusion. This imho shouldn't work that way. Since it has to parse the string through the expression to determine what matches, it should be able to see the exclusion and correctly handle it for coloring as well. After all, you told it to *not* include that as part of the result, even though it matches it.

I don't know, maybe there is some obscure reason why it only works for wildcards, but that doesn't entirely make sense either, since I expect you can exclude things that are not explicitly placed in () too. In which case it does what? Pretty much nothing in this implimentation.
[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.


15,531 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] 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.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]