Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Rangerman
Newbie


Joined: 09 Feb 2008
Posts: 5

PostPosted: Sun Feb 24, 2008 5:05 am   

Gauges in status window????
 
Is it possable to put a gauge in the status window at all??? and if so how would i get started on it i have the guages all ready built
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sun Feb 24, 2008 3:31 pm   
 
No it is now. What you can do is creating a floating window, add the gauges to that and the remove the command lines and output windows.
_________________
Asati di tempari!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 25, 2008 7:57 am   
 
No it is not*
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Daagar
Magician


Joined: 25 Oct 2000
Posts: 461
Location: USA

PostPosted: Thu Feb 28, 2008 3:47 am   
 
This isn't really what you were asking for, but the following set of variables will allow you to create ASCII gauge bars in the status window. They are, in fact, quite excellent. This is not my code, it was in the zmud completed scripts forum years and years ago (actually, I think they predate that forum...). Unfortunately I can't seem to find any code at the moment that actually _uses_ these bars to describe how to set them up - you basically just pass in 3 values to the "bar" function, the 'current' value, the 'max' value, and the number of character across you want to make the bar.

What you get in return is something like this (here representing a half-full bar). It auto-colors and all. Add some text to the front to show 'numerical' values, and go to town.
[########................]

I'm sure this code can be improved with the new features of CMUD, but I have used this code as-is since... zmud 3.62 possibly? Kudos to the original author.

Code:
<class name="Status" initdisable="true" enabled="false" id="147">
  <var name="bar" type="String" id="143"><![CDATA["["%if( %3 > 100, "Illegal length (0 < length < 101)", %if( %3 < 1, "Illegal length (0 < length < 101)", %if( @b_perc( %1, %2) < 50, %ansi( high, red), %if( @b_perc( %1, %2) < 75, %ansi( high, yellow), %ansi( high, green)))%repeat( "#", %if( @b_length( %1, %2, %3) > %3, %3, @b_length( %1, %2, %3)))%ansi( def)%repeat( ".", %if( @b_remaining( %1, %2, %3) > %3, %3, @b_remaining( %1, %2, %3)))))"]"]]></var>
  <var name="b_length" type="String" id="144">%eval( %3 - @b_remaining( %1, %2, %3))</var>
  <var name="b_perc" type="String" id="145">%eval( %1 * 100 / %2)</var>
  <var name="b_remaining" type="String" id="146">%eval(((%3 * 100) - (%3 * @b_perc(%1, %2))) / 100)</var>
</class>
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Feb 28, 2008 11:18 am   
 
Nifty stuff. Not a lot that needs doing except changing it to the new function format. How about:

Code:
#func bar($val,$max,$len) {#if ($len<1) {#return "Illegal Length "$len}
$perc=($val*100)/$max
$remaining=(($len*100)-($len*$perc))/100
$length=$len-$remaining
#local $col
#switch ($perc < 26) {$col=%ansi(high,red)}
  ($perc <76) {$col=%ansi(high,yellow)}
  {$col=%ansi(high,green)}
#return %concat("[",$col,%repeat("#",$remaining),%ansi(def),%repeat(".",$length),"]")}


I haven't tested this (I'm at work Embarassed ) so there might be something wrong with it. But hopefully it conveys the idea. I also removed the arbitrary 100 length limit, because while you'd probably never need a gauge that long, why limit yourself?
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Daagar
Magician


Joined: 25 Oct 2000
Posts: 461
Location: USA

PostPosted: Fri Feb 29, 2008 12:55 am   
 
Thanks Fang. It was one of those things I never bothered to touch because it always worked so perfect. Tad easier to read now in the new format :)
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Fri Feb 29, 2008 3:17 am   
 
I made a slight modification to Fang's setup. Which does work btw.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <func name="bar">
    <value><![CDATA[#if ($len<1) {#return "Illegal Length "$len}
$perc=($val*100)/$max
$remaining=(($len*100)-($len*$perc))/100
$length=$len-$remaining
#local $col
#switch ($perc < 26) {$col="red red"}
  ($perc <76) {$col="yellow yellow"}
  {$col="limegreen limegreen"}
#return %concat("[","<color ",$col,">",%repeat("#",$length),"</color><color black black>",%repeat("#",$remaining),"</color>","]")]]></value>
    <arglist>$val,$max,$len</arglist>
  </func>
</cmud>

Now it looks like it is a health bar in a button.

Edit: Placed said missing comma. Laughing
I didn't catch it cause it worked that way.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram

Last edited by Arminas on Fri Feb 29, 2008 4:14 am; edited 4 times in total
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Feb 29, 2008 3:57 am   
 
I did ponder using MXP colour (I prefer it) but decided to stick with the original method. One thing - you've missed out a comma between $col and ">" in your #return at the end there.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Feb 29, 2008 8:44 am   
 
Sweet piece of code... I think I'll incorporate into my stuff and give folks the options of having status bar health vs. gauge buttons.
_________________
Asati di tempari!
Reply with quote
Rangerman
Newbie


Joined: 09 Feb 2008
Posts: 5

PostPosted: Sun Mar 02, 2008 3:07 pm   
 
Thanks for the info guys, and future possable code :), I gonna start withe ascii ones first to see hwo it goes :) but i have a couple questions about soem of the code
Code:

#func bar($val,$max,$len) {#if ($len<1) {#return "Illegal Length "$len}


For the Variables currently I have variables of 'chp' for current and 'mhp' for max. do i just substitute @chp for $val or do i got to make a something to tell it to get its values fromt hese variables
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sun Mar 02, 2008 4:47 pm   
 
Rangerman for your variables just place the function command in the status bar/window script box like so.

@bar(@chp,@mhp,27)

I just arbitrarily chose 27 as the size of the bar try different lengths to fit your taste.

To install Fang's you copy the text in the box; then paste it into the command line and hit enter.
To install mine you copy the text in the box; then paste into the tree view in the package editor where you want it.

Each one displays a little bit different. I wanted one that looked just like a button display.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Tue Mar 04, 2008 8:13 am   
 
I had started making my own status bar, with ascii chars and ansi color before I found this. Combined what I was working on and what you guys came up with and got this:
Code:

<func name="bargraph" id="197">
  <value><![CDATA[#if ($len<1) {#return "Illegal Length "$len}
#local $perc,$length,$remaining,$text,$tstart,$tfinish,$col,$string,$prestring
$perc           = %eval(($val*100)/$max)
$remaining      = %eval((($len*100)-($len*$perc))/100)
$length         = $len-$remaining
$text           = %if($text=%null,%concat(%char(37),$perc),$text)
$tstart         = ($len-%len($text))/2
$tfinish        = $tstart + %len($text)
#switch ($perc < 26) {$col="white red"}
        ($perc <76) {$col="blue yellow"}
        (1)  {$col="red limegreen"}
$prestring = %concat(%repeat(%char(32),$tstart)$text,%repeat(%char(32),($len-$tfinish)))
$string = %concat("[","<color ",$col,">",%left($prestring,$length),"</color><color white black>",%right($prestring,$length),"</color>","]")
#return $string]]></value>
  <arglist>$len, $max, $val,$text</arglist>
  <notes>
</notes>
</func>
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Mar 04, 2008 1:09 pm   
 
$var = value creates local variables, so you don't need to declare them at the start. The only time you need to do it is when the scope is going to be an issue, such as the $col variable that's defined inside the #switch - unless it's defined in the body of the script, it'll exist only inside the switch.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Mar 04, 2008 2:01 pm   
 
Very nice, but if you want the text to show instead of the percent you need to remove the $text variable from the #local line.

As Fang mentioned the Only variable that needs explicit declaration is $col

Now someone needs to place this gem in the package library if it hasn't already found itself there!

I don't want to as all the real work was done by other people! *looks at Fang Zianfu, Wrym, and Mysterious original Author*
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Daagar
Magician


Joined: 25 Oct 2000
Posts: 461
Location: USA

PostPosted: Tue Mar 04, 2008 8:46 pm   
 
I tried a few times to dig up the original author, but to no avail. I definitely agree this belongs in the package library - I didn't realize how many people would take to it. Thanks all for sprucing it up.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Mar 04, 2008 9:18 pm   
 
If only cmud:// links were in already. I've uploaded it anyway.

Also, one note to wyrm - #switch has support for a real else-command, there's no need to fool it by using (1). Check the help.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net