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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Tips and tricks
➜ Need help making a complex replacement
Need help making a complex replacement
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Sat 27 Jan 2007 09:49 AM (UTC) Amended on Mon 29 Jan 2007 06:21 AM (UTC) by Hoinzor
|
Message
| Basically, what I want to do is be able to add "notes" to a character. For example:
I type "Who" in the mud I play and it will display something along the lines of:
[ 2 H-Elf Bar] Jezzabelle the Jester
[ 8 H-Drw Asn] Ghuron the 1st Brown
[ 1 Gnome Ran] Shizra the Tenderfoot
[ 5 Storm War] Leinadynous the Cadet
I would like to be able to add notes next to their names. I would like it to display something like:
[ 2 H-Elf Bar] Jezzabelle the Jester (Information here)
[ 8 H-Drw Asn] Ghuron the 1st Brown (I don't like this guy)
[ 1 Gnome Ran] Shizra the Tenderfoot (He's okay)
[ 5 Storm War] Leinadynous the Cadet (Blah blah)
I would like this information stored, and triggered each time I type "Who", or a variation "Whois" (You type "Whois Jezzabelle" and it will list one person at a time)
Is there any possible way to create something like this?
I searched a bit and came up with nothing near what I would like to accomplish, so if there is something already posted, I apologize.
Thanks in advance.
Edit: Also, could you make the note portion in a different color?
EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT
The final revisions have been made by the wonderful Mister Gammon: It is!
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, January 28, 2007, 1:50 PM -->
<!-- MuClient version 3.84 -->
<!-- Plugin "Improved_who" generated by Plugin Wizard -->
<muclient>
<plugin
name="Improved_who"
author="Nick Gammon"
id="b8e59c12ea2d835e5a96d2bc"
language="Lua"
purpose="Adds comments to a 'who' list"
save_state="y"
date_written="2007-01-28 13:49:50"
requires="3.84"
version="1.0"
>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^\[\s*\d+\s+[-\w]+\s+\w+\] ([\[\(]\w+?[\]\)] )*(?P<player>[\w ]+?) the \w+"
omit_from_output="y"
regexp="y"
send_to="14"
sequence="100"
>
<send>-- display original line with original colours
for k, v in ipairs (TriggerStyleRuns) do
ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
v.text)
end -- for
notes = player_notes ["%<player>"] -- any notes?
if notes then
ColourTell ("blue", "", " (" .. notes .. ")")
end -- notes found
Note "" -- end line</send>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
match="^note (?P<player>[\w]+?) (?P<description>.*?)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = "%<description>"</send>
</alias>
<alias
match="shownotes"
enabled="y"
send_to="12"
sequence="100"
>
<send>for k, v in pairs (player_notes) do
Note (k, ": ", v)
end -- for</send>
</alias>
<alias
match="^note "(?P<player>[\w ]+)" (?P<description>.*?)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = "%<description>"</send>
</alias>
<alias
match="^deletenote (?P<player>[\w]+?)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = nil</send>
</alias>
<alias
match="^deletenote "(?P<player>[\w ]+)"$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = nil</send>
</alias>
</aliases>
<!-- Timers -->
<timers>
<timer enabled="y" minute="5" send_to="12"
>
<send>SaveState ()</send>
</timer>
</timers>
<!-- Script -->
<script>
<![CDATA[
-- load data from variable in state file into a Lua table
function OnPluginInstall ()
assert (loadstring (GetVariable ("player_notes") or "")) ()
player_notes = player_notes or {} -- ensure table exists
end -- function OnPluginInstall
-- save Lua table into MUSHclient variable "player_notes",
-- ready to save the state
require "serialize"
function OnPluginSaveState ()
SetVariable ("player_notes", serialize.save ("player_notes"))
end --- function OnPluginSaveState
]]>
</script>
</muclient>
- Enters information that will display next to the characters name on the Who list. Use quotation marks if the person has a two word name (Note "Robert Marley" Information)
- Will display all notes that you have written about everyone.
- Will delete a single persons name and note from your Shownotes list. Use quotation marks if the person has a two word name (Deletenote "Robert Marley")
| Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 28 Jan 2007 02:16 AM (UTC) Amended on Sun 28 Jan 2007 05:04 AM (UTC) by Nick Gammon
|
Message
| This is an interesting challenge. I have done this using a plugin, because that makes saving and loading a bit simpler, as the plugin automatically saves its state when it is closed.
I have also added a timer to save automatically every 5 minutes, so if the PC crashes you haven't lost everything.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, January 28, 2007, 1:50 PM -->
<!-- MuClient version 3.84 -->
<!-- Plugin "Improved_who" generated by Plugin Wizard -->
<muclient>
<plugin
name="Improved_who"
author="Nick Gammon"
id="b8e59c12ea2d835e5a96d2bc"
language="Lua"
purpose="Adds comments to a 'who' list"
save_state="y"
date_written="2007-01-28 13:49:50"
requires="3.84"
version="1.0"
>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="\[ \d+ [-\w]+ \w+\] (?P<player>\w+) the \w+"
omit_from_output="y"
regexp="y"
send_to="14"
sequence="100"
>
<send>-- display original line with original colours
for k, v in ipairs (TriggerStyleRuns) do
ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
v.text)
end -- for
notes = player_notes ["%<player>"] -- any notes?
if notes then
ColourTell ("white", "", " (" .. notes .. ")")
end -- notes found
Note "" -- end line</send>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
match="^note (?P<player>[\w]+?) (?P<description>.*?)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = "%<description>"</send>
</alias>
<alias
match="shownotes"
enabled="y"
send_to="12"
sequence="100"
>
<send>for k, v in pairs (player_notes) do
Note (k, ": ", v)
end -- for</send>
</alias>
</aliases>
<!-- Timers -->
<timers>
<timer enabled="y" minute="5" send_to="12"
>
<send>SaveState ()</send>
</timer>
</timers>
<!-- Script -->
<script>
<![CDATA[
-- load data from variable in state file into a Lua table
function OnPluginInstall ()
assert (loadstring (GetVariable ("player_notes") or "")) ()
player_notes = player_notes or {} -- ensure table exists
end -- function OnPluginInstall
-- save Lua table into MUSHclient variable "player_notes",
-- ready to save the state
require "serialize"
function OnPluginSaveState ()
SetVariable ("player_notes", serialize.save ("player_notes"))
end --- function OnPluginSaveState
]]>
</script>
</muclient>
This requires MUSHclient version 3.84 (onwards), because it uses the new concept of omitting from output, and then writing to the output window.
You may need to modify the trigger that matches the who list a bit, but this one should work OK.
First thing you need to do is make notes, eg.
note Ghuron I don't like this fellow
This adds a note for Ghuron into the table (this is case-sensitive, so you better copy the name from the screen).
You can check your current notes by typing:
shownotes
You should see something like this:
Jezzabelle: is a nice person
Ghuron: I don't like this fellow
Now when you do a "who" the trigger matches the "who" line, looks up the name in the table, and adds the extra stuff, like this:
[ 2 H-Elf Bar] Jezzabelle the Jester (is a nice person)
[ 8 H-Drw Asn] Ghuron the 1st Brown (I don't like this fellow)
[ 1 Gnome Ran] Shizra the Tenderfoot
[ 5 Storm War] Leinadynous the Cadet
The last few lines in the plugin handle serialization of the Lua table into a MUSHclient variable, for saving, and the loading back into a Lua table when the plugin is loaded. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #2 on Sun 28 Jan 2007 07:37 PM (UTC) Amended on Sun 28 Jan 2007 08:53 PM (UTC) by Nick Gammon
|
Message
| I upgraded to the version you required and copied/pasted into a new XML document. I saved that file in the plugins directory and loaded it via "Load Plugin".
The plugin is functioning to the point that:
Note Name information
If I typed the above (Obviously modified to a true name and information) it will register the information and will output it upon typing "Shownotes", however, it does not show anything on my "Who" list.
I've pasted some more variations of the "Who" list in order for you to better see what can be done. I do appreciate the work you've put forward towards this. Really. Thank you.
<100%hp 96%m 100%mv 12957tnl (5.01%) 5 AM><forest-outdoor-cloudy>
*51 Felar War* (PK) Myname the editedforcoolness
[33 Fire A-P] Krirga the Captain of Legion
[24 Svirf War] Ajirun the Knight
[20 W-Elf Ran] Mikirel the Ranger
[29 Elf Pal] (PK) [TRIBUNAL] Wionlohs the Bestower of Charity, Magistrate of Seantryn Modan
[24 Orc Ber] Gnashgaar the Impaler
[35 Human Nec] (PK) Kore the Abomination, Imperial Black Magician
[24 Fire War] (PK) Thrakazhaar the Knight
[30 Human War] (PK) Gatto the Man-At-Arms
[27 Orc Ber] (PK) Charnak the Spinebreaker
[21 Felar Ran] Abulin the Howler
[35 Svirf War] (PK) Rhoth the Warrior of the Blade
[24 Human Nec] Gothinat the Bringer of Plague, Bloodchild
[33 Storm Pal] Dahltu the Protector of the Meek
[32 Felar War] (PK) Gharral the Master of Defense
Players found: 15
I edited my name, some people who play Carrion Fields may read this and obviously giving out who I play is not a good thing, but... to show how it displays my, and people whom I can PK, I've attached that. Perhaps this is causing a problem?(The (PK) or even the spaces, or titles?)
Peoples Titles change each level, so tomorrow, Gharral the Master of Defense will likely be something else. Is this effecting the plugin at all? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 28 Jan 2007 09:02 PM (UTC) Amended on Sun 28 Jan 2007 09:03 PM (UTC) by Nick Gammon
|
Message
| OK I see the problem here. Triggers are very sensitive to getting things like spacing right.
Also, unless you use the [code] tag, the forum reduces multiples spaces to a single space. I have modified your post to add that tag.
Based on your original posting, I assumed there was a space before the level number, eg.
[ 2 H-Elf Bar] Jezzabelle the Jester
I see now that if the level is above 9, then that space is not there.
Also in this example:
There are 2 spaces on each side of "Elf".
In addition, some names have things like "(PK) [TRIBUNAL]" before them.
I have modified the match line (just replace that in the plugin), and the plugin seems to work for me for the test data you gave then.
match="^\[\s*\d+\s*[-\w]+\s*\w+\] (\(PK\) )?(\[TRIBUNAL\] )?(?P<player>\w+) the \w+"
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #4 on Sun 28 Jan 2007 09:13 PM (UTC) |
Message
| Fantastic!
It works just as it should with one exception. How can I enable it to note on people with two names. A reward in CF is that you get a last name, and by doing so it messed with the "the" part of the trigger because the word after their first name is not "the".
Would enabling "_" (an underscore) as an input for two named people work? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 28 Jan 2007 09:49 PM (UTC) |
Message
| You mean, like "Dahltu Strongsword the Protector of the Meek"?
I think you just need to allow for a space in the player name part.
Instead of:
match="^\[\s*\d+\s*[-\w]+\s*\w+\] (\(PK\) )?(\[TRIBUNAL\] )?(?P<player>\w+) the \w+"
Try:
match="^\[\s*\d+\s*[-\w]+\s*\w+\] (\(PK\) )?(\[TRIBUNAL\] )?(?P<player>[\w ]+) the \w+"
I have changed \w+ to [\w ]+, which effectively matches on "word" characters, or a space. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #6 on Sun 28 Jan 2007 10:22 PM (UTC) Amended on Sun 28 Jan 2007 10:23 PM (UTC) by Hoinzor
|
Message
| No dice. Hrm.
Perhaps allow the input to accommodate for quotation marks to input multiple words? Instead of typing Note Dahltu Stronghold (As, currently, it will read Dahltu: Stronghold) Perhaps note "Dahltu Stronghold" information so that it may read:
Shownotes
Dahltu Stronghold: Information
as opposed to the current:
Dahltu: Stronghold information
That's the only way I can think of doing it, but... I have no idea what I'm doing in the first place. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #7 on Sun 28 Jan 2007 11:43 PM (UTC) |
Message
| Yes you are on the right track there.
My change would make the trigger work, but didn't address the question of adding the note in the first place.
Try adding this extra alias, by pasting this just before the line: </aliases>
<alias
match="^note "(?P<player>[\w ]+)" (?P<description>.*?)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = "%<description>"</send>
</alias>
This adds an alias that matches on a quoted name, eg:
note "Dahltu Stronghold" should be avoided
However for single names, you can still use the unquoted version, that is matched by the original alias. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #8 on Sun 28 Jan 2007 11:46 PM (UTC) |
Message
| match="^[\s*\d+\s*[-\w]+\s*\w+] (\(PK\) )?([TRIBUNAL] )?([BATTLE] )?([FORTRESS] )?([SCION] )?([EMPIRE] )?([OUTLANDER] )?(\(WANTED\) )?(?P<player>\w+) the \w+"
The above is posted for players from Dio's. Copy and paste that to replace your current. It's as up to date as the other, but contains all cabals so that you can make notes on your cabal mates. | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #9 on Mon 29 Jan 2007 12:12 AM (UTC) |
Message
| The new portion you added now prevents anyone with (Wanted) or a cabal name (In the brackets) from displaying notes now.
Hrm. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #10 on Mon 29 Jan 2007 01:33 AM (UTC) Amended on Mon 29 Jan 2007 01:36 AM (UTC) by Nick Gammon
|
Message
| Hmm, this is getting a bit out of hand with all the extra words that might appear in brackets.
Also, this isn't right: "([TRIBUNAL] )"
Something in square brackets like that matches on a set, in other words it simply matches a single letter, which can be one of T, R, I, B, U, N, A or L.
You really mean: "(\[TRIBUNAL\] )"
The backslash escapes the brackets, so that we are literally looking for "[TRIBUNAL]".
To make the whole thing more general, try this:
match="^\[\s*\d+\s*[-\w]+\s*\w+\] ([\[\(]\w+?[\]\)] )*(?P<player>[\w ]+) the \w+"
This matches on any number of things, in brackets, before the player name. All the brackets and backslashes may look confusing, but the important part is here:
([\[\(]\w+?[\]\)] )*
This is saying, match zero or more of (that is the final asterisk):
- A [ or ( symbol
- One or more "word" characters (letters, numbers, underscore) - that is the \w+? symbol.
The ? at the end makes it non-greedy, so it matches the least number of things it can.
- A ] or ) symbol
- A final space
So that will match on something like:
(PK) [TRIBUNAL] [BATTLE] [EMPIRE] (dead) Fred Nurk the sword swinger
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #11 on Mon 29 Jan 2007 02:04 AM (UTC) Amended on Mon 29 Jan 2007 02:05 AM (UTC) by Hoinzor
|
Message
| Well, after all of that, it's breaking it more and more each time. Some names work (Now, with the most current anyone with (PK) in front of their name that starts with an I will not display notes for some reason) and some don't. No one with a [TRIBUNAL] or any bracket in their name works at all.
I reverted back to the second one:
match="^[\s*\d+\s*[-\w]+\s*\w+] (\(PK\) )?([TRIBUNAL] )?(?P<player>\w+) the \w+"
If you feel like trying to figure it out, fantastic, if you don't, no hard feelings. Truly. You've spent far too much time on this as is. I can live with not being able to make notes on a few different types of names.
Thanks again.
Also, the last favor I'm going to ask. How do I delete entries? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #12 on Mon 29 Jan 2007 03:12 AM (UTC) Amended on Mon 29 Jan 2007 03:27 AM (UTC) by Nick Gammon
|
Message
|
Quote:
No one with a [TRIBUNAL] or any bracket in their name works at all.
I reverted back to the second one:
match="^[\s*\d+\s*[-\w]+\s*\w+] (\(PK\) )?([TRIBUNAL] )?(?P<player>\w+) the \w+"
Well you didn't really, because my 2nd one had more backslashes in it:
match="^\[\s*\d+\s*[-\w]+\s*\w+\] (\(PK\) )?(\[TRIBUNAL\] )?(?P<player>[\w ]+) the \w+"
I explained that you needed them or it would not match.
It is working for me, so you need to copy and paste carefully. Even my last one should have worked.
If there is a case that is not working you need to paste the exact text from the MUD, perhaps there is something there that the regular expression is not testing for.
Quote:
How do I delete entries?
You could add two more aliases before the </aliases> line, like this:
<alias
match="^deletenote (?P<player>[\w]+?)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = nil</send>
</alias>
<alias
match="^deletenote "(?P<player>[\w ]+)"$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
player_notes ["%<player>"] = nil</send>
</alias>
Now you can type: deletenote "Dahltu Stronghold"
or: deletenote Dahltu
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Hoinzor
(10 posts) Bio
|
Date
| Reply #13 on Mon 29 Jan 2007 03:16 AM (UTC) |
Message
| For some reason when I paste on the forum it's taking out the backslashes, they're all there in my xml. Weird.
Trying it again to be 100%. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #14 on Mon 29 Jan 2007 03:29 AM (UTC) |
Message
| If you post with forum codes enabled, you need to "escape" the backslashes and brackets, or the forum will take them away for you.
MUSHclient has a function to do that, use Edit menu -> Convert Clipboard Forum Codes, once you have something on the clipboard you are intending to paste here. That will put extra backslashes in front, so it comes out right. |
- 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.
51,702 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