[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]  Tips and tricks
. . -> [Subject]  How to make a separate chats window
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

How to make a separate chats window

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


Pages: 1  2 3  4  5  6  7  8  

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #15 on Tue 04 Mar 2008 07:03 PM (UTC)
Message
Ah, that one is easier to read. ;)

Well you just need to match in this case on the start of the line, rather than trying to guess the last character.

I assume you are using a different function for you who list? You are redirecting to a different window, so I presume so.

Instead of:


if line:sub (-1) == '"' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go


You could have something like:


if string.match (line, "^%d+h,") then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go


In other words, if a line comes along that starts with some numbers followed by "h," it is time to stop.

Your other problem here is that this is a line you don't want to see, so you want to move the test further up (before the line is copied to the other window).

If you are in fact making multiple copies of the redirect function I would personally be making the middle bit (that copies the lines) into a separate function, to save repeating something that will be the same in each case.

- Nick Gammon

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

Posted by Aromaros   (9 posts)  [Biography] bio
Date Reply #16 on Tue 04 Mar 2008 07:18 PM (UTC)

Amended on Tue 04 Mar 2008 07:20 PM (UTC) by Aromaros

Message
Thanks again Nick, it works great. I actually tried to get it to do something like this by I was going about it all wrong in my ignorance of proper scripting.

I tried to change
-- if ends with quote, end of multi-line chat

to

-- if starts with 2, end of multi-line chat
if line:sub (-1) == '^2(.*?)$' then

Among several different attempts. I suppose I really need to learn Lua. On that note, do you have any reccomendations on books or websites to that effect? It seems like vbscript book I had (which I didn't realize until just the other day) focuses mostly on utilizing scripting in web sites. I have a basic understanding of C...

PS: Also, when you suggest changing the fuction do you mean this?

function redirect (name, line, wildcards, styles)
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #17 on Tue 04 Mar 2008 08:28 PM (UTC)
Message
Quote:

-- if starts with 2, end of multi-line chat
if line:sub (-1) == '^2(.*?)$' then


That wouldn't work because you are using a regular expression where a simple comparison is being done. You need to look up string.sub in the MUSHclient help - that pulls out a substring, and -1 means the last column (however 1 means the first column). The last column would never match '^2(.*?)$' (for one thing, that is more than one byte).

Quote:

do you have any reccomendations on books or websites to that effect?


See: http://www.lua.org/docs.html

The book "Programming in Lua" by Roberto Ierusalimschy (one of the authors of Lua) is really well-written. That page also leads to links for online documentation.


Quote:

Also, when you suggest changing the fuction do you mean this?


Yes - the example below replaces my original script portion with two "redirect" functions - one for chats and one for the who list. They share the function send_to_window - which does the actual copying of text to the other window, because this will be the same in both cases (or for more cases again, as your screen dump seems to show).

You can see that in who_list_redirect I test for the end of the list first, so that the prompt line does not end up in the other window.

As a general rule I like to simplify things that are done repeatedly, rather than copy-and-paste, because if you ever find a problem then you only need to fix it in one place.


local tried_to_open = {}  -- set flag if can't open world

function send_to_window (chat_world, styles)

  -- try to find "chat" world
  local w = GetWorld (chat_world)  -- get "chat" world

  -- if not found, try to open it
  if not tried_to_open [chat_world] and not w then
    local filename = GetInfo (67) .. chat_world .. ".mcl"
    Open (filename)
    w = GetWorld (chat_world)  -- try again
    if not w then
      ColourNote ("white", "red", "Can't open chat world file: " .. filename)
      tried_to_open [chat_world] = true -- don't repeatedly show failure message
    end -- can't find world 
  end -- can't find world first time around

  if w then  -- if present
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
    end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found

end -- send_to_window 

-- chat redirector
function chat_redirect (name, line, wildcards, styles)

  send_to_window ("Chats", styles)

  -- if ends with quote, end of multi-line chat
  if line:sub (-1) == '"' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else
    EnableTrigger ("multi_line_chat", true)  -- capture subsequent lines
  end -- if

end -- function chat_redirect 

-- who list redirector
function who_list_redirect (name, line, wildcards, styles)

  if string.match (line, "^%d+h,") then
    EnableTrigger ("multi_line_who", false)  -- no more lines to go
    return -- don't copy line
  else
    EnableTrigger ("multi_line_who", true)  -- capture subsequent lines
  end -- if

  send_to_window ("Who list", styles)

end -- function who_list_redirect 

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #18 on Tue 18 Mar 2008 06:24 AM (UTC)
Message
Version 4.23, just released, no longer will display "[Closed]" in the title of your extra (dummy) worlds.

- Nick Gammon

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

Posted by Zylogia   (12 posts)  [Biography] bio
Date Reply #19 on Thu 05 Jun 2008 02:55 AM (UTC)
Message
The whole thing works fine for me except for one minor issue. When a multi-line chat message comes into MUSHclient, it gets redirected to RoDchats as expected. However, the terminating CRLF gets processed in *both* windows, resulting in an unwanted status line in the main window (just as if I hit ENTER by itself).

I've installed v4.23, and revised the regex (which might be problem). The trigger code I'm using now is:

<triggers>
<trigger
enabled="y"
match="^\(OOC\)*"
omit_from_output="y"
regexp="y"
script="redirect"
sequence="100"
>
</trigger>

Ideas?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #20 on Thu 05 Jun 2008 04:45 AM (UTC)
Message
Quote:

match="^\(OOC\)*"


That doesn't look right - that will match OOC followed by zero or more right brackets. Perhaps you mean:

Quote:

match="^\(OOC\).*"


Anyway, I don't see how that is your problem. I gather you are saying you have a prompt line, which the chat then terminates (so this is the initial newline actually), and although the chat is moved to another window you still have the prompt, is that it?

I'm not sure of an easy solution, but one would be to match the prompt line, and discard it if it is the same as the 2nd last line. Something like this could do the trick:


<triggers>
  <trigger
   enabled="y"
   match="&lt;*hp *m *mv&gt; &lt;#*&gt;*"
   send_to="14"
   sequence="100"
  >
  <send>
if GetLineInfo (GetLinesInBufferCount () - 1, 1) == "%0" then
  DeleteLines (1)
end -- same as previous line
</send>
  </trigger>
</triggers>


You could need to modify the match part to be the same as your prompt. Now this should omit multiple prompts which are identical to the previous one.


- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #21 on Thu 05 Jun 2008 04:46 AM (UTC)
Message
I confused myself by naming two different things the same in my earlier example. This is the amended plugin that handles chats, and omits the original chat from the main window:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, June 30, 2007, 10:48  -->
<!-- MuClient version 4.13 -->

<!-- Plugin "Chat_Redirector" generated by Plugin Wizard -->

<!--
Edit plugin and change "chat_world" variable to be the name of the 
world you want chats to go to.
-->

<muclient>
<plugin
   name="Chat_Redirector"
   author="Nick Gammon"
   id="cb84a526b476f69f403517da"
   language="Lua"
   purpose="Redirects chat messages to another world"
   date_written="2007-06-30 10:45:35"
   requires="4.08"
   version="2.0"
   >
<description trim="y">
<![CDATA[
Redirects chats to the specified world.

Add or modify "chat" triggers to capture different sorts of message.

Change the variable "chat_world" to be the name of the world chats are to go to.
]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>

  <trigger
   enabled="y"
   match="^(\(.+\): )?[A-Za-z]+ (says|yells|tells you), &quot;.+"
   regexp="y"
   script="chat_redirect"
   omit_from_output="y"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="^You (tell|whisper) .+, &quot;.+"
   regexp="y"
   script="chat_redirect"
   omit_from_output="y"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="n"
   match="*"
   script="chat_redirect"
   name="multi_line_chat"
   omit_from_output="y"
   sequence="10"
  >
  </trigger>


</triggers>

<!--  Script  -->


<script>
<![CDATA[
chat_world = "RoD chats"
who_world = "Who List"

local tried_to_open = {}  -- set flag if can't open world

function send_to_window (world_name, styles)

  -- try to find "chat" world
  local w = GetWorld (world_name)  -- get "chat" world

  -- if not found, try to open it
  if not tried_to_open [world_name] and not w then
    local filename = GetInfo (67) .. world_name .. ".mcl"
    Open (filename)
    w = GetWorld (world_name)  -- try again
    if not w then
      ColourNote ("white", "red", "Can't open chat world file: " .. filename)
      tried_to_open [world_name] = true -- don't repeatedly show failure message
    end -- can't find world 
  end -- can't find world first time around

  if w then  -- if present
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
    end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found

end -- send_to_window 

-- chat redirector
function chat_redirect (name, line, wildcards, styles)

  send_to_window (chat_world, styles)

  -- if ends with quote, end of multi-line chat
  if line:sub (-1) == '"' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else
    EnableTrigger ("multi_line_chat", true)  -- capture subsequent lines
  end -- if

end -- function chat_redirect 

-- who list redirector
function who_list_redirect (name, line, wildcards, styles)

  if string.match (line, "^%d+h,") then
    EnableTrigger ("multi_line_who", false)  -- no more lines to go
    return -- don't copy line
  else
    EnableTrigger ("multi_line_who", true)  -- capture subsequent lines
  end -- if

  send_to_window (who_world, styles)

end -- function who_list_redirect 

]]>
</script>
</muclient>



- Nick Gammon

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

Posted by Zylogia   (12 posts)  [Biography] bio
Date Reply #22 on Thu 05 Jun 2008 04:33 PM (UTC)
Message
I tried this new version, and it has a strange result. When I first start up the two windows, everything works. However, as soon as a chat is redirected to the RoD Chats window, ALL subsequent output from commands given in the main window appears in RoD Chats. Chat output from other players continues to appear in RoD Chats, too.
[Go to top] top

Posted by Aromaros   (9 posts)  [Biography] bio
Date Reply #23 on Thu 05 Jun 2008 07:40 PM (UTC)
Message
Oh, I have this issue from time to time. At some points in the game the plugin will catch some text that confuses it, something with a few quotations in it I believe. Once it sees that it redirects everything to the secondary output window. I've been able to fix this just by saying something. It catches the quotes and stops sending everything to the output.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #24 on Thu 05 Jun 2008 09:16 PM (UTC)
Message
An example of a chat would help. The critical thing to get right is the function that detects when a chat is over. If that is wrong, it thinks everything is part of the chat.

This is the important part (near the end of the plugin):


 -- if ends with quote, end of multi-line chat
  if line:sub (-1) == '"' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else


This is cancelling the redirection when it gets a line ending in a double-quote. (The expression line:sub (-1) means the very last character).

If your line ends in a single quote, it would need to read instead:



 -- if ends with quote, end of multi-line chat
  if line:sub (-1) == "'" then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else


That might look the same but it is a single quote inside double quotes, rather than a double quote inside single quotes.

It might be more readable like this:


 -- if ends with quote, end of multi-line chat
  if line:sub (-1) == [[']] then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else


Now you can see the quote more easily.

You really need to closely look at the way chats are shown. For example, if it ends with double quote, period, like this:


Nick tells, you "hello".


Then you need to catch the period too. For example:


 -- if ends with quote, end of multi-line chat
  if line:sub (-2) == [[".]] then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else


Notice the -1 has become -2, which means the last 2 characters on the line.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #25 on Thu 05 Jun 2008 09:20 PM (UTC)
Message
Quote:

At some points in the game the plugin will catch some text that confuses it, something with a few quotations in it I believe.


Again, if this happens often, capture the whole lot around where it happens and post it (x-out names if you like), so we can analyze it.

However the way the plugin works, redirecting is turned on with a fairly specific trigger, it shouldn't just turn on when it hits a quote.

- Nick Gammon

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

Posted by Zylogia   (12 posts)  [Biography] bio
Date Reply #26 on Thu 05 Jun 2008 11:54 PM (UTC)
Message
Thanks for the response. Here is an extended log from the MUD.

Quote:
(OOC) Orion: Hoy.
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night

(OOC) Textor: Uh, ok. Well, one day a spider was walking along the forest. Then, this big, mean person started beating him with a newspaper. The spider was in pain, mangled from the beating, but he bit the abusive person. The End.
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night

inv
You are carrying nothing.
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night

(OOC) Namino blinks.
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night

ooc great, thanks
(OOC) Koreabard: great, thanks
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night



  • All chats start with the string '(OOC)'
  • Multiline chats do not have newlines -- they just wrap in the client window.
  • The next line after the chat always begins with 'H:'
  • I want that entire line to be ignored. But if it showed up in the chat window it would be OK.
  • The status line can end with any of a number of time strings -- about 35 different possibilities.
  • The line in the middle of the example, starting with 'inv', is a line (together with the following resulting line or lines) that should not be sent to the chat window.


[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #27 on Fri 06 Jun 2008 12:50 AM (UTC)
Message
If the chats are a single line, wrapped by the client, then you don't need all this complexity. Just use the plugin from page 1 of this thread, which assumed the chat was one line. You need to amend the matching regexp, that is all.

- Nick Gammon

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

Posted by Zylogia   (12 posts)  [Biography] bio
Date Reply #28 on Fri 06 Jun 2008 11:31 PM (UTC)
Message
Until you suggested a closer look at the MUD output, I had not realized that my "multi-line" chats were, in fact, just one-liners with wrapping. So, I went back to the simple plugin as you suggested.

However, my original problem still persists, that the chat output itself goes to the RoD Chats window, but a newline is processed in the main client window, which results in a status display line. (That's the default action for a blank CRLF).

[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #29 on Fri 06 Jun 2008 11:41 PM (UTC)
Message
Well that is not really the chat plugin's fault. I think what is happening is this. You get:


H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night
(OOC) Orion: Hoy.
(OOC) Namino blinks.
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night
(OOC) Koreabard: great, thanks
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night


You have successfully moved the chats to another window, leaving you with:


H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night
H:Healthy, S:Energetic, K:Energetic, F: 100, Camday night


This is nothing to do with a blank CRLF - it is simply what is left once you move the chats.

I suggest you adapt the trigger I gave earlier, which simply suppresses multiple prompts, if they are identical to the previous one.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


143,622 views.

This is page 2, subject is 8 pages long:  [Previous page]  1  2 3  4  5  6  7  8  [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]