mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2005
Posts: 106
S
Vogon poet
OP Offline
Vogon poet
S
Joined: May 2005
Posts: 106
ok i've been calculating stuff and noticed something in the mirc scripting world

theres no calculators :P does someone want to make one


and thats the way the scout leader burns
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
//echo -a $calc( equation here )

Joined: May 2005
Posts: 106
S
Vogon poet
OP Offline
Vogon poet
S
Joined: May 2005
Posts: 106
ok could ya do one with dialogs/buttons because what you asted did not sink in to my puney little mind


and thats the way the scout leader burns
Joined: May 2005
Posts: 106
S
Vogon poet
OP Offline
Vogon poet
S
Joined: May 2005
Posts: 106
eh don't worry i wrote one in a couple of minutes

heres my code

Code:
; mIRC Calculator by Paul
; Start it with /calculator

; Initialization alias
alias calculator {
  if ($dialog(calc)) { dialog -x calc }
  if (!$hget(calc)) { hadd -m calc eq 0 }
  dialog -dmr calc calc
  hadd calc mode deg
}

; Dialog elements
dialog calc {
  title "mIRC Calculator"
  size -1 -1 255 470
  menu "Options",100
  item "",101
  item "Clear Equations",102
  edit "",50,10 12 230 20,right autohs
  edit "0",51,10 35 230 20,right read
  button "x!",58,10 65 35 25
  button "C(n,r)",42,50 65 35 25
  button "P(n,r)",43,90 65 35 25
  button "norm",17,130 65 35 25
  button ",",18,170 65 35 25
  button "Off",54,210 65 35 25,ok
  button "log",2,10 100 35 25
  button "ln",3,50 100 35 25
  button "e",19,90 100 35 25
  button "sin",4,130 100 35 25
  button "cos",5,170 100 35 25
  button "tan",6,210 100 35 25
  button "1/x",44,10 135 35 25
  button "^",20,50 135 35 25
  button "root",7,90 135 35 25
  button "asin",8,130 135 35 25
  button "acos",9,170 135 35 25
  button "atan",10,210 135 35 25
  button "(",21,10 170 35 25
  button ")",22,50 170 35 25
  button "M",45,90 170 35 25
  button "M-",46,130 170 35 25
  button "MR",47,170 170 35 25
  button "M+",48,210 170 35 25
  button "sinh",11,10 205 35 25
  button "cosh",12,50 205 35 25
  button "tanh",13,90 205 35 25
  button "asinh",14,130 205 35 25
  button "acosh",15,170 205 35 25
  button "atanh",16,210 205 35 25
  button "7",23,10 285 45 40
  button "8",24,60 285 45 40
  button "9",25,110 285 45 40
  button "4",26,10 330 45 40
  button "5",27,60 330 45 40
  button "6",28,110 330 45 40
  button "1",29,10 375 45 40
  button "2",30,60 375 45 40
  button "3",31,110 375 45 40
  button "AC",1,205 285 40 40
  button "*",32,160 330 40 40
  button "/",33,205 330 40 40
  button "+",34,160 375 40 40
  button "-",35,205 375 40 40
  button "0",36,10 420 45 40
  button ".",37,60 420 45 40
  button "Pi",38,110 420 45 40
  button "=",49,205 420 40 40,default
  button "Phi",39,160 285 40 40
  button "<-",55,32.5 245 60 35
  button "Del",57,97.5 245 60 35
  button "->",56,162.5 245 60 35
  button "Ans",41,160 420 40 40
  button "<",59,215 0 10 12
  button ">",60,230 0 10 12
  text "",61,160 0 50 12 
  text "",52,125 0 10 12
}

; Evaluate an expression
alias parse_exp {
  if ($count($1,$chr(40)) != $count($1,$chr(41))) { 
    .echo -q $input(Parentheses mismatch,diou,Error) 
    return
  }
  var %e = $remove($1,$cr),%s,%r,%re /(?<=\))([^()+\-/^*])/g
  .echo -q $regsub(%e,/(?<=\d)([a-z])/gi,* \1,%e) $regsub(%e,%re,* \1,%e) $regsub(%e,/(Pi|Phi|e)(?=[a-z])/gi,\1 *,%e)
  %e = $replace(%e,log,lg,e,$e,phi,1.6180339887498948482,pi,$pi,ans,$iif($hget(calc,ans),$ifmatch,0))
  while $regex(%e,/(([a-z]+)\(([^()]*?)\))/gi) {
    %r = $regml(1)
    %s = $($+($,$regml(2),$chr(40),$iif($chr(44) isin $regml(3),$regml(3),$calc($regml(3))),$chr(41),$iif($regex($regml(2), $+ $&
      /a?(?:sin|cos|tan)h?/i) && $hget(calc,mode) = deg,.deg)),2)
    if (%s = $null) {
      .echo -q $input(Invalid expression,diou,Error)
      return 
    }    
    %e = $replace(%e,%r,%s)
  }
  return $iif($regex(%e,[*\-/+^]),$calc(%e),%e)
}

; Factorial
alias -l fact {
  var %i = $1,%n = 1
  if ($1 < 0) || ($2 < 0) { return }  
  while (%i && (($2 && %i > $2) || !$2)) {
    %n = $calc(%i *%n)
    dec %i
  }
  return %n
}

; Permutations
alias -l p return $iif($1 <= $2,$fact($1,$calc($1 -$2)))

; Combinations
alias -l c  {
  if ($2 > $1) return
  var %1 = $iif($calc($1 -$2) > $2,1)
  return $calc($fact($1,$iif(%1,$calc($1 -$2),$2))/$fact($iif(%1,$2,$calc($1 -$2))))
}

; Nth root of x
alias -l root return $calc($1 ^(1/$iif($2,$2,2)))

; Log (base 10)
alias -l lg return $calc($log($1)/$log(10))

; Natural Log (base e)
alias -l ln return $log($1)

; Euclid's number
alias -l e return 2.71828182845904523536

; Hyperbolic functions
alias -l sinh return $calc(($e ^$1 -$e ^-$1)/2)
alias -l cosh return $calc(($e ^$1 +$e ^-$1)/2)
alias -l tanh return $calc($sinh($1)/$cosh($1))
alias -l asinh return $log($calc($sqrt($calc($1 ^2+1))+$1))
alias -l acosh return $iif($1 >= 1,$log($calc($sqrt($calc($1 ^2-1))+$1)))
alias -l atanh return $iif($abs($1) < 1,$log($sqrt($calc((1+$1)/(1-$1)))))

; Approximate to cummulative normal distribution function
; Absolute value of error is never greater than 0.00025
alias -l norm return $round($calc(1-(1/(1+0.196854*$1 +0.115194*$1 ^2+0.000344*$1 ^3+0.019527*$1 ^4)^4)/2),4)

; Dialog initialize
on *:dialog:calc:init:*:{
  did -o calc 101 Switch to $iif($hget(calc,mode) = rad,degrees,radians)
  eq /
}

; Event for buttons
on *:dialog:calc:sclick:*:{
  tokenize 32 $did(50).selstart $did(50).selend
  if ($did = 1) {
    did -r calc 50,51 
    did -a calc 51 0
  }
  elseif ($did isnum 2-41) { add $did($did) $+ $iif($did isnum 2-17,$chr(40)) $1-2 }  
  elseif ($did = 58) { add fact( $1-2 }
  elseif ($did isnum 42-43) { add $left($did($did),1) $+ ( $1-2 }
  elseif ($did = 44) { add ^-1 $1-2 }
  elseif ($did = 45) && ($hget(calc,mem) != $null) { add $ifmatch $1-2 }
  elseif ($did = 46) { 
    hdel calc mem 
    did -r calc 52 
  }
  elseif ($did = 47) { did -ar calc 51 $iif($hget(calc,mem),$ifmatch,0) }
  elseif ($did = 48) { 
    hadd calc mem $iif($did(51),$ifmatch,0) 
    did -ra calc 52 M 
  }
  elseif ($did = 49) {
    var %x = $$parse_exp($did(50)) 
    did -ar calc 51 %x
    hadd calc ans %x
    .echo -q $eq($did(50),%x)
    hadd calc tmp 1
  } 
  did -f calc 50
  if ($did = 55) && ($1) {
    did -c calc 50 $1 $1 
    return
  }
  elseif ($did = 56) {     
    did -c calc 50 $calc(2+$2) $calc(2+$2) 
    return
  }
  elseif ($did = 57) {
    var %d = $did(50),%c = did -c calc 50,%m = did -ar calc 50 
    if (!$1) || (!$2) { 
      %m $mid(%d,$calc(1+$iif(!$2,1)+$2))
      %c 1 1 
    }
    elseif ($1 = $2) && ($1) {
      %m $left(%d,$calc($1 -1)) $+ $mid(%d,$calc(1+$1))
      %c $1 $1
    }
    else { 
      %m $left(%d,$1) $+ $mid(%d,$calc(1+$2))
      %c $calc(1+$1) $calc(1+$1)
    }
  }
  elseif ($did = 59) { eq - }
  elseif ($did = 60) { eq + }
}

; Add text to editbox
alias -l add {
  var %t = $did(calc,50),%d = did -ar calc 50,%c did -c calc 50  
  if ($hget(calc,tmp)) && ($2 = $len(%t)) {
    hdel calc tmp
    if ($regex($1,[*+\-/^])) { %d Ans $+ $1 }
    else { %d $1 }
    halt
  }
  did -f calc 50
  if (!$3) || (!$2) {
    %d $1 $+ $iif(!$3,%t,$mid(%t,$calc(1+$3))) 
    %c $calc(1+$len($1)) $calc(1+$len($1))
  }
  else { 
    %d $+($mid(%t,1,$2),$1,$mid(%t,$calc(1+$3))) 
    %c $calc(1+$len($1)+$2) $calc(1+$len($1)+$2) 
  }
  halt
} 

; Handle previous equations
alias -l eq {
  var %1 = $iif($isid,$3,$1),%q = $hget(calc,eq),%t = $hfind(calc,eq?*,0,w),%b = did -b calc,%e = did -e calc,%r = did -ar calc
  tokenize 32 $remove($did(calc,61),/) $calc(1+%t) $1- hadd calc eq
  if ($isid) {
    $6- $+ $3 $+($4,$cr,$5) 
    $6- $3
    inc %t
    %q = %t
  }
  else { 
    if (%1 isin +-) { h $+ $iif(%1 = +,inc,dec) calc eq }
    %q = $calc(%q %1 1)
    tokenize 13 $hget(calc,eq $+ %q)
    %r 50 $1
    %r 51 $2
  }
  %r 61 %q / %t
  if (%q < 2) { %b 59 }
  elseif (%q = 2) && ((%1 = +) || ($isid)) { %e 59 }
  if (%q = %t) { %b 60 }
  elseif ($calc(1+%q) = %t) && (%1 = -) { %e 60 }
}

; Option menu
on *:dialog:calc:menu:*:{
  if ($did = 101) {
    hadd calc mode $iif($hget(calc,mode) = deg,rad,deg) 
    did -o calc 101 Switch to $iif($hget(calc,mode) = rad,degrees,radians)
  }
  else {
    hdel -w calc eq?*
    hadd calc eq 0
    eq / 
  }
}
 


and thats the way the scout leader burns
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
oh lol, sorry i missunderstood you, thought u ment u didnt know how to do a calculation in mirc. smile

Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
You mean you took my script and changed 'mIRC Calculator by Sigh' to 'mIRC Calculator by Paul' in a couple of minutes?

Original including documentation at: http://www.mirc.net/projects.php?go=1091652935

Last edited by Sigh; 16/07/05 04:33 PM.
Joined: May 2005
Posts: 106
S
Vogon poet
OP Offline
Vogon poet
S
Joined: May 2005
Posts: 106
lol dw its alright


and thats the way the scout leader burns
Joined: Feb 2005
Posts: 681
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Feb 2005
Posts: 681
hahaha busted. only losers steal credit for someone elses work.

Last edited by mIRCManiac; 16/07/05 04:34 PM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I wouldnt be suprised if his intent to post Sigh calculator as his own, was the entire intent of the thread in the first place, he may well have already had the code, and just wanted to show what great programming he can do by posting it in reply to someones replied attempt, i thumbled that a slight bit for him, by missreading what he even asked for.

I also looked at the code, and didnt really beleive he wrote that in a few minutes, for three reasons, (1) it would have taken longer than that just to write that much code, (2) its way to advanced for that time frame, and (3) I have seen his code in other threads, theres no way it looked like his work.

Joined: Feb 2005
Posts: 681
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Feb 2005
Posts: 681
Quote:

he may well have already had the code

(1) it would have taken longer than that just to write that much code, (2) its way to advanced for that time frame


I thought that too. There was 69 minutes between the
post with the code and his previous post, so that was
69 minutes to write all that code, I think even that would
be a stretch. I bet Sigh didn't write it in 69 minutes lol.

Last edited by mIRCManiac; 16/07/05 05:05 PM.
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
Indeed, it took at least a few hours if I remember

Normally I wouldn't have mentioned anything but as Dave said, it looked he was planning this from the first post. What's also weird is that I've replied to his questions in the past, did he not think I would see this one too

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
You're a loser and deserve no respect. Rippers are the kind of people I dislike the most.

Especially since this whole thread seems like a setup for you to try to brag about other people's skills in your own name.

One word: Bah.


Gone.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Quote:
eh don't worry i wrote one in a couple of minutes


A couple of minutes to write, test & debug all that...I think not.

If you're going to post someone else's work, have the courtesy to provide credit where credit is due. I'm quite sure that you wouldn't like it if you made a really good script and then some newbie came along and posted it, as theirs, with only a couple of minor changes.

Joined: Mar 2005
Posts: 420
X
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
He's been known to do that.


If you have a plastic floor runner over your tiles, then you're one Hella Pinoy!
Joined: Apr 2004
Posts: 218
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Apr 2004
Posts: 218
ROFL - I'd like to congratulate Sigh on catching that.
As for this pethetic loser who was stupid enough to post a code he edited and claimed as his own. You're a dumbass. smile


Live to Dream & Dream for Life

Link Copied to Clipboard