Register forum user name Search FAQ

Gammon Forum

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 Reply #15 on Mon 29 Jan 2007 03:37 AM (UTC)
Message
I just sent you an email.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #16 on Mon 29 Jan 2007 05:15 AM (UTC)

Amended on Mon 29 Jan 2007 05:27 AM (UTC) by Nick Gammon

Message
Just as well you warned me, I don't often read emails, being 99.9% spam. (In case anyone is wondering, the email contained an example who list).

A minor tweak was necessary, the test for the name needed to be made "not greedy" as, once we added in the space, it was sucking in all the letters and spaces onwards, including the word "the". This seemed to work with your test data:


match="^\[\s*\d+\s+[-\w]+\s+\w+\] ([\[\(]\w+?[\]\)] )*(?P<player>[\w ]+?) the \w+"


Basically there is a ? after the + in the test for the player name.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #17 on Mon 29 Jan 2007 05:27 AM (UTC)

Amended on Mon 29 Jan 2007 05:31 AM (UTC) by Nick Gammon

Message
Just to break this regexp down into its component parts, this is what it does:


  • ^ - match start of line
  • \[ - match a LH square bracket
  • \s* - match zero or more spaces
  • \d+ - match one or more digits (the level)
  • \s+ - match one or more spaces
  • [-\w]+ - match one or more of the set "word" characters or hyphens (the race)
  • \s+ - match one or more spaces
  • \w+ - match one or more word characters (the class)
  • \] - match a RH square bracket
  • Now we have a group consisting of the next few things inside round brackets (the optional things) with a * afterwards, to indicate "zero or more of these things".

    • ( - start of the group
    • [\[\(] a set consisting of the [ or ( character
    • \w+? - one or more word characters, not greedy
    • [\]\)] - a set consisting of the ] or ) character
    • ) - end of the group
    • * - match this entire group zero or more times

  • (?P<player> - start of group named "player"
  • [\w ]+? - match one or more of the set "word" characters or spaces (the player name), not greedy
  • ) - end of the group named "player"
  • the \w+ - the word "the" followed by another word


Simple, huh?

But at least, looking at this you should be able to understand it, and be better able to design modifications.

In the XML code "<player>" is represented as "&lt;player&gt;", but that is just for inside the plugin, internally the regular expression is just "<player>".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Hoinzor   (10 posts)  Bio
Date Reply #18 on Mon 29 Jan 2007 06:15 AM (UTC)
Message
I love you! It works perfectly now. I cannot thank you enough.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #19 on Tue 30 Jan 2007 05:09 AM (UTC)

Amended on Tue 30 Jan 2007 05:12 AM (UTC) by Nick Gammon

Message
Good!

In case anyone wants to use it, this is the final version I had:


<?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-30 17:00:00"
   requires="3.84"
   version="1.1"
   >

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="^\[\s*\d+\s+[-\w]+\s+\w+\] ([\[\(]\w+?[\]\)] )*(?P&lt;player&gt;[\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 ["%&lt;player&gt;"] -- any notes?

if notes then
  ColourTell ("green", "", " (" .. notes .. ")")
end -- notes found

Note ""  -- end line
</send>
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   match="^note (?P&lt;player&gt;[\w]+?) (?P&lt;description&gt;.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
player_notes ["%&lt;player&gt;"] = "%&lt;description&gt;"</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 &quot;(?P&lt;player&gt;[\w ]+)&quot; (?P&lt;description&gt;.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
player_notes ["%&lt;player&gt;"] = "%&lt;description&gt;"</send>
  </alias>

 <alias
   match="^deletenote (?P&lt;player&gt;[\w]+?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
player_notes ["%&lt;player&gt;"] = nil</send>
  </alias>

  <alias
   match="^deletenote &quot;(?P&lt;player&gt;[\w ]+)&quot;$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
player_notes ["%&lt;player&gt;"] = 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>



To use:


note person comment   (eg. note Nick avoid him)
note "person" comment (eg. note "Nick Longsword" herbalist)
deletenote person     (eg. deletenote Nick)
deletenote "person"   (eg. deletenote "Nick Longsword")
shownotes             (lists existing notes)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Christopher Palmer   (2 posts)  Bio
Date Reply #20 on Sat 19 Jan 2008 12:29 AM (UTC)
Message
-------------Immortals--------------
[Goddess 96 Ang Asn] Bryn

-------------Mortals--------------
[SacredC 91 Drg Pal] [AFK] Baja If Not Why Not [IAW]
[Keeper 84 Vmp Wit] Elektra Blood Sucker Extrordinare!
[CircleC 70 Lch Wiz] [AFK] Cavcav
[Keeper 43 Hum Cle] [AFK] Sasuke, The Magician of Faith
[ 1 Hum Cle] Testing the Believer

This is the wholist for the mud Im on. emperia.org 5002

Its basically like this

[tribe level race class] Name Title

As you can see the player Testing has no tribe, so his spot there is blank. Also, we have an option for AFK (away from computer) that shows people are afk. This puts [AFK] in front of the player name when enabled.

Can someone please come up with a script that will work for me?
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.


68,346 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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

Go to topic:           Search the forum


[Go to top] top

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