[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]  Plugins
. . -> [Subject]  Show current exits in a miniwindow
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Show current exits in a miniwindow

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


Posted by Nick Gammon   Australia  (21,648 posts)  [Biography] bio   Forum Administrator
Date Sat 07 Feb 2009 01:11 AM (UTC)

Amended on Sat 07 Feb 2009 05:02 AM (UTC) by Nick Gammon

Message
Here is another small, fun plugin. It is pretty trivial, it shows the current rooms exits in a small miniwindow in the top left corner. However that is reasonably useful, as the room description, telling you the current exits, may well scroll out of view as you chat with people, or fight mobs.

Hopefully it will illustrate the fundamentals of writing small miniwindow plugins, so you might be inspired to make something similar (eg. the name of the current mob you are fighting).

Save between the lines as Exits_Window.xml and use File menu -> Plugins to load that file as a plugin. It uses a simple trigger, matching on: Exits: *.

If your exits line looks a bit different, just change that spot.


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

<!-- MuClient version 4.37 -->

<muclient>
<plugin
   name="Exits_Window"
   author="Nick Gammon"
   id="fd1a20e303e48b78eceb103c"
   language="Lua"
   purpose="Redirects exits to a miniwindow"
   date_written="2009-02-03 17:00"
   requires="4.37"
   version="1.0"
   >

</plugin>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="Exits: *."
   script="exits_line"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Script  -->


<script>
<![CDATA[

-- configuration

-- font
FONT_NAME = "Lucida Console"
FONT_SIZE = 9

-- where to put the window
WINDOW_POSITION = 4  -- see below (4 is top left)

--[[
Useful positions:

4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]


-- colours
WINDOW_BACKGROUND_COLOUR = ColourNameToRGB ("olivedrab")
WINDOW_TEXT_COLOUR = ColourNameToRGB ("#002800")

-- offset of text from edge
HORIZONTAL_OFFSET = 5
VERTICAL_OFFSET = 2

-- here on getting an exits line
function exits_line (name, line, wildcards, styles)

  exits = line

  width   = WindowTextWidth (win, "f", exits) 

  -- make the window again the correct size
  WindowCreate (win, 0, 0, 
                width + (HORIZONTAL_OFFSET * 2), 
                font_height + (VERTICAL_OFFSET * 2), 
                WINDOW_POSITION, 0, 
                WINDOW_BACKGROUND_COLOUR)  -- create window

  WindowText (win, "f", exits, HORIZONTAL_OFFSET, VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
                    
  -- show window
  WindowShow (win,  true)  -- show it 
  
end -- end exits_line

-- 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 exits then
    WindowShow (win,  true)  -- show it
  end -- if
end -- OnPluginEnable

-- startup stuff

win = GetPluginID ()  -- get a unique name

-- make the window with zero size to load the font into
WindowCreate (win, 0, 0, 0, 0, WINDOW_POSITION, 0, 
              WINDOW_BACKGROUND_COLOUR)  -- create window
               
-- grab a font
WindowFont (win, "f", FONT_NAME, FONT_SIZE) -- define font

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

]]>
</script>


</muclient>



- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,648 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 07 Feb 2009 01:12 AM (UTC)
Message

Example of it in operation:


- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,648 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 07 Feb 2009 09:43 PM (UTC)
Message
Of course, you don't have to show just exits. Simply by changing the trigger, it could show what the current room name is, or what mob you last killed, or if you are on a quest, how far through you are (eg. "killed 3 of 5 rats").

- Nick Gammon

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

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #3 on Fri 27 Feb 2009 02:28 PM (UTC)
Message
Hmm, I have a thought that might be interesting. I use the "show_killed" plugin, could this exits plugin be modified a bit to show the total number of kills under the exits? I like to kill a certain number a day and this would really help in that process.
[Go to top] top

Posted by Nick Gammon   Australia  (21,648 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 27 Feb 2009 06:58 PM (UTC)
Message
Well anything is possible. I haven't tested, but a change like this should roughly do it:


-- make the window again the correct size
  WindowCreate (win, 0, 0, 
                width + (HORIZONTAL_OFFSET * 2), 
                font_height * 2  + (VERTICAL_OFFSET * 2), 
                WINDOW_POSITION, 0, 
                WINDOW_BACKGROUND_COLOUR)  -- create window

  WindowText (win, "f", exits, HORIZONTAL_OFFSET, VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
  WindowText (win, "f", "your other stuff here", HORIZONTAL_OFFSET, font_height  + VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)



- Nick Gammon

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

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #5 on Sat 28 Feb 2009 12:49 AM (UTC)
Message
My problem is that it doesn't seem to want to recall in the killed_mobs, Possibly because they came from the other script. So would I need to combine scripts in order to get this to work?
[Go to top] top

Posted by Nick Gammon   Australia  (21,648 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sat 28 Feb 2009 05:39 AM (UTC)
Message
Yes, you could combine them. Or you could extract out the kills information from wherever it is. If the kill count is in another plugin you could use GetPluginVariable to find the number of kills.


http://www.gammon.com.au/scripts/doc.php?function=GetPluginVariable

- Nick Gammon

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

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #7 on Sat 28 Feb 2009 03:25 PM (UTC)
Message
sighs, I so suck at trying to program. I tried to combine the two but I'm getting errors and I'm not experienced enough to sort out what I did wrong.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, January 08, 2008, 3:26 -->
<!-- MuClient version 4.20 -->

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

<muclient>
<plugin
name="Count_Mobs_Killed"
author="Nick Gammon"
id="f11e3bb0e48d526152798439"
language="Lua"
purpose="Counts how many mobs I have killed"
save_state="y"
date_written="2008-01-08 15:17:18"
requires="4.00"
version="1.0"
>
<description trim="y">
<![CDATA[
Counts how many mobs have been killed.

Type "show_killed" to see a count.
]]>
</description>

</plugin>


<!-- Triggers -->

<triggers>
<trigger
custom_colour="2"
enabled="y"
match="* dies."
send_to="12"
sequence="100"
>
<send>killed_mobs = killed_mobs or {} -- make mobs table

mob_name = "%1" -- this mob's name (first wildcard)

-- add this mob if first time

killed_mobs [mob_name] = killed_mobs [mob_name] or { count = 0 }

-- add 1 to count of mobs
killed_mobs [mob_name].count = killed_mobs [mob_name].count + 1

-- remember when we last killed it
killed_mobs [mob_name].last_time = os.time ()

</send>
</trigger>

<trigger
enabled="y"
match=" Obvious exits : *."
script="exits_line"
sequence="100"
>
</trigger>
</triggers>

<!-- Aliases -->

<aliases>
<alias
match="show_killed"
enabled="y"
send_to="12"
sequence="100"
>
<send>if not killed_mobs or next (killed_mobs) == nil then
ColourNote ("white", "blue", "No mobs killed yet")
return
end -- if nothing

-- go through each one

count = 0
for k, v in pairs (killed_mobs) do
Note (string.format ("%%-30s x %%i (last at %%s)",
k,
v.count,
os.date ("%%H:%%M %%d %%b %%Y", v.last_time)))
count = count + v.count
end -- for loop

-- show total

Note (string.format ("%%5i mobs killed.", count))</send>
</alias>
</aliases>

<aliases>
<alias
match="reset_mob_counts"
enabled="y"
send_to="12"
sequence="100"
>
<send>

killed_mobs = {} -- clear mobs table

</send>
</alias>
</aliases>

<!-- Script -->


<script>
<![CDATA[

-- on plugin install, convert variable into Lua table
function OnPluginInstall ()
require "serialize" -- needed to serialize table to string
killed_mobs = {} -- ensure table exists, if not loaded from variable
assert (loadstring (GetVariable ("killed_mobs") or "")) ()
end -- function OnPluginInstall

-- on saving state, convert Lua table back into string variable
function OnPluginSaveState ()
SetVariable ("killed_mobs", "killed_mobs = " ..
serialize.save_simple (killed_mobs))
end -- function OnPluginSaveState


-- configuration

-- font
FONT_NAME = "Lucida Console"
FONT_SIZE = 9

-- where to put the window
WINDOW_POSITION = 4 -- see below (4 is top left)

--[[
Useful positions:

4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]


-- colours
WINDOW_BACKGROUND_COLOUR = ColourNameToRGB ("olivedrab")
WINDOW_TEXT_COLOUR = ColourNameToRGB ("#002800")

-- offset of text from edge
HORIZONTAL_OFFSET = 5
VERTICAL_OFFSET = 2

-- here on getting an exits line
function exits_line (name, line, wildcards, styles)

exits = line

width = WindowTextWidth (win, "f", exits)

-- make the window again the correct size
WindowCreate (win, 0, 0,
width + (HORIZONTAL_OFFSET * 2),
font_height *2 + (VERTICAL_OFFSET * 2),
WINDOW_POSITION, 0,
WINDOW_BACKGROUND_COLOUR) -- create window


WindowText (win, "f", exits, HORIZONTAL_OFFSET, VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
WindowText (win, "f", killed_mobs" mobs killed.", HORIZONTAL_OFFSET, font_height + VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)

-- show window
WindowShow (win, true) -- show it

end -- end exits_line

-- 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 exits then
WindowShow (win, true) -- show it
end -- if
end -- OnPluginEnable

-- startup stuff

win = GetPluginID () -- get a unique name

-- make the window with zero size to load the font into
WindowCreate (win, 0, 0, 0, 0, WINDOW_POSITION, 0,
WINDOW_BACKGROUND_COLOUR) -- create window

-- grab a font
WindowFont (win, "f", FONT_NAME, FONT_SIZE) -- define font

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

]]>
</script>

<!-- Plugin help -->

<aliases>
<alias
script="OnHelp"
match="Count_Mobs_Killed:help"
enabled="y"
>
</alias>
</aliases>

<script>
<![CDATA[
function OnHelp ()
world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script>

</muclient>

I'm sure it must be something silly you'll laugh at so feel free to.
[Go to top] top

Posted by Nick Gammon   Australia  (21,648 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sat 28 Feb 2009 07:09 PM (UTC)

Amended on Sat 28 Feb 2009 07:11 PM (UTC) by Nick Gammon

Message
Quote:


I'm getting errors...


It always helps to paste the error, that narrows it down a lot. I presume this is it?


Plugin: Count_Mobs_Killed (called from world: smaug 2)
Function/Sub: exits_line called by trigger
Reason: processing trigger ""
[string "Plugin"]:60: attempt to call global 'killed_mobs' (a table value)
stack traceback:
        [string "Plugin"]:60: in function <[string "Plugin"]:45>
Error context in script:
  56 :                 WINDOW_BACKGROUND_COLOUR)  -- create window
  57 : 
  58 : 
  59 :   WindowText (win, "f", exits, HORIZONTAL_OFFSET, VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
  60*:   WindowText (win, "f", killed_mobs" mobs killed.", HORIZONTAL_OFFSET, font_height  + VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
  61 :                     
  62 :   -- show window
  63 :   WindowShow (win,  true)  -- show it 
  64 :   


It was basically crashing on this bit: killed_mobs" mobs killed."

At the very least, you need to concatentate them together, like this:

killed_mobs" .. mobs killed."

However even that doesn't work because killed_mobs is a table of mobs, not a single number.

I had to add some extra code to count the number, from going through the table.

Then there was the problem of getting the count to update after each kill, even if you didn't see another "Exits" line, so a bit more fiddling around got that working. Below is my amended plugin:



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, January 08, 2008, 3:26 -->
<!-- MuClient version 4.20 -->

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

<muclient>
<plugin
name="Count_Mobs_Killed"
author="Nick Gammon"
id="f11e3bb0e48d526152798439"
language="Lua"
purpose="Counts how many mobs I have killed"
save_state="y"
date_written="2008-01-08 15:17:18"
requires="4.00"
version="1.0"
>
<description trim="y">
<![CDATA[
Counts how many mobs have been killed.

Type "show_killed" to see a count.
]]>
</description>

</plugin>


<!-- Triggers -->

<triggers>
<trigger
custom_colour="2"
enabled="y"
match="* dies."
send_to="12"
sequence="100"
>
<send>killed_mobs = killed_mobs or {} -- make mobs table

mob_name = "%1" -- this mob's name (first wildcard)

-- add this mob if first time

killed_mobs [mob_name] = killed_mobs [mob_name] or { count = 0 }

-- add 1 to count of mobs
killed_mobs [mob_name].count = killed_mobs [mob_name].count + 1

-- remember when we last killed it
killed_mobs [mob_name].last_time = os.time ()

-- update miniwindow
exits_line ("died_trigger")

</send>
</trigger>

  <trigger
   enabled="y"
   match="   Obvious exits : *."
   script="exits_line"
   name="exits_trigger"
   sequence="100"
  >
  </trigger>
</triggers>

<!-- Aliases -->

<aliases>
<alias
match="show_killed"
enabled="y"
send_to="12"
sequence="100"
>
<send>
if not killed_mobs or next (killed_mobs) == nil then
ColourNote ("white", "blue", "No mobs killed yet")
return
end -- if nothing

-- go through each one

count = 0
for k, v in pairs (killed_mobs) do
Note (string.format ("%%-30s x %%i (last at %%s)",
k, 
v.count,
os.date ("%%H:%%M %%d %%b %%Y", v.last_time)))
count = count + v.count
end -- for loop

-- show total

Note (string.format ("%%5i mobs killed.", count))</send>
</alias>
</aliases>

<aliases>
<alias
match="reset_mob_counts"
enabled="y"
send_to="12"
sequence="100"
>
<send>

killed_mobs = {} -- clear mobs table

</send>
</alias>
</aliases>

<!-- Script -->


<script>
<![CDATA[

-- on plugin install, convert variable into Lua table
function OnPluginInstall ()
require "serialize" -- needed to serialize table to string
killed_mobs = {} -- ensure table exists, if not loaded from variable
assert (loadstring (GetVariable ("killed_mobs") or "")) ()
end -- function OnPluginInstall

-- on saving state, convert Lua table back into string variable
function OnPluginSaveState ()
SetVariable ("killed_mobs", "killed_mobs = " ..
serialize.save_simple (killed_mobs))
end -- function OnPluginSaveState


-- configuration

-- font
FONT_NAME = "Lucida Console"
FONT_SIZE = 9

-- where to put the window
WINDOW_POSITION = 4  -- see below (4 is top left)

--[[
Useful positions:

4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]


-- colours
WINDOW_BACKGROUND_COLOUR = ColourNameToRGB ("olivedrab")
WINDOW_TEXT_COLOUR = ColourNameToRGB ("#002800")

-- offset of text from edge
HORIZONTAL_OFFSET = 5
VERTICAL_OFFSET = 2

-- here on getting an exits line
function exits_line (name, line, wildcards, styles)

  -- only have exits line if called from exits_trigger
  if name == "exits_trigger" then
    exits = Trim (line)
  end -- if
  
  -- if no exits line, can't make the window
  if not exits then
    return
  end -- if

  width   = WindowTextWidth (win, "f", exits) 

  -- make the window again the correct size
  WindowCreate (win, 0, 0, 
                width + (HORIZONTAL_OFFSET * 2), 
                font_height *2 + (VERTICAL_OFFSET * 2), 
                WINDOW_POSITION, 0, 
                WINDOW_BACKGROUND_COLOUR)  -- create window


  -- count total mobs killed
  local count = 0
  if killed_mobs then
    for k, v in pairs (killed_mobs) do
      count = count + v.count
    end -- for loop
  end -- if table exists

  WindowText (win, "f", exits, HORIZONTAL_OFFSET, VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
  WindowText (win, "f", count .. " mobs killed.", HORIZONTAL_OFFSET, font_height  + VERTICAL_OFFSET, 0, 0, WINDOW_TEXT_COLOUR)
                    
  -- show window
  WindowShow (win,  true)  -- show it 
  
end -- end exits_line

-- 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 exits then
    WindowShow (win,  true)  -- show it
  end -- if
end -- OnPluginEnable

-- startup stuff

win = GetPluginID ()  -- get a unique name

-- make the window with zero size to load the font into
WindowCreate (win, 0, 0, 0, 0, WINDOW_POSITION, 0, 
              WINDOW_BACKGROUND_COLOUR)  -- create window
               
-- grab a font
WindowFont (win, "f", FONT_NAME, FONT_SIZE) -- define font

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

]]>
</script>

<!-- Plugin help -->

<aliases>
<alias
script="OnHelp"
match="Count_Mobs_Killed:help"
enabled="y"
>
</alias>
</aliases>

<script>
<![CDATA[
function OnHelp ()
world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 

</muclient>

- Nick Gammon

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

Posted by Istarian   (7 posts)  [Biography] bio
Date Reply #9 on Sun 09 Oct 2011 05:17 PM (UTC)
Message
Having trouble getting this plugin to work. Other than "installing" and enabling the plugin, what else needs to be done to get it to work? Is it incompatible with some versions of MUSHclient or something?
[Go to top] top

Posted by Istarian   (7 posts)  [Biography] bio
Date Reply #10 on Sun 09 Oct 2011 08:17 PM (UTC)
Message
Well, scratch that, now it seems to work. Odd, must have messed something up somehow.
[Go to top] top

Posted by Neves   USA  (78 posts)  [Biography] bio
Date Reply #11 on Thu 21 Jun 2012 12:26 PM (UTC)
Message
I'm trying to edit this plugin to work with the MUD I am playing. The room exits show after the room desc in short between square brackets like this:
The middle of a gloomy back-alley [n,nw,se].

I would have thought it would match "\[*", but it doesn't seem to be working, any ideas what to change the match line to?

Thanks,
Edge
[Go to top] top

Posted by Fiendish   USA  (1,774 posts)  [Biography] bio   Global Moderator
Date Reply #12 on Thu 21 Jun 2012 11:42 PM (UTC)
Message
Why do you have a backslash?

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Neves   USA  (78 posts)  [Biography] bio
Date Reply #13 on Thu 28 Jun 2012 10:38 AM (UTC)
Message
I thought that was the escape character, I don't need it?
[Go to top] top

Posted by Fiendish   USA  (1,774 posts)  [Biography] bio   Global Moderator
Date Reply #14 on Sat 30 Jun 2012 06:13 PM (UTC)

Amended on Sat 30 Jun 2012 06:21 PM (UTC) by Fiendish

Message
"\[*" as a glob pattern will match
Quote:
"\[asdfasdhfsadfasdfasfda..."
or
Quote:
"\["


"\[*" as a regex pattern will match
Quote:
"[[[[[[[[[[[[[[[[..."
or
Quote:
""


Neither will match
Quote:
"[asdfasd..."

https://github.com/fiendish/aardwolfclientpackage
[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.


15,595 views.

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]