All pastes #353153 Raw Edit

New Remote Calc Code

public text v1 · immutable
·published 2007-02-13 06:04 UTC
rendered paste body
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
    }
  }
  var %calculate $replace($remove(%calculate,$chr(44),$chr(61)),x,*,k,*1000,m,*1000000)
  var %answer = $bytes($calc(%calculate),db)
  return %answer
}

on *:text:*:#:{
  if (!$regex($1,/^[!@.]calc */Si) && ($left($1,1) != `)) halt
  if ($regex($1,/^[!@.]calc */Si)) var %calc = $2-
  else var %calc = $right($1,-1)
  if ($regex(%calc,/[a-jln-z]/i)) { notice $nick 1*** [4Calc1]: ERROR: Illegal Letters Detected. Only M for Millions and K for Thousands are allowed. | halt }
  if (help isin $1-) { notice $nick 1*** [4Calc1]: Usage: .calc <math> - Example: .calc 2.3m-357k - Only M for Millions and K for Thousands are allowed. | halt }
  var %send = $iif($left($1,1) == @,msg $chan,notice $nick)
  %send 1*** [4Calc1]: %calc = $acalc(%calc)
}