[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]  Aardwolf stats in miniwindow.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Aardwolf stats in miniwindow.

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


Posted by Blainer   (191 posts)  [Biography] bio
Date Wed 19 Aug 2009 04:52 AM (UTC)

Amended on Thu 20 Aug 2009 11:47 PM (UTC) by Blainer

Message
This puts your stats in a small window designed to sit at the top of the screen.
Template:saveplugin=Aardwolf_Stats_Window To save and install the Aardwolf_Stats_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 Aardwolf_Stats_Window.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Aardwolf_Stats_Window.xml (which you just saved in step 3) as a plugin
  7. Click "Close"

The plugin requires Stats_Detector.xml from the link below.
Template:post=8776 Please see the forum thread: http://gammon.com.au/forum/?id=8776.

------------------------------------------

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, August 19, 2009, 7:38 AM -->
<!-- MuClient version 4.43 -->

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

<muclient>
<plugin
   name="Aardwolf_Stats_Miniwindow"
   author="Blainer"
   id="124279faf50f012ce0fdd17c"
   language="Lua"
   purpose="Put aardwolf stats in a miniwindow"
   date_written="2009-08-19 07:37:33"
   requires="4.43"
   version="1.0"
   save_state="y"
   >
<description trim="n">
<![CDATA[
Uses the xStats_Detector.xml to put a one line bar with player states, align, exp to level and gold at the top of the screen.
]]>
</description>

</plugin>



<!--  Get our standard constants -->

<include name="constants.lua"/>
<!--  Script  -->

<script>
<![CDATA[

require "movewindow"
require "mw"

-- Options --------------
local WIN_STACK             = "aa"
local TITLE                 = "Aardwolf Player Stats"
local BACKGROUND_COLOUR     = 0x00220E
local TEXT_OFFSET           = "2"
local BORDER_WIDTH          = "1"
local LINE_SPACING          = "1"
local FONT_NAME             = "Courier"
local FONT_SIZE             = 8

function Draw_Window (t)

    fstr = "@YStr @g\[@w%3d@g/@w%-3d@g\] @YInt @g\[@w%3d@g/@w%-3d@g\] @YWis @g\[@w%3d@g/@w%-3d@g\] @YDex @g\[@w%3d@g/@w%-3d@g\] @YCon @g\[@w%3d@g/@w%-3d@g\] @YLuck @g\[@w%3d@g/@w%-3d@g\] @YHitroll @g\[ @w%d @g\] @YDamroll @g\[ @w%d @g\] @YExp to Level @g\[ @w%d @g\] @YLevel @g\[ @W%d @g\] @YAlignment @g\[ @w%d @g\] @YGold @g\[ @Y%d @g\]"
    s = fstr:format(t.str, t.base_str, t.int, t.base_int, t.wis, t.base_wis, t.dex, t.base_dex, t.con, t.base_con, t.luck, t.base_luck, t.hitroll, t.damroll, t.to_level, t.level, t.align, t.gold)
    text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))
    window_width = text_width + TEXT_OFFSET * 2
    window_height = font_height + (TEXT_OFFSET * 2)
    check(WindowCreate (win,
            windowinfo.window_left,
            windowinfo.window_top,
            window_width,     -- width
            window_height,    -- height
            windowinfo.window_mode,
            windowinfo.window_flags,
            BACKGROUND_COLOUR))
    left    = TEXT_OFFSET
    top     = TEXT_OFFSET
    bottom  = top + font_height
    right   = left + text_width
    mw.colourtext (win, font_id, s, left, top, right, bottom, false)
    movewindow.add_drag_handler (win, 0, 0, WindowInfo (win, 3), WindowInfo (win, 4), 1)
    WindowShow (win, true)

end

function OnPluginInstall ()

    win = WIN_STACK .. GetPluginID ()

    local fonts = utils.getfontfamilies ()
    if fonts[FONT_NAME] then
        font_size = FONT_SIZE
        font_name = FONT_NAME
    elseif fonts.Dina then
        font_size = 8
        font_name = "Dina"    -- the actual font
    else
        font_size = 10
        font_name = "Courier"
    end -- if

    font_id = "stat_font"

    windowinfo = movewindow.install (win, 4)

    check (WindowCreate (win,
        windowinfo.window_left,
        windowinfo.window_top,
        1, 1,
        windowinfo.window_mode,
        windowinfo.window_flags,
        BACKGROUND_COLOUR) )

    WindowFont (win, font_id, font_name, font_size, false, false, false, false, 0, 0)  -- normal
    font_height = WindowFontInfo (win, font_id, 1)  -- height

    if GetVariable ("enabled") == "false" then
        ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
        check (EnablePlugin(GetPluginID (), false))
        return
    end -- they didn't enable us last time


end -- OnPluginInstall

function OnPluginEnable ()

    OnPluginInstall ()

end -- OnPluginEnable

function OnPluginClose ()

    OnPluginDisable ()

end -- OnPluginClose

function OnPluginDisable ()

  WindowShow (win, false)

end -- OnPluginDisable

function OnPluginSaveState ()

  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))

  movewindow.save_state (win)

end -- OnPluginSaveState

function OnPluginBroadcast (msg, id, name, text)

  if msg == 1 and id == "8a710e0783b431c06d61a54c" then
    local stats = GetPluginVariableList("8a710e0783b431c06d61a54c")
    Draw_Window (stats)
  end -- stats changed

end

]]>
</script>
</muclient>

------------------------------------------
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #1 on Thu 20 Aug 2009 10:57 PM (UTC)
Message
-Plugin will now install to the top left of screen.
-Plugin will now remove the window when uninstalled.
-Added colours to make it easier to read.
[Go to top] top

Posted by Crowe   (21 posts)  [Biography] bio
Date Reply #2 on Thu 21 Jan 2010 03:04 PM (UTC)
Message
I am having difficulty enabling this plug-in. I was testing it out and disabled it and re-enabling it. Now, I am unable to re-enable the plug-in. I have deleted the plug-in, recopied it from this website, and saved in a new file. I am using the health bar plug-in. Could this be affecting the plug-in? Any help would be helpful.
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 21 Jan 2010 07:12 PM (UTC)
Message
There should be a "state" folder under the plugins directory. Perhaps that has recorded some off-screen location for the window.

In that folder look for a file with the plugin ID in the filename, ie. "124279faf50f012ce0fdd17c" (with another long number next to it which will be your world file ID).

Delete that file, and try again. Do that when the plugin is *not* installed.

- Nick Gammon

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

Posted by Crowe   (21 posts)  [Biography] bio
Date Reply #4 on Sun 21 Feb 2010 05:36 PM (UTC)
Message
Thank you for pointing that out to me Mr. Gammon. I was wondering what is the piece of code I need to break the line of information from Blainer's stats bar into two lines. Right now it is one line and too long for my screen. I was able to remove some of the information, but I am sort of confused on how to break it up into two lines.
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 21 Feb 2010 07:41 PM (UTC)
Message
Looks like he is using colourtext to display the text. I would split up the text into two parts, and then do two lots of colourtext, eg:


mw.colourtext (win, font_id, line1, left, top, 0, 0, false)
left    = TEXT_OFFSET
top     = top + font_height
mw.colourtext (win, font_id, line2, left, top, 0, 0, false)



- Nick Gammon

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

Posted by Crowe   (21 posts)  [Biography] bio
Date Reply #6 on Sun 21 Feb 2010 08:45 PM (UTC)

Amended on Sun 21 Feb 2010 09:58 PM (UTC) by Nick Gammon

Message
I have tried to piece this together, but I cannot get it to work correctly. What mistake am I making here?


function Draw_Window (t)

    fstr = "@YStr @g\[@w%3d@g/@w%-3d@g\] @YInt @g\[@w%3d@g/@w%-3d@g\] @YWis @g\[@w%3d@g/@w%-3d@g\] @YDex @g\[@w%3d@g/@w%-3d@g\] @YCon @g\[@w%3d@g/@w%-3d@g\] @YLuck @g\[@w%3d@g/@w%-3d@g\] @YHitroll @g\[ @w%d @g\] @YDamroll @g\[ @w%d @g\] @YExp to Level @g\[ @w%d @g\] @YLevel @g\[ @W%d @g\] @YAlignment @g\[ @w%d @g\] @YGold @g\[ @Y%d @g\]"
    line1 = fstr:format(t.str, t.base_str, t.int, t.base_int, t.wis, t.base_wis, t.dex, t.base_dex, t.con, t.base_con, t.luck, t.base_luck, t.hitroll, t.damroll)
    line2 = fstr:format(t.to_level, t.level, t.align, t.gold)
    text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))
    window_width = text_width + TEXT_OFFSET * 2
    window_height = font_height + (TEXT_OFFSET * 2)
    check(WindowCreate (win,
            windowinfo.window_left,
            windowinfo.window_top,
            window_width,     -- width
            window_height,    -- height
            windowinfo.window_mode,
            windowinfo.window_flags,
            BACKGROUND_COLOUR))
    left    = TEXT_OFFSET
    top     = TEXT_OFFSET
    bottom  = top + font_height
    right   = left + text_width
    mw.colourtext (win, font_id, line1, left, top, 0, 0, false)
    left    = TEXT_OFFSET
    top     = top + font_height
    mw.colourtext (win, font_id, line2, left, top, 0, 0, false)
    movewindow.add_drag_handler (win, 0, 0, WindowInfo (win, 3), WindowInfo (win, 4), 1)
    WindowShow (win, true)

end
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sun 21 Feb 2010 10:01 PM (UTC)
Message
Well you didn't say in what way, which always helps, but for one thing you still only have one "fstr" which is your formatting string, but you now have two lines.

So you really want fstr1 (for formatting line 1) and fstr2 (for formatting line 2).

- Nick Gammon

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

Posted by Crowe   (21 posts)  [Biography] bio
Date Reply #8 on Sun 21 Feb 2010 11:58 PM (UTC)
Message
Run-time error
Plugin: Aardwolf_Stats_Miniwindow (called from world: Aardwolf)
Function/Sub: OnPluginBroadcast called by Plugin Aardwolf_Stats_Miniwindow
Reason: Executing plugin Aardwolf_Stats_Miniwindow sub OnPluginBroadcast
[string "Plugin"]:172: attempt to index global 'fstr2' (a nil value)
stack traceback:
[string "Plugin"]:172: in function 'Draw_Window'
[string "Plugin"]:267: in function <[string "Plugin"]:263>
Error context in script:
168 : fstr = "@YStr @g\[@w%3d@g/@w%-3d@g\] @YInt @g\[@w%3d@g/@w%-3d@g\] @YWis @g\[@w%3d@g/@w%-3d@g\] @YDex @g\[@w%3d@g/@w%-3d@g\] @YCon @g\[@w%3d@g/@w%-3d@g\] @YLuck @g\[@w%3d@g/@w%-3d@g\] @YHitroll @g\[ @w%d @g\] @YDamroll @g\[ @w%d @g\]"
169 :
170 : fstr1 = "@YExp to Level @g\[ @w%d @g\] @YLevel @g\[ @W%d @g\] @YAlignment @g\[ @w%d @g\] @YGold @g\[ @Y%d @g\]"
171 : line1 = fstr1:format(t.str, t.base_str, t.int, t.base_int, t.wis, t.base_wis, t.dex, t.base_dex, t.con, t.base_con, t.luck, t.base_luck, t.hitroll, t.damroll)
172*: line2 = fstr2:format(t.to_level, t.level, t.align, t.gold)
173 : text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))
174 : window_width = text_width + TEXT_OFFSET * 2
175 : window_height = font_height + (TEXT_OFFSET * 2)
176 : check(WindowCreate (win,


I did change to this:
function Draw_Window (t)

fstr = "@YStr @g\[@w%3d@g/@w%-3d@g\] @YInt @g\[@w%3d@g/@w%-3d@g\] @YWis @g\[@w%3d@g/@w%-3d@g\] @YDex @g\[@w%3d@g/@w%-

3d@g\] @YCon @g\[@w%3d@g/@w%-3d@g\] @YLuck @g\[@w%3d@g/@w%-3d@g\] @YHitroll @g\[ @w%d @g\] @YDamroll @g\[ @w%d @g\]"

fstr1 = "@YExp to Level @g\[ @w%d @g\] @YLevel @g\[ @W%d @g\] @YAlignment @g\[ @w%d @g\] @YGold @g\[ @Y%d @g\]"
line1 = fstr1:format(t.str, t.base_str, t.int, t.base_int, t.wis, t.base_wis, t.dex, t.base_dex, t.con, t.base_con,

t.luck, t.base_luck, t.hitroll, t.damroll)
line2 = fstr2:format(t.to_level, t.level, t.align, t.gold)
text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))
window_width = text_width + TEXT_OFFSET * 2
window_height = font_height + (TEXT_OFFSET * 2)
check(WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
window_width, -- width
window_height, -- height
windowinfo.window_mode,
windowinfo.window_flags,
BACKGROUND_COLOUR))
left = TEXT_OFFSET
top = TEXT_OFFSET
bottom = top + font_height
right = left + text_width
mw.colourtext (win, font_id, line1, left, top, 0, 0, false)
left = TEXT_OFFSET
top = top + font_height
mw.colourtext (win, font_id, line2, left, top, 0, 0, false)
movewindow.add_drag_handler (win, 0, 0, WindowInfo (win, 3), WindowInfo (win, 4), 1)
WindowShow (win, true)

end



The rest of the script I have not changed. Where is my coding error? I feel like I am learning a new language. lol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Mon 22 Feb 2010 12:01 AM (UTC)
Message
Crowe said:

[string "Plugin"]:172: attempt to index global 'fstr2' (a nil value)

168 : fstr = "@YStr @g[@w%3d@g/@w%-3d@g] @YInt @g[@w%3d@g/@w%-3d@g] @YWis @g[@w%3d@g/@w%-3d@g] @YDex @g[@w%3d@g/@w%-3d@g] @YCon @g[@w%3d@g/@w%-3d@g] @YLuck @g[@w%3d@g/@w%-3d@g] @YHitroll @g[ @w%d @g] @YDamroll @g[ @w%d @g]"
169 :
170 : fstr1 = "@YExp to Level @g[ @w%d @g] @YLevel @g[ @W%d @g] @YAlignment @g[ @w%d @g] @YGold @g[ @Y%d @g]"

171 : line1 = fstr1:format(t.str, t.base_str, t.int, t.base_int, t.wis, t.base_wis, t.dex, t.base_dex, t.con, t.base_con, t.luck, t.base_luck, t.hitroll, t.damroll)
172*: line2 = fstr2:format(t.to_level, t.level, t.align, t.gold)

Very first thing I noticed: you're defining fstr and fstr1, but using fstr1 and fstr2 - see my underlines.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Crowe   (21 posts)  [Biography] bio
Date Reply #10 on Mon 22 Feb 2010 12:14 AM (UTC)
Message
Thank you for pointing that out. This is what I have now.

function Draw_Window (t)

fstr1 = "@YStr @g\[@w%3d@g/@w%-3d@g\] @YInt @g\[@w%3d@g/@w%-3d@g\] @YWis @g\[@w%3d@g/@w%-3d@g\] @YDex @g\[@w%3d@g/@w%-3d@g\] @YCon @g\[@w%3d@g/@w%-3d@g\] @YLuck @g\[@w%3d@g/@w%-3d@g\] @YHitroll @g\[ @w%d @g\] @YDamroll @g\[ @w%d @g\]"
fstr2 = "@YExp to Level @g\[ @w%d @g\] @YLevel @g\[ @W%d @g\] @YAlignment @g\[ @w%d @g\] @YGold @g\[ @Y%d @g\]"
line1 = fstr1:format(t.str, t.base_str, t.int, t.base_int, t.wis, t.base_wis, t.dex, t.base_dex, t.con, t.base_con, t.luck, t.base_luck, t.hitroll, t.damroll)
line2 = fstr2:format(t.to_level, t.level, t.align, t.gold)
text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))
window_width = text_width + TEXT_OFFSET * 2
window_height = font_height + (TEXT_OFFSET * 2)
check(WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
window_width, -- width
window_height, -- height
windowinfo.window_mode,
windowinfo.window_flags,
BACKGROUND_COLOUR))
left = TEXT_OFFSET
top = TEXT_OFFSET
bottom = top + font_height
right = left + text_width
mw.colourtext (win, font_id, line1, left, top, 0, 0, false)
left = TEXT_OFFSET
top = top + font_height
mw.colourtext (win, font_id, line2, left, top, 0, 0, false)
movewindow.add_drag_handler (win, 0, 0, WindowInfo (win, 3), WindowInfo (win, 4), 1)
WindowShow (win, true)

end


I am getting this message now.


Run-time error
Plugin: Aardwolf_Stats_Miniwindow (called from world: Aardwolf)
Function/Sub: OnPluginBroadcast called by Plugin Aardwolf_Stats_Miniwindow
Reason: Executing plugin Aardwolf_Stats_Miniwindow sub OnPluginBroadcast
F:\Personal Files\MUD Files\MUSHclient\lua\mw.lua:195: attempt to index local 's' (a nil value)
stack traceback:
F:\Personal Files\MUD Files\MUSHclient\lua\mw.lua:195: in function 'strip_colours'
[string "Plugin"]:172: in function 'Draw_Window'
[string "Plugin"]:266: in function <[string "Plugin"]:262>
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Mon 22 Feb 2010 12:32 AM (UTC)
Message
In the original it had:


fstr = "blah blah"

s = fstr:format(blah blah)

text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))


So you can see "s" is defined (it is the output from fstr:format).

In yours you have:


line1 = fstr1:format(blah blah)
line2 = fstr2:format(blah blah)
text_width = WindowTextWidth (win, font_id, mw.strip_colours(s))


You have left "s" there but renamed what it used to be to line1 and line2.

- Nick Gammon

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

Posted by Crowe   (21 posts)  [Biography] bio
Date Reply #12 on Mon 22 Feb 2010 12:52 AM (UTC)
Message
Thank you. I changed the line to this:

text_width = WindowTextWidth (win, font_id, mw.strip_colours(line1))

How do I address line2? I know I cannot do this:

text_width = WindowTextWidth (win, font_id, mw.strip_colours(line1, line2))

Because it will not show line2.

What would I need to do? I am really trying to learn this. I do thank you for your help in understanding this.
[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.


11,049 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]