$bar

By Callison1 on Jun 27, 2007

This identifier will calculate what percentage N is of C and display it in a coloured bar format, useful for rating scripts, it uses 20 characters, the majority are spaces but the middle shows the percentage, and if "text" exists, it will appear after the bar. If the percentage is more than 5 digits long it is displayed at the end of the bar after "text"

Usage: $bar(C,N,text)

alias bar {
  set -u0 %i 1
  set -u0 %p 5
  while (( %i <= 20 )) {
    if (( $calc( (100 / $$1) * $$2 ) >= %p )) set -u0 $+(%,c.,%i) 4,09
    else set -u0 $+(%,c.,%i) 9,04
    inc %i
    inc %p 5
  }
  set %bar.per $round($calc( (100 / $$1) * $$2 ),0)
  if (( $len(%bar.per) >= 6 )) { goto dig.more }
  goto dig. $+ $len(%bar.per)
  :dig.1
  return $+(%c.1,$chr(32),%c.2,$chr(32),%c.3,$chr(32),%c.4,$chr(32),%c.5,$chr(32),%c.6,$chr(32),%c.7,$chr(32),%c.8,$chr(32),%c.9,$chr(32),%c.10,%bar.per,%c.11,%,%c.12,$chr(32),%c.13,$chr(32),%c.14,$chr(32),%c.15,$chr(32),%c.16,$chr(32),%c.17,$chr(32),%c.18,$chr(32),%c.19,$chr(32),%c.20,$chr(32),,$iif($3 != $null, $3 ))
  :dig.2
  return $+(%c.1,$chr(32),%c.2,$chr(32),%c.3,$chr(32),%c.4,$chr(32),%c.5,$chr(32),%c.6,$chr(32),%c.7,$chr(32),%c.8,$chr(32),%c.9,$left(%bar.per,1),%c.10,$right(%bar.per,1),%c.11,%,%c.12,$chr(32),%c.13,$chr(32),%c.14,$chr(32),%c.15,$chr(32),%c.16,$chr(32),%c.17,$chr(32),%c.18,$chr(32),%c.19,$chr(32),%c.20,$chr(32),,$iif($3 != $null, $3 ))
  :dig.3 
  return $+(%c.1,$chr(32),%c.2,$chr(32),%c.3,$chr(32),%c.4,$chr(32),%c.5,$chr(32),%c.6,$chr(32),%c.7,$chr(32),%c.8,$chr(32),%c.9,$left(%bar.per,1),%c.10,$mid(%bar.per,2,1),%c.11,$right(%bar.per,1),%c.12,%,%c.13,$chr(32),%c.14,$chr(32),%c.15,$chr(32),%c.16,$chr(32),%c.17,$chr(32),%c.18,$chr(32),%c.19,$chr(32),%c.20,$chr(32),,$iif($3 != $null, $3 ))
  :dig.4
  return $+(%c.1, $chr(32),%c.2,$chr(32),%c.3,$chr(32),%c.4,$chr(32),%c.5,$chr(32),%c.6,$chr(32),%c.7,$chr(32),%c.8,$left(%bar.per,1),%c.9,$mid(%bar.per,2,1),%c.10,$mid(%bar.per,3,1),%c.11,$right(%bar.per,1),%c.12,%,%c.13,$chr(32),%c.14,$chr(32),%c.15,$chr(32),%c.16,$chr(32),%c.17,$chr(32),%c.18,$chr(32),%c.19,$chr(32),%c.20,$chr(32),,$iif($3 != $null, $3 ))
  :dig.5
  return $+(%c.1,$chr(32),%c.2,$chr(32),%c.3,$chr(32),%c.4,$chr(32),%c.5,$chr(32),%c.6,$chr(32),%c.7,$chr(32),%c.8,$left(%bar.per,1),%c.9,$mid(%bar.per,2,1),%c.10,$mid(%bar.per,3,1),%c.11,$mid(%bar.per,4,1),%c.12,$right(%bar.per,1),%c.13,%,%c.14,$chr(32),%c.15,$chr(32),%c.16,$chr(32),%c.17,$chr(32),%c.18,$chr(32),%c.19,$chr(32),%c.20,$chr(32),,$iif($3 != $null, $3 ))
  :dig.more 
  return $+(%c.1,$chr(32),%c.2,$chr(32),%c.3,$chr(32),%c.4,$chr(32),%c.5,$chr(32),%c.6,$chr(32),%c.7,$chr(32),%c.8,$chr(32),%c.9,$chr(32),%c.10,$chr(32),%c.11,$chr(32),%c.12,$chr(32),%c.13,$chr(32),%c.14,$chr(32),%c.15,$chr(32),%c.16,$chr(32),%c.17,$chr(32),%c.18,$chr(32),%c.19,$chr(32),%c.20,$chr(32),,$iif($3 != $null,$3 $+ $chr(32)),$chr(32),%bar.per,%)
}
Sign in to comment.
evilMonkey   -  Dec 07, 2010

I know this is really old, but use

var

instead of

set -u0
 Respond  
Callison1   -  Jul 01, 2007

Yes stargazer989 in remotes

 Respond  
stargazer989   -  Jul 01, 2007

where does this go in the remotes, like all the others?

 Respond  
stargazer989   -  Jul 01, 2007

this is what i got: nothing

 Respond  
Callison1   -  Jun 29, 2007

Oh right

 Respond  
xDaeMoN   -  Jun 29, 2007

I think it\'s with mIRC & can\'t handle long numbers accurately. I tested yours & returned the same.

 Respond  
Callison1   -  Jun 29, 2007
alias bartest {
  echo -a $bar($1,$2,$3-)
}

I have that alias to test it. I typed

/bartest 100 50000000000000000000000000 testing

It returned the full bar followed by 50000000000000002000000000% testing, where does the 2 come from? If I have been an idiot and missed something please tell me.

 Respond  
xDaeMoN   -  Jun 28, 2007

Here\'s what I came up now and includes the update that you did. I tested it & seems to works fine. This is just to give you an idea on how to shorten it. =)

alias bar {
  var %l = 20, %a = $round($calc((100 / $$1) * $$2 ),0), %o = $round($calc(%l * (%a / 100)),0), %d = $round($calc(%l / 2),0), %b1 = $str($chr(160),%l)
  var %p = $round($calc(($len(%a) + 1) / 2),0), %p1 = $calc(%d - %p), %p2 = $calc(%l - %p1 - $len(%a $+ %)), %b2 = $mid(%b1,1,%p1) $+ %a $+ % $+ $right(%b1,%p2)
  return 08,12 $+ $iif($len(%a) > 5,%b1 $+  %a $+ %,$left(%b2,%o) $+ 12 $+ $chr(44) $+ 08 $+ $right(%b2,$calc(%l - %o)) $+ ) $3-
}
 Respond  
Callison1   -  Jun 28, 2007

Updated

Thats all I could think of, if anyone has any better ideas please tell me.

 Respond  
Callison1   -  Jun 28, 2007

Corrected Lindrian.

I realised that in my code if the percentage is 4 or more digits e.g. 2000%, it is returned as 200% as it returns the 2 as the first left character, the first 0 as the 2nd character (returned by $mid) and the final 0 as the first right character, i\'m going to try and correct this but if anyone has any ideas that would be greatly appreciated.

 Respond  
Lindrian   -  Jun 27, 2007

use $+() instead of item $+ item $+ etc.

 Respond  
xDaeMoN   -  Jun 27, 2007

Hmm didn\'t really test big numbers on mine & wasn\'t able to test it that much. Yep, he did a good work but I know it can still be shorten. I\'ll check on it.

 Respond  
Noutrious   -  Jun 27, 2007

xDaeMoN, Sorry, Your way didn\'t work as well as his. I used:

//echo -a $bar(1323523522,2352525252626238672362100)

His way it returned:

   170%         

Your way: 177747143403337150%1

Anyway, good work - found it useful in my MD5 system, 7/10

 Respond  
xDaeMoN   -  Jun 27, 2007

You can still shorten this & get rid of the while loop and the long last line.

Here\'s what I came up:

alias bar {
  var %l = 20, %c = $calc($2 / $1), %d = $int($calc(%l * %c)), %p = $calc(%c * 100) $+ %, %ps = $int($calc($len(%p) / 2))
  var %bar = $str($chr(160),%l), %p1 = $calc((%l / 2) - %ps), %p2 = $calc((%l / 2) - %ps + $len(%p))
  %bar = $mid(%bar,1,%p1) $+ %p $+ $mid(%bar,%p2,$calc(%l - %p2))
  return 12,08 $+ $left(%bar,%d) $+ 08,12 $+ $right(%bar,$calc(%l - %d)) $+  $3-
}

Same usage: $bar(C,N,text)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.