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.
Entire forum
➜ MUSHclient
➜ General
➜ How do I do an output substitution?
How do I do an output substitution?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Elvind
(4 posts) Bio
|
Date
| Sat 28 Jun 2008 08:27 PM (UTC) |
Message
| Hi, I was wondering if someone could help me do a substitution in the text of in the output of the MUSH. I'm not great at coding, and I've been searching awhile for it.
anyway, what I'd like to know is how to replace a player's name with something else (for example, their real name, or a previous name they had) and all instances of that.
it would be greatly appreciated.
thank you! :D | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 28 Jun 2008 09:36 PM (UTC) |
Message
| If you want to replace every instance, incoming from the MUD, install this small plugin.
Copy the text beween the lines and save as Convert_Word.xml.
Change the FROM word below to the name you want to match on, and the TO word to the one to change it to.
Then go to File menu -> Plugins and install it.
This will scan every incoming packet from the MUD and make the conversion. The %f stuff is to make sure only a whole word is converted. For example, since the FROM word is "foo" it won't match on "foot".
The conversion is case-sensitive.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Convert_Word"
author="Nick Gammon"
id="9c0ed228bdb4a71c77e85ce0"
language="Lua"
purpose="Converts one word to another"
date_written="2008-06-29"
requires="4.00"
version="1.0"
>
</plugin>
<!-- Script -->
<script>
FROM = "foo"
TO = "bar"
function OnPluginPacketReceived (s)
return (string.gsub (s, "%f[%a]" .. FROM .. "%f[%A]", TO))
end -- function OnPluginPacketReceived
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Elvind
(4 posts) Bio
|
Date
| Reply #2 on Sat 28 Jun 2008 09:55 PM (UTC) |
Message
| it works great! is there anyway it can substitute more than one word?
thanks so much already :D | Top |
|
Posted by
| Elvind
(4 posts) Bio
|
Date
| Reply #3 on Sat 28 Jun 2008 09:56 PM (UTC) |
Message
| more than one instance... like say,
Jim -> Mike
Joe -> Bob
John -> Sam
etc...
I tried adding more in the FROM and TO, but it just substituted one.
thanks :D | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sat 28 Jun 2008 10:53 PM (UTC) Amended on Sat 28 Jun 2008 10:55 PM (UTC) by Nick Gammon
|
Message
| More than one, eh?
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Convert_Word"
author="Nick Gammon"
id="9c0ed228bdb4a71c77e85ce0"
language="Lua"
purpose="Converts one word to another"
date_written="2008-06-29"
requires="4.00"
version="1.0"
>
</plugin>
<!-- Script -->
<script>
conversions = {
foo = "bar",
dog = "cat",
horse = "donkey",
-- add more here
}
function OnPluginPacketReceived (s)
return (string.gsub (s, "%a+", conversions))
end -- function OnPluginPacketReceived
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Elvind
(4 posts) Bio
|
Date
| Reply #5 on Sat 28 Jun 2008 11:54 PM (UTC) |
Message
| great! :D thank you so much. | Top |
|
Posted by
| IneptGuest
(3 posts) Bio
|
Date
| Reply #6 on Mon 30 Jun 2008 09:23 AM (UTC) Amended on Mon 30 Jun 2008 09:51 AM (UTC) by IneptGuest
|
Message
| This is an interesting plugin, very helpful. I've tried to do something similar myself but never been able to, since I'm quite inept at these things.
I have a few questions regarding this topic, if someone would be so kind as to point me in the right direction, I'd be grateful.
Is there someway to do exactly what this plugin does, but with entire sentences? (Able to do this -and- add colour to the subbed text?)
Example:
(From) You eat a sandwich (TO) Not hungry anymore!
Is there a way to make whatever you have targetted show up in caps?
Example:
t kobold -> kick kobold(input to MUD) -> You kick a KOBOLD(output on screen)
If anyone is able to give any feedback to this, I'm happy as can be. If this has been covered in another topic, I'm sorry but would be glad if someone would point me towards the topic if this is the case.
Thank you
EDIT: Doing a few searches and noticed this has been covered a few times(the 'sentence sub' at least, not the target in caps) and it seems like it's hard to do.
| Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #7 on Tue 01 Jul 2008 06:19 AM (UTC) |
Message
|
Quote:
Is there someway to do exactly what this plugin does, but with entire sentences? (Able to do this -and- add colour to the subbed text?)
The best way is to make a trigger, omit the triggered line from output, and then do a ColourNote to send whatever replacement line you want, in whatever colour you want.
Ditto for changing a word like kobold. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| IneptGuest
(3 posts) Bio
|
Date
| Reply #8 on Tue 01 Jul 2008 10:51 AM (UTC) |
Message
| Ah, thank you!
Quote: Ditto for changing a word like kobold.
It's not the word I'm trying to get in caps, it's whatever I have in the @target variable. Sorry if described it poorly.
| Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #9 on Wed 02 Jul 2008 07:24 AM (UTC) |
Message
| I suggest highlighting the word you want in a eye-catching colour. This trigger demonstrates the idea:
<triggers>
<trigger
custom_colour="17"
enabled="y"
expand_variables="y"
match="@target"
regexp="y"
sequence="100"
other_text_colour="orangered"
other_back_colour="yellow"
>
</trigger>
</triggers>
With "expand_variables" checked, it matches on whatever word is in the 'target' variable, anywhere on the line, and colours it red on yellow. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| IneptGuest
(3 posts) Bio
|
Date
| Reply #10 on Wed 02 Jul 2008 07:43 AM (UTC) |
Message
| A highlight would work just as well, of course. Thanks a lot! | Top |
|
Posted by
| Brubaker
(1 post) Bio
|
Date
| Reply #11 on Thu 10 Jul 2008 06:05 PM (UTC) |
Message
| Is there any way to subsitute few words to few diffrent words for instance: "i am great" = "i hate myself"? | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #12 on Thu 10 Jul 2008 11:51 PM (UTC) |
Message
| One approach is to do it at the packet level, but I warn you that the output from the MUD could quite easily be broken over multiple packets, and so this may not work.
Using my earlier plugin above, you could do something like this. Change:
return (string.gsub (s, "%a+", conversions))
to:
s = string.gsub (s, "i am great", "i hate myself")
s = string.gsub (s, "fish is good", "seafood is great")
return s
However as I said, this depends on everything being in one packet, and also that there is no telnet codes (like colour codes) in there.
Another approach is to make a trigger, omit that line from output, and then redisplay it with the substituted text. That will work regardless of how many packets the line takes, and at that stage the color information has been stripped out. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Khuran
(5 posts) Bio
|
Date
| Reply #13 on Mon 13 Aug 2012 03:07 AM (UTC) |
Message
| Hello Nick! I appreciate all your great work on this plugin (and all the others)
In this convert_word plugin, is it possible to convert words that are variables?
meaning, variable @char1 is "Peter"
I want to convert Peter to "Peter-[1]"
When I change the contents of my variable to say Pierre, it would then convert Pierre to "Pierre-[1]"
I tried @char1="@char1-[1]" but it did not work...
awaiting response... | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #14 on Mon 13 Aug 2012 09:48 PM (UTC) |
Message
| You could do something like:
conversions [ GetVariable ("char") ] = GetVariable ("char") .. "-[1]"
So this pulls in the contents of the variable "char", puts it into the table as the match text, and also the replacement text with "-[1]" after it. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
46,983 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top