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 ➜ Plugins ➜ Plugin to show an experience bar

Plugin to show an experience bar

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


Pages: 1 2  3  

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Sat 07 Feb 2009 08:17 PM (UTC)

Amended on Wed 04 Mar 2009 07:03 PM (UTC) by Nick Gammon

Message
Modern graphical MMORPGs tend to show an "experience bar" near the bottom of the screen, to show visually how close you are to levelling. The plugin below does the same thing for a text MUD (see screenshot in next message).

For the plugin to work it needs to know how much XP you have, and how much to level, in order to work out how far through the level you are.

In the case of Smaug, you need to change your default prompt and fight prompt, as per "help prompt". I made mine the same as the default, plus the experience, like this:


prompt &w<&Y%hhp &C%mm &G%vmv &C%x/&c%X&Cxp&w> 
fprompt &w<&Y%hhp &C%mm &G%vmv &C%x/&c%X&Cxp&w> 


(Note: trailing space after the prompt, as in the trigger)

This makes my prompt look like this:


<28hp 100m 102mv 2875/6325xp> 


The stuff like &w, &C etc. is just colour-coding the prompt.

Below is the plugin.

Save between the lines as Experience_Bar.xml and use File menu -> Plugins to load that file as a plugin.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

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

<muclient>
<plugin
   name="Experience_Bar"
   author="Nick Gammon"
   id="7e2bf8628a8f51bf2115d2f0"
   language="Lua"
   purpose="Shows XP to level"
   date_written="2009-02-08"
   requires="4.35"
   version="1.1"
   >
<description trim="y">
<![CDATA[
Install this plugin to show an how close you are to levelling.
]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="&lt;*hp *m *mv */*xp&gt; "
   script="do_prompt"
   sequence="100"
  >
  </trigger>
</triggers>


<!--  Script  -->


<script>
<![CDATA[

win = GetPluginID ()  -- get a unique name

-- configuration

GAUGE_HEIGHT = 11
NUMBER_OF_TICKS = 20

BACKGROUND_COLOUR = ColourNameToRGB "gray"
BOX_COLOUR = ColourNameToRGB "dodgerblue"

-- draw the bar here, on getting the prompt, or window resize
function draw_bar ()

  -- check numbers for validity
  if not current_xp or  
     not max_xp or
     current_xp < 0 or
     max_xp <= 0 then
     return
  end -- if

  -- cannot have more than max xp
  if current_xp > max_xp then
     current_xp = max_xp
  end -- if
  
 -- width is window width minus 2
 local gauge_width = GetInfo (281) - 2
 
 -- make room for the bar
 local bottom_margin = GetInfo (275)
 
 -- adjust text rectangle, keeping existing settings where possible
 if bottom_margin == 0 or 
    (bottom_margin < 0 and math.abs (bottom_margin) < (GAUGE_HEIGHT + 2)) then
   TextRectangle(GetInfo (272), GetInfo (273),   -- left, top
                  GetInfo (274), -- right
                  - (GAUGE_HEIGHT + 2),  -- bottom (gauge height plus 2 more)
                  GetInfo (276), GetInfo (282) or 0, GetInfo (277),  --  BorderOffset, BorderColour, BorderWidth
                  GetInfo (278), GetInfo (279)) -- OutsideFillColour, OutsideFillStyle
 end -- if
  
 -- make the miniwindow
 WindowCreate (win, 
             0, 0,   -- left, top (auto-positions)
             gauge_width,     -- width
             GAUGE_HEIGHT,  -- height
             10,       -- auto-position: bottom left
             0,  -- flags
             BACKGROUND_COLOUR) 
  
  WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR)  -- fill entire box
 
  -- how far through the level we are 
  local done = current_xp / max_xp
  local bar_width = gauge_width * done
 
  -- box size must be > 0 or WindowGradient fills the whole thing 
  if math.floor (bar_width) > 0 then
    
    -- top half
    WindowGradient (win, 0, 0, 
                    bar_width, GAUGE_HEIGHT / 2, 
                    0x000000,  -- black
                    BOX_COLOUR, 
                    2)   -- vertical gradient
    
    -- bottom half
    WindowGradient (win, 0, GAUGE_HEIGHT / 2, 
                    bar_width, 0, 
                    BOX_COLOUR,
                    0x000000,  -- black
                    2)   -- vertical gradient

  end -- any experience to speak of
  
  -- show ticks
  local ticks_at = gauge_width / NUMBER_OF_TICKS
  
  -- ticks
  for i = 1, NUMBER_OF_TICKS do
    WindowLine (win, i * ticks_at, 0, i * ticks_at, GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
  end -- for

  -- draw a box around it
  check (WindowRectOp (win, 1, 0, 0, 0, 0, ColourNameToRGB ("lightgrey")))  -- frame entire box
    
  -- ensure window visible
  WindowShow (win, true)
  
end -- draw_bar

function do_prompt (name, line, wildcards, styles)
 
  -- CHANGE HERE if your prompt is different (eg. different wildcard numbers)
  -- (string.gsub removes commas from the experience figures, if necessary)

  current_xp = tonumber ((string.gsub (wildcards [4], ",", "")))
  max_xp = tonumber ((string.gsub (wildcards [5], ",", ""))) + (current_xp or 0)
  
  draw_bar ()
  
end -- do_prompt

function OnPluginWorldOutputResized ()
  draw_bar ()
end -- function
 
-- 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


]]>
</script>

</muclient>



If you have a different prompt, or find your experience out in a different way, you would need to change the trigger.

The main work is done in draw_bar, based on two global variables current_xp and max_xp. If you need to establish your experience differently, just make sure your trigger, or triggers, set those two variables.

There is also a plugin callback OnPluginWorldOutputResized which redraws the bar if the world window is resized.

The plugin uses TextRectangle to make the output window slightly smaller at the bottom edge, this is to fit in the experience bar.

You can play with the gauge_height variable to make the bar shorter or taller. An odd number would be better to make the bar look more even, as it is drawn with a gradient from top to the middle, then middle to the bottom. A value of 7 looks more discrete, or you could make it larger than 11.

There is also a configurable number of "tick marks" you can show. The default is 20, which means each "bubble" of experience would represent 5% of the way to the next level. If they are too close together (or too far apart) just change the variable NUMBER_OF_TICKS).

[EDIT] Amended on 5th March 2009 to allow for commas in the experience wildcards.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 07 Feb 2009 08:17 PM (UTC)
Message

Example of it in operation:


- Nick Gammon

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

Posted by Itzie   Australia  (16 posts)  Bio
Date Reply #2 on Sun 08 Feb 2009 07:50 AM (UTC)
Message
I practically hopped up and down when I came across this plugin :P What a great idea!

I've got it to match on my prompts, the thing is that at 4000/4000 TNL it only takes up 50% of it's bar, and at 2000/4000 TNL it takes up one quarter etc.

I tried doing it exactly like it is in the original plugin too, changing my prompt and all. Still does the same thing!

Is there anything I can do to fix that? Or is that how it's supposed to be? It just seems that it should take up the whole bar then tick down from there...

My prompt -
|100%| |100%| |100%| Tnl[3092/4000] [0] [] Q[0] [The Grand City of Aylor]

What I have in the match part -
* Tnl[*/*] *

I've got the wildcard matching on the 2nd & 3rd asterisks for current/max exp.
Top

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 08 Feb 2009 08:47 AM (UTC)

Amended on Sun 08 Feb 2009 08:48 AM (UTC) by Nick Gammon

Message
Quote:

the thing is that at 4000/4000 TNL it only takes up 50% of it's bar


It depends what the figures mean. In Smaug, that means you have 4000 xp, and you have 4000 to go. Thus it is 8000 to level and you are halfway through, thus it correctly shows you as 50%.

I originally had the line:


 max_xp = tonumber (wildcards [5])  + (current_xp or 0)


as:


 max_xp = tonumber (wildcards [5])  


As I thought that it meant 4000 out of 4000. You might change it to that, if that is what the prompt means for you.



- Nick Gammon

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

Posted by Itzie   Australia  (16 posts)  Bio
Date Reply #4 on Sun 08 Feb 2009 09:24 AM (UTC)
Message
Ah right! I removed the '+ (current_xp or 0)' and it works perfectly now.

Thank you very much!
Top

Posted by Doomfyre   (12 posts)  Bio
Date Reply #5 on Wed 25 Feb 2009 12:44 AM (UTC)
Message
Would anyone care to see if this can be modified for Aardwolf? Here's my prompt:

<5257/5257hp 4816/4932m 3813/3813mv $29828 -2468al [2624tnl] 0tnq>

One possible quirk, is that i don't know of a way to display my total experience required for my current level. There's no 'token' available to represent that in prompt configuration - that i can find at least. I've heard that Aardwolf stores that info, and lots more, in client-accessible variables. I know nothing else concerning that though, sorry...

If it would just be much simpler to use a trigger and modify the current plugin, then i have a suggestion. How about an alias to manually set the max_xp variable? I'd just need to know how to implement that change near the bottom of the plugin, where it says:

-- CHANGE HERE if your prompt is different (eg. different wildcard numbers)
current_xp = tonumber (wildcards [4])
max_xp = tonumber (wildcards [5]) + (current_xp or 0)

Right?

This stuff is starting to make sense, but it's coming along slowly. Thanks for any insight.
Top

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 25 Feb 2009 12:54 AM (UTC)

Amended on Wed 25 Feb 2009 12:55 AM (UTC) by Nick Gammon

Message
See this:

http://www.gammon.com.au/forum/bbshowpost.php?id=8776

That is how you get the experience to next level.

Assuming you have that plugin installed (which actually finds the experience and other stuff from the {stats} prompt), I had an earlier version designed for Aardwolf:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

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

<muclient>
<plugin
   name="Aardwolf_Exp_Bar"
   author="Nick Gammon"
   id="5a686c03d20d8f6c3ef501f4"
   language="Lua"
   purpose="Shows Aardwolf XP to level"
   date_written="2008-08-04"
   requires="4.35"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Install this plugin to show how close you are to levelling.
]]>
</description>

</plugin>

<!--  Script  -->


<script>
<![CDATA[

gauge_height = 5
gauge_width = 600
max_xp = 1000

background_colour = 0x808080
box_colour = ColourNameToRGB "magenta"

require "checkplugin"


function draw_bar ()

 
               
  check (WindowRectOp (win, 2, 0, 0, 0, 0, background_colour))  -- fill entire box
  
  local done = (max_xp - stats.to_level) / max_xp
 
  check (WindowRectOp (win, 2, 0, 0, gauge_width * done, 0, box_colour)) 

  local ticks_at = gauge_width / 20
  
  -- ticks
  for i = 1, 20 do
    WindowLine (win, i * ticks_at, 0, i * ticks_at, 0, ColourNameToRGB ("silver"), 0, 1)
  end -- for
  
  WindowShow (win, true)
  
end -- draw_bar

function OnPluginBroadcast (msg, id, name, text)
  if msg == 1 and id == "8a710e0783b431c06d61a54c" then
  
   -- get all variables
   stats = GetPluginVariableList("8a710e0783b431c06d61a54c")
   draw_bar ()
   
  end -- stats changed
end

function OnPluginInstall ()
  
  win = GetPluginID ()
 
  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
  
  OnPluginEnable ()  -- do initialization stuff
  
end -- OnPluginInstall

function OnPluginEnable ()
  checkplugin ("8a710e0783b431c06d61a54c", "Stats_Detector.xml")
  
  WindowCreate (win, 
               0, 0,   -- left, top (auto-positions)
               gauge_width,     -- width
               gauge_height,  -- height
               10,       -- auto-position: bottom left
               0,  -- flags
               background_colour) 
               
end -- OnPluginEnable

function OnPluginDisable ()
  WindowShow (win, false)
end -- OnPluginDisable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState


]]>
</script>

</muclient>



The bar isn't as pretty, though. A bit of copying and pasting and you might have the best of both worlds.

- Nick Gammon

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

Posted by Doomfyre   (12 posts)  Bio
Date Reply #7 on Wed 25 Feb 2009 01:41 AM (UTC)
Message
As soon as i click 'open', while installing the plugin, a window tries to pop up, then i crash to desktop.

Should i mention i'm using Ubuntu/Wine? Latest Aardwolf edition MUSHclient, dowloaded here.

I didn't modify the Aardwolf version of the exp bar plugin that you posted in any way.
Top

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 25 Feb 2009 01:44 AM (UTC)
Message
Open up the Wine configuration, and set the operating system emulation to Windows 98, then try again.

- Nick Gammon

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

Posted by Doomfyre   (12 posts)  Bio
Date Reply #9 on Wed 25 Feb 2009 11:03 PM (UTC)
Message
Hello again!

Well, the Win98 fix for wine worked great.

When i logged in just now, i got:

Run-time error
Plugin: Aardwolf_Exp_Bar (called from world: Aardwolf)
Function/Sub: OnPluginBroadcast called by Plugin Aardwolf_Exp_Bar
Reason: Executing plugin Aardwolf_Exp_Bar sub OnPluginBroadcast
[string "Plugin"]:15: attempt to call global 'WindowRectOp' (a nil value)
stack traceback:
[string "Plugin"]:15: in function 'draw_bar'
[string "Plugin"]:37: in function <[string "Plugin"]:32>
Error context in script:
11 : function draw_bar ()
12 :
13 :
14 :
15*: check (WindowRectOp (win, 2, 0, 0, 0, 0, background_colour)) -- fill entire box
16 :
17 : local done = (max_xp - stats.to_level) / max_xp
18 :
19 : check (WindowRectOp (win, 2, 0, 0, gauge_width * done, 0, box_colour))

this sorta looks like the part where you said i could do some copy/pasting.
Top

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #10 on Wed 25 Feb 2009 11:31 PM (UTC)
Message
What version of MUSHclient are you using?

- Nick Gammon

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

Posted by Doomfyre   (12 posts)  Bio
Date Reply #11 on Thu 26 Feb 2009 01:34 PM (UTC)
Message
I re-read my post and i hope i didn't sound sarcastic about the win98 thing 'working great'. What i meant was, i no longer crash to desktop when loading a plugin. It had something to do with the error window popping up....

Now for the part that will make you pull your hair out...

I thought i was being really smart when i changed 'requires="4.35"' to 4.33, to make that error go away.

I would love to upgrade, but i don't see a newer version of the aardclient version. Is there one available?
Top

Posted by Bast   (78 posts)  Bio
Date Reply #12 on Thu 26 Feb 2009 01:39 PM (UTC)
Message
You can just download the latest mushclient from this website and install it. It will install over the aard client and you will have the aardclient with mush 4.4.

Bast

Bast

Scripts: http://github.com/endavis
Top

Posted by Doomfyre   (12 posts)  Bio
Date Reply #13 on Thu 26 Feb 2009 02:23 PM (UTC)
Message
Do you play aard and have you tried that? It seems to me that it would wipe out all my custom aard plugins and such.
Top

Posted by Bast   (78 posts)  Bio
Date Reply #14 on Thu 26 Feb 2009 02:37 PM (UTC)
Message
Yes, I play aard, and I have most of the standard aard plugins. Installing a new mushclient doesn't touch the worlds/plugin/Aardwolf directory or the worlds/Aardwolf directory, so your aard plugins don't change.

Bast

Bast

Scripts: http://github.com/endavis
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.


126,319 views.

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

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.