!calc Calculator

Platform:  mIRC
Published  Dec 27, 2010
Updated  May 20, 2011
My First script posted on Hawkee (code snippets, not forums. I use the forums more)

Anyhow, I made it so the command is !calc

It works with spaces; commas, m as in million, k as in thousand, b as in billion, and if it returns 0 it messages the channel why the result may be 0

Anyway, here it is!
-$comma made by FiberOPtics.

~~~~~~~~~~~~~~~~
Previous description is for the old script. Now, basically it regsubs it. Used the $comma regex in still, credit of the regular expression of that to FiberOPtics still. on *:TEXT:!calc*:#: msg # $iif($regsubex($remove($2-,$chr(32),$chr(44)),/((^|[+-/^*%]+)(([0-9]|\56)+)(k|m|b)|(^|[+-/^*%]+)(([0-9]|\56)+)|(^|[+-/^*%]+)(\50(.+?)\51))/ig,),Syntax Error,$iif(!$2,Syntax Error,[!calc] $2- = $regsubex($ticks,$calc($regsubex($ticks,$remove($2-,$chr(44),$chr(32)),/(^|[+-/*%]+|[+-/*%]+\50)(([0-9]|\56)+)(k|m|b)/ig,\1 $+ ( $+ \2 $+ $iif(\4 == b,*1000000000,$iif(\4 == m,*1000000,*1000)) $+ ))),/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44))))

Comments

Sign in to comment.
toclafane1   -  Oct 05, 2011
yes i seen, i just though i'd mention it again :P
 Respond  
Conscious   -  Oct 05, 2011
We went through that earlier. Read comments after it. >.<
 Respond  
toclafane1   -  Oct 04, 2011

Quote

$chr(46) is $....


Why? :o


it's $chr(36) :P
 Respond  
napa182   -  May 20, 2011
lol @ one line, more like one long mess ;x maybe bust it up some.
 Respond  
Conscious   -  May 20, 2011
Okay, so this was in a high need of a recode.
First of all, with the method I used above it replaced 'm' with *1000000
That works in some cases, but if you have !calc 1m/1m it returns 1,000,000,000,000 instead of 1.
So I turned it into regex, making it do something like $calc((1*1000000)/(1*1000000))
However this wasn't capturing the . so I made another edit to incorporate that.

...then I made it one line xD

Old script for history to anyone who's interested, editing the new script above now.

Code

 
 Respond  
Conscious   -  Feb 27, 2011
Done..
 Respond  
sunslayer   -  Feb 27, 2011
you should credit FiberOPtics for the $comma identifier
 Respond  
Conscious   -  Feb 27, 2011
wrong thread -.-
Edit: Though I did make a little edit.
 Respond  
Conscious   -  Dec 29, 2010
Update: Forgot to add the $comma alias at the top last update or something, causing the calculator not to work.
 Respond  
Conscious   -  Dec 28, 2010
oops. Complete math fail
nevermind
 Respond  
Conscious   -  Dec 28, 2010
I don't know what you're reffering to.. sorry..

 Respond  
jaytea   -  Dec 27, 2010
i just remembered an old post i made on another forum that would be quite relevant here:

http://forum.swiftirc.net/viewtopic.php?f=32&t=4003

both of the issues i mentioned in my post (about modulo and the effect of $replace() when used with certain operators) are present in this snippet.
 Respond  
Conscious   -  Dec 27, 2010
But the calulator bit AND the replace are in the same line.... so where the heck do I put isnum? Because $calc(letters) will return 0
 Respond  
_Teen_   -  Dec 27, 2010
about the k m b, on your main script, you use it to multiple if the person use

!calc 33K+44K , then the script will recognize that this is 33,000+44,000

we just used $replace, on this case, to replace k for *1000, m *1000000, b *1000000000

so the $calc identifier will multiply, in this case

$calc(33*1000) and 33k, will become 33,000
 Respond  
Conscious   -  Dec 27, 2010
Hmmm

for isnum...


What will that do to the k,m,b? and * and + and things?

Sorry, I just prefer if ($1 == !calc) then adding a space, because if you use it for scripts that have like.... for instance a number association to a person, you can either do !number or !number nick and that doesnt work if there's a space up the top for just !number

correct me if I'm wrong.
 Respond  
_Teen_   -  Dec 27, 2010
look dont need the if $1 == !calc, cause if you put an space here

Code

 


this

Quote


!calc1*2*3


will not happen, by the way, why dont u do a check for

Code

 


to check if $2- is number, then you will send a message to channel like

Code

 


the $strip identifier, strip all incoming colors
 Respond  
Conscious   -  Dec 27, 2010
The timers because it looks better when its acctually happening, its not all instant.

And oops, changing the 0 now.

if ($1 == !calc) {

This stops them from doing !calc1*2*3 and messing the script up

And also if I do another script !calc2 or something.





What's 'the stip'?
 Respond  
_Teen_   -  Dec 27, 2010
why the timers? ._.

change the

Code

 


for

Code

 


by the way dont need it dude

Code

 


someone will come here, saying about the flood protection and the strip
 Respond  
Conscious   -  Dec 27, 2010
So make it...

Code

 

Is that right?
Sorry if my BB code didn't work, by the way
 Respond  
_Teen_   -  Dec 27, 2010
no problem so, you can replace the $chr(44) for $null
 Respond  
Conscious   -  Dec 27, 2010
Oops! That's 36!

No, I don't want the commas translated into decimal points...

Commas are like 1,000,000 which would equal 1... not a million

Unless I missed something
 Respond  
_Teen_   -  Dec 27, 2010
no $chr(46) its dot...

type //echo -ag $asc(.)
 Respond  
Conscious   -  Dec 27, 2010
$chr(46) is $....


Why? :o
 Respond  
Conscious   -  Dec 27, 2010
Adding a small timer to the Answer.



 Respond  
_Teen_   -  Dec 27, 2010
damn, i was posting when u post the same thing ._.

but, by the way, dont need to remove the commas, just replace it for $null

Code

 
 Respond  
SunnyD   -  Dec 27, 2010
Aside from the useless "Calculating...." Its a pretty nice script. The only reason I say this is because its nearly a split second for the results to be sent, and in my opinion its kind of a killer.

Could crunch down some of the prefix enumerating and calculating into

Code

 
 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.