Replacing MUD Text with Your Own

Post Reply
User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Replacing MUD Text with Your Own

Post by Jules »

Years back, I downloaded a MUD client that allowed me to actually REPLACE text outputs given to me from the MUD with something of my own. For example:
You have regained balance on all limbs.
I was able to run a command that would replace that with anything that I wished, such as:
Balance is Back!!
Is there any possible way that I can do that using Lua scripting? I've been wondering this, because I wish to make a new prompt for Lusternia that replaces the elrx- prompt with something like:
You have: Balance and Equilibrium
...or something along those lines. Is this possible?

And if not, could someone please explain the Prompt Detection example in the Manual?

Thank you!

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Replacing MUD Text with Your Own

Post by Heiko »

To replace text have a look at the select- and replace functions in the API section in the manual. After having selected some text you can do all sorts of formating, colouring and replacements. -> manual & read the relevant posts in the help forum as it contains a lot of newer information for the cases where the information in the manual is outdated.

Code: Select all

selectString("You have regained balance on all limbs.", 1)
replace("Balance is back!!")
Mudlet can do much more though like inserting a subsequent ascii-map output into the room description etc.. You have full cursor control on all console windows.

Have a look at the Achaea demo package here: http://mudlet.sourceforge.net/phpBB3/vi ... p?f=6&t=95. It shows how to use some of Mudlet's more advanced features like filters and chains to do things like prompt-balance detection etc.. Adapting this package for Lusternia should be no problem.

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: Replacing MUD Text with Your Own

Post by Jules »

Again, Heiko, you come to my rescue! Thank you very much! I've scoured the Help Manuel and looked around the Help thread, but I couldn't find anything like this to help me. I guess I wasn't looking hard enough, apparently... Heh...

Again, though, Thank you!

goose
Posts: 13
Joined: Sun Jun 14, 2009 2:51 pm

Re: Replacing MUD Text with Your Own

Post by goose »

I have a related question which, as it might help Jules as well and fits well under this subject, I won't make its own thread for:

If I have a lot of substitutions, which of the following would be the Better Idea:

A) Make n triggers matching on each of the lines to be substituted, that each do, simply, deleteLine() and echo() with the new text.

or B) Make ONE trigger matching (.+), and have, as the script:

Code: Select all

selectString("You have regained balance on all limbs.", 1)
replace("Balance is back!!")
selectString("You have regained equilibrium.", 1)
replace("EQ is back!!")
selectString("Thingy1.", 1)
replace("Substitution1")
selectString("Thingy2.", 1)
replace("Substitution2")
selectString("Thingy3.", 1)
replace("Substitution3")

Which of the above would slow mudlet down less? I'd guess in general the first option would win. However, I think I'm going to end up needing to have a (.+) regexp trigger active a lot of the time anyway, so would it then be smarter to put the substitutions in that one, since it's matching everything anyway?

Edit: Many of the substitutions would be very frequent, but there's be some rarer things in there as well

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Replacing MUD Text with Your Own

Post by Heiko »

Your method A doesn't work because Mudlet ignores any subsequent print commands after a deleteLine() function call because of performance reasons. The function deleteLine() is optimized for speed gagging as this is a very important function in most MUD scripts.

The most efficient way of solving your problem is to delete the text that the MUD has sent without calling deleteLine() and then using echo() to print whatever you like instead of the text the MUD has sent.
The global variable "line" holds the current text line from the MUD that the triggers are run on. You simply select this text and replace it with an empty string in order to gag the current line without calling deleteLIne().

Code: Select all

selectString( line, 1 )
replace("")
echo("thingy1")
echo("thingy2")
echo("thingy3")
Have a look at the Achaea GUI demo package. It contains a very simple and efficient way of prompt based equilibrum, balance, deafness, blindness etc. detection using filters and trigger chains.
Look at the prompt detection trigger chain and espcially at the last child trigger "report status". To understand this example you need to read the trigger chain & filter section in the manual.

goose
Posts: 13
Joined: Sun Jun 14, 2009 2:51 pm

Re: Replacing MUD Text with Your Own

Post by goose »

Ah, right. That was off the top of my head - anyway, the questions still stands, and I'll try to clarify what I meant a bit.

Say I get this from the MUD:
You see some cheese.
H:100 M:100 mv:68>
It is yellow with spots on.
H:100 M:100 mv:68>
It's cheese man, what do you want? Seriously.
H:100 M:100 mv:68>
And I want it to look like:
TARGET ACQUIRED: cheese
H:100 M:100 mv:68>
TARGET STATUS CHANGED TO: yellow with spots on.
H:100 M:100 mv:68>
TARGET CONFIRMED: cheese
H:100 M:100 mv:68>
Assume I have a hundred more similar substitutions on all sorts of lines, many of them happening several times a minute. Would it then be better to have:

A) a hundred separate triggers, each with one selectString(line,1) and one replace("Line to substitute in here"). One trigger for each line I want to sub, each trigger has only that particular line as the pattern.

or B) A single trigger with just one pattern (.+) (or substring equivalent - I still haven't looked at those even though they're supposed to be faster) and a hundred different selectString("You see some cheese.",1) and replace("TARGEtcetera")


The second option would have to match and run on every line coming from the MUD, but the first option would mean a LOT more triggers to parse per line the mud sends. So my question is basically, would the second option, with a single pattern but lots of code, be "faster"?

(I haven't had any speed problems yet, but at this rate I'll have about nine point five billion triggers by this time next year :roll: )

On a sort of sidenote, if I ended up using the second method, should it look like this:

Code: Select all

selectString("You see some cheese.",1)
replace("TARGET ACQUIRED: Cheese")
selectString("It is yellow etc",1)
replace("TARGET STATUS CHANGEtc")
selectString("It is cheese man.",1)
replace("TARGET CONFIRMED")
or like this:

Code: Select all

local ternary=selectString("You see some cheese.",1)>-1 and replace("TARGET ACQUIRED: Cheese")
local ternary=selectString("It is yellow etc.",1)>-1 and replace("TARGET STATUS CHANGEtc")
local ternary=selectString("It is cheese man.",1)>-1 and replace("TARGET CONFIRMED")
That is, would a lot of replace() calls while nothing is actually selected be bad, or would it be worse to have a hundred if statements? (or makeshift ternary conditionals as above - not sure if that works and can't remember where I got the idea from)

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Replacing MUD Text with Your Own

Post by Heiko »

One trigger per replacement is the faster solution. Don't worry about speed. Mudlet is the king of speed.
In general, it is a lot slower to use Lua to do the pattern matching & parsing than using the trigger engine. Lua is fast, but not nearly as fast with low level computations as C++. Don't do this unless you have some special reason to do so.
Mudlet is especially designed to be able to handle tens of thousands of triggers. Make sure to use the advanced grouping, chain & filter features as much as possible as this will help to reduce the number of active triggers automatically and thus optimize the overall speed.
For example you can use chain head triggers with Lua code patterns that only grant access to its children triggers when certain system variables are activated e.g. you are in a fight etc.
Another way would be the standard (and fastest but also the most error prone) way to activate the relevant trigger groups.
Anyways, try to always use faster pattern types when possible. Regex is nice, but it's also the slowest.
For example I ran tests with 5000 active substring triggers that lead to no system slow down whatsoever, but having 5000 active regex triggers will definitely slow down your system somewhat depending on the complexity of the patterns.

goose
Posts: 13
Joined: Sun Jun 14, 2009 2:51 pm

Re: Replacing MUD Text with Your Own

Post by goose »

Will do. Thanks

Post Reply