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, 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 ➜ Miniwindows ➜ Help with IF statement to miniwindow

Help with IF statement to miniwindow

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


Posted by Hoboku   (2 posts)  Bio
Date Mon 23 Aug 2010 07:59 AM (UTC)

Amended on Mon 23 Aug 2010 08:29 AM (UTC) by Hoboku

Message
I am not sure how to make this work: I want to have proccess mobile information into a miniwindow if they are attacking a group mate. The trigger information i have so far is:
^(.*?) is (.*?) here\, fighting (.*?)\.$
- this matches - A peasant is standing here, fighting Bob.

What i would like is to have something like this,
for i,v in ipairs(resc) do
if v == "%3" then
Note "---- %3 ---- has agro from %1"
SetVariable("torescue","%3")
end -- if
end -- for

transfered into a miniwindow where i can easily see who is being attacked. I tried to insert this into the Current_Output plugin included with Mushclient, but without success.
One of the biggest problems I have is figuring out how to insert captured information to a window. I have looked at various examples of plugins but can not seem to grasp how it is written to the miniwindow.
Top

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 24 Aug 2010 01:19 AM (UTC)

Amended on Wed 15 Sep 2010 12:31 AM (UTC) by Nick Gammon

Message
To simplify answering this I made a new plugin that lets you display messages from any script (including the main world file, or another plugin).

Template:saveplugin=Messages_Window To save and install the Messages_Window plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Messages_Window.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Messages_Window.xml (which you just saved in step 3) as a plugin
  7. Click "Close"



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Messages_Window"
   author="Nick Gammon"
   id="126d9061f9758498c878a204"
   language="Lua"
   purpose="Shows messages in a miniwindow"
   date_written="2010-08-24 10:30"
   date_modified="2010-08-24 13:30"
   save_state="y"
   requires="4.55"
   version="1.2"
   >
   
<description trim="y">
<![CDATA[
Call from scripts to display information messages.

eg.

Note a message (starts a new line):

  CallPlugin ("126d9061f9758498c878a204", "MsgNote", "test note")
  CallPlugin ("126d9061f9758498c878a204", "MsgNote", "test note", "yellow") -- yellow text
  CallPlugin ("126d9061f9758498c878a204", "MsgNote", "test note", "yellow", "white") -- yellow on white

Tell a message in the default text colour (stays on same line):

  CallPlugin ("126d9061f9758498c878a204", "MsgTell", "test tell")
  CallPlugin ("126d9061f9758498c878a204", "MsgTell", "test tell", "yellow") -- yellow text
  CallPlugin ("126d9061f9758498c878a204", "MsgTell", "test tell", "yellow", "white") -- yellow on white
  
Clear the message window:

  CallPlugin ("126d9061f9758498c878a204", "MsgClear")

Hide the message window:

  CallPlugin ("126d9061f9758498c878a204", "MsgHide")

Show the message window:

  CallPlugin ("126d9061f9758498c878a204", "MsgShow")
  
Change the message window title:

  CallPlugin ("126d9061f9758498c878a204", "MsgTitle", "Combat text")
    
]]>
</description>
</plugin>

<!--  Script  -->


<script>
<![CDATA[

-- configuration

-- number of lines to show
local MAX_LINES = 20

-- font
local FONT_NAME = "Dina"
local FONT_SIZE = 8

-- where to put the window
local WINDOW_POSITION = miniwin.pos_top_right 

-- colours
local WINDOW_BACKGROUND_COLOUR = "black"
local WINDOW_TITLE_COLOUR = "white"
local WINDOW_TITLE_BACKGROUND = "darkgoldenrod"

local NOTE_COLOUR = "Cyan"


-- window title
local title = "Messages"

-- offset of text from edge
local TEXT_INSET = 5

-- where to store the message lines
local lines = {}  -- table of recent message lines
local styles = {} -- current line

-- display one line
local function show_line (n, styles)

  local left = TEXT_INSET
  local top = (n - 1) * font_height + TEXT_INSET
  
  -- display each style, including the appropriate background under it
  for _, v in ipairs (styles) do
    local width = WindowTextWidth (win, "f", v.text) -- get width of text
    local right = left + width                       -- work out RH side
    local bottom = top + font_height                 -- work out bottom
    WindowRectOp (win, miniwin.rect_fill, left, top, right, bottom, 
                  ColourNameToRGB (v.backcolour or WINDOW_BACKGROUND_COLOUR))  -- draw background
    WindowText (win, "f", v.text, left, top, window_width - TEXT_INSET, 0, 
                  ColourNameToRGB (v.textcolour or NOTE_COLOUR))  -- draw text
    left = left + width  -- advance horizontally
  end -- for each style run                 
  
end -- Display_Line

local function add_line (line)

  -- remove first line if filled up
  if #lines >= MAX_LINES then
    table.remove (lines, 1)
  end -- if 

  -- add new line
  table.insert (lines, line)

end -- add_line

-- here on output to display
local function redraw_all ()

  -- blank existing window contents
  WindowRectOp (win, miniwin.rect_fill, 0, 0, 0, 0, ColourNameToRGB (WINDOW_BACKGROUND_COLOUR))
  
  -- draw drag bar rectangle
  WindowRectOp (win, miniwin.rect_fill, 0, 0, 0, font_height, ColourNameToRGB (WINDOW_TITLE_BACKGROUND))
  
  local sz = WindowTextWidth (win, "fb", title)
  WindowText (win, "fb", title, (window_width - sz) / 2, 0, window_width - TEXT_INSET, 0, 
              ColourNameToRGB (WINDOW_TITLE_COLOUR))
  
  -- display all lines
  for k, v in ipairs (lines) do
    show_line (k + 1, v)
  end -- for
 
  Redraw ()
  
end -- end redraw_all

local function warning (msg)
  ColourNote ("white", "red", msg)
end -- warning

-- EXPOSED FUNCTIONS

-- hide window on removal
function OnPluginClose ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginClose

-- hide window on disable
function OnPluginDisable ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginDisable

-- show window on enable
function OnPluginEnable ()
  if #lines > 0 then
    WindowShow (win,  true)  -- show it
  end -- if
end -- OnPluginEnable

function OnPluginSaveState ()
  -- save window current location for next time  
  movewindow.save_state (win)
end -- function OnPluginSaveState


-- FOR CALLING BY SCRIPTS:

-- eg. CallPlugin ("126d9061f9758498c878a204", "MsgNote", "test note")
--     CallPlugin ("126d9061f9758498c878a204", "MsgNote", "test note", "yellow") -- yellow text
--     CallPlugin ("126d9061f9758498c878a204", "MsgNote", "test note", "yellow", "white") -- yellow on white

-- Note a line (starts a new line afterwards). Text colour and background colour are optional.

function MsgNote (text, textcolour, backcolour)

  -- add this style (if any text)
  if text then
  
    if type (text) ~= "string" then
     warning ("First argument to MsgNote must be message text (string)")
     return
    end -- if
    
    table.insert (styles, { text = text, textcolour = textcolour, backcolour = backcolour } )
  end -- if
    
  -- add all styles to this line
  add_line (styles)
  
  -- start new line
  styles = {}
  
  -- display existing lines
  redraw_all () 
  
  WindowShow (win,  true)  -- show it
  
end -- MsgNote


-- eg. CallPlugin ("126d9061f9758498c878a204", "MsgTell", "test note")
--     CallPlugin ("126d9061f9758498c878a204", "MsgTell", "test note", "yellow") -- yellow text
--     CallPlugin ("126d9061f9758498c878a204", "MsgTell", "test note", "yellow", "white") -- yellow on white

-- Tell a line (does not start a new line). Text colour and background colour are optional.

function MsgTell (text, textcolour, backcolour)
  
  if type (text) ~= "string" then
     warning ("First argument to MsgTell must be message text (string)")
     return
  end -- if

  -- add this style
  table.insert (styles, { text = text, textcolour = textcolour, backcolour = backcolour } )
end -- MsgTell

-- eg.  CallPlugin ("126d9061f9758498c878a204", "MsgClear")

function MsgClear ()
  lines = {}
  styles = {}
   -- display blank window
  redraw_all () 
end -- MsgClear

-- eg.  CallPlugin ("126d9061f9758498c878a204", "MsgHide")

function MsgHide ()
  WindowShow (win,  false)  -- hide it
end -- MsgHide

-- eg.  CallPlugin ("126d9061f9758498c878a204", "MsgShow")

function MsgShow ()
  WindowShow (win,  true)  -- show it
  redraw_all () 
end -- MsgShow

-- eg.  CallPlugin ("126d9061f9758498c878a204", "MsgTitle", "Combat Messages")

function MsgTitle (new_title)
  if type (new_title) ~= "string" then
     warning ("First argument to MsgTitle must be window title (string)")
     return
  end -- if
  
  title = new_title
  redraw_all () 
end -- MsgTitle

-- startup stuff - create window, find font characteristics

win = GetPluginID ()  -- get a unique name

-- make the window
WindowCreate (win, 0, 0, 1, 1, WINDOW_POSITION, 0, 0)  -- create window

fonts = utils.getfontfamilies ()

if not fonts.Dina then
  AddFont (GetInfo (66) .. "\\Dina.fon")
end -- if Dina not installed
               
-- grab a font
WindowFont (win, "f", FONT_NAME, FONT_SIZE) -- define font
WindowFont (win, "fb", FONT_NAME, FONT_SIZE, true) -- define font

-- work out how high and wide it is
font_height = WindowFontInfo (win, "f", 1)   -- height of the font  
wrap_column = GetOption ("wrap_column")

window_width = (wrap_column * WindowFontInfo (win, "f", 6)) + (TEXT_INSET * 2)
window_height = (MAX_LINES + 1) * font_height + TEXT_INSET * 2  -- one more line for title

require "movewindow"  -- load the movewindow.lua module

-- install the window movement handler, get back the window position
windowinfo = movewindow.install (win, WINDOW_POSITION)
 
-- remake the window with the correct width
WindowCreate (win, 
               windowinfo.window_left, 
               windowinfo.window_top, 
               window_width, window_height,              
               windowinfo.window_mode,   
               windowinfo.window_flags,
               0) 

-- add the drag handler so they can move the window around
movewindow.add_drag_handler (win, 0, 0, 0, font_height)
      
]]>
</script>

</muclient>


[EDIT] Amended to make a bit simpler.

The above plugin shows 20 lines of recent messages (you can change the 20 in the plugin) which then scroll off and disappear. You can drag the window around by the title bar.

You need MUSHclient 4.55 or more recent, see here for recent releases:

http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=1

In the case of your trigger (it would help to see the whole thing) ...

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


You can do something like this, if you install the above plugin:


 CallPlugin ("126d9061f9758498c878a204", "MsgNote","---- %3 ---- has aggro from %1")


Or you can simplify things a little bit by putting these functions in your script file (if you are using one)


function MsgNote (text, textcolour, backcolour)
  CallPlugin ("126d9061f9758498c878a204", "MsgNote", text, textcolour, backcolour)
end -- Msg_Note 

function MsgTell (text, textcolour, backcolour)
  CallPlugin ("126d9061f9758498c878a204", "MsgTell", text, textcolour, backcolour)
end -- Msg_Tell 

function MsgTitle (new_title)
  CallPlugin ("126d9061f9758498c878a204", "MsgTitle", new_title)
end -- MsgTitle 

function MsgClear (text)
  CallPlugin ("126d9061f9758498c878a204", "MsgClear")
end -- MsgClear


With those "stub" routines in your script file, you could just do this:


  MsgNote ("---- %3 ---- has agro from %1")


The difference between "Note" and "Tell" is like in normal MUSHclient scripting - MsgTell leaves the text on the same line, and the MsgNote starts a new line.

[EDIT] Changed 15 September 2010 to load the Dina font, and then load it into the miniwindow.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 24 Aug 2010 01:23 AM (UTC)

Amended on Tue 24 Aug 2010 03:48 AM (UTC) by Nick Gammon

Message
Example:


MsgNote ("A peasant is here, fighting Bill")
MsgNote ("A kobold is here, fighting Nick")
MsgNote ("Nick has aggro!", "red")



- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 24 Aug 2010 01:50 AM (UTC)

Amended on Tue 24 Aug 2010 03:51 AM (UTC) by Nick Gammon

Message
So your overall trigger might look like this:


<triggers>
  <trigger
   enabled="y"
   match="^(.*?) is (.*?) here\, fighting (.*?)\.$"
   regexp="y"
   send_to="12"
   sequence="110"
  >
  <send>

CallPlugin ("126d9061f9758498c878a204", "MsgNote", "---- %3 ---- has aggro from %1")

</send>
  </trigger>
</triggers>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Of course, you need the plugin installed for it to work.

And to illustrate how you might use multiple colours:


<triggers>
  <trigger
   enabled="y"
   match="^(.*?) is (.*?) here\, fighting (.*?)\.$"
   regexp="y"
   send_to="12"
   sequence="110"
  >
  <send>

CallPlugin ("126d9061f9758498c878a204", "MsgTell", "%3", "white")
CallPlugin ("126d9061f9758498c878a204", "MsgTell", " has aggro from ", "cyan")
CallPlugin ("126d9061f9758498c878a204", "MsgNote", "%1", "red")

</send>
  </trigger>
</triggers>



[EDIT] Amended plugin to put the colours second (so they can be optional) and also to allow for background colours.

- Nick Gammon

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

Posted by Hoboku   (2 posts)  Bio
Date Reply #4 on Tue 24 Aug 2010 04:09 AM (UTC)
Message
This is beyond what I was expecting, but exactly what I was looking for. Thank you very much.
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.


20,431 views.

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.