Author Topic: Calculator Commands | v1.5  (Read 8236 times)

Sounds cool, PM me the code and I'll implement it.
Code: [Select]
function doEquation(%equ)
{
%equ = strReplace(%equ, " ", "");
%equ = strReplace(%equ, "*", "x");
%old = %equ;
%equ = strReplace(%equ, "+", " + ");
%equ = strReplace(%equ, "x", " x ");
%equ = strReplace(%equ, "/", " / ");
%equ = strReplace(%equ, "-", " - ");
%equ = strReplace(%equ, "^", " ^ ");
while(strPos(%equ, "(") > -1 && strPos(%equ, ")") > 0)
{
%start = strPos(%equ, "(");
%end = %start;
%level = 1;
while(%level != 0 && %end != strLen(%equ))
{
%end++;
if(getsubStr(%equ, %end, 1) $= "(")
%level++;
if(getsubStr(%equ, %end, 1) $= ")")
%level--;
}
%inbrackets = getsubStr(%equ, %start+1, %end - strLen(getsubStr(%equ, 0, %start + 1)));
%leftofbrackets = getsubStr(%equ, 0, %start);
%rightofbrackets = getsubStr(%equ, %end + 1, strLen(%equ) - %end);
%equ = %leftofbrackets @ doEquation(%inbrackets) @ %rightofbrackets;
}
for(%a = 0; %a < getWordCount(%equ); %a++)
{
if(getWord(%equ, %a) $= "^" && %a != 0)
{
%f = getWord(%equ, %a - 1);
%l = getWord(%equ, %a + 1);
%equ = setWord(%equ, %a, mPow(%f, %l));
%equ = removeWord(removeWord(%equ, %a + 1), %a - 1);
%a--;
}
}
for(%a = 0; %a < getWordCount(%equ); %a++)
{
if(getWord(%equ, %a) $= "x" || getWord(%equ, %a) $= "/" && %a != 0)
{
%f = getWord(%equ, %a - 1);
%l = getWord(%equ, %a + 1);
%o = getWord(%equ, %a);
switch$(%o)
{
case "x":
%equ = removeWord(removeWord(setWord(%equ, %a, %f * %l), %a+1), %a-1);
%a--;
case "/":
%equ = removeWord(removeWord(setWord(%equ, %a, %f / %l), %a+1), %a-1);
%a--;
}
}
}
for(%a = 0; %a < getWordCount(%equ); %a++)
{
if(getWord(%equ, %a) $= "+" || getWord(%equ, %a) $= "-" && %a != 0)
{
%f = getWord(%equ, %a - 1);
%l = getWord(%equ, %a + 1);
%o = getWord(%equ, %a);
switch$(%o)
{
case "+":
%equ = removeWord(removeWord(setWord(%equ, %a, %f + %l), %a+1), %a-1);
%a--;
case "-":
%equ = removeWord(removeWord(setWord(%equ, %a, %f - %l), %a+1), %a-1);
%a--;
}
}
}
return %equ;
}

Here's one that supports powers on top of what brian's offers.

Code: [Select]
function doEquation(%equ)
{
%equ = strReplace(%equ, " ", "");
%equ = strReplace(%equ, "*", "x");
%old = %equ;
%equ = strReplace(%equ, "+", " + ");
%equ = strReplace(%equ, "x", " x ");
%equ = strReplace(%equ, "/", " / ");
%equ = strReplace(%equ, "-", " - ");
%equ = strReplace(%equ, "^", " ^ ");
while(strPos(%equ, "(") > -1 && strPos(%equ, ")") > 0)
{
%start = strPos(%equ, "(");
%end = %start;
%level = 1;
while(%level != 0 && %end != strLen(%equ))
{
%end++;
if(getsubStr(%equ, %end, 1) $= "(")
%level++;
if(getsubStr(%equ, %end, 1) $= ")")
%level--;
}
%inbrackets = getsubStr(%equ, %start+1, %end - strLen(getsubStr(%equ, 0, %start + 1)));
%leftofbrackets = getsubStr(%equ, 0, %start);
%rightofbrackets = getsubStr(%equ, %end + 1, strLen(%equ) - %end);
%equ = %leftofbrackets @ doEquation(%inbrackets) @ %rightofbrackets;
}
for(%a = 0; %a < getWordCount(%equ); %a++)
{
if(getWord(%equ, %a) $= "^" && %a != 0)
{
%f = getWord(%equ, %a - 1);
%l = getWord(%equ, %a + 1);
%equ = setWord(%equ, %a, mPow(%f, %l));
%equ = removeWord(removeWord(%equ, %a + 1), %a - 1);
%a--;
}
}
for(%a = 0; %a < getWordCount(%equ); %a++)
{
if(getWord(%equ, %a) $= "x" || getWord(%equ, %a) $= "/" && %a != 0)
{
%f = getWord(%equ, %a - 1);
%l = getWord(%equ, %a + 1);
%o = getWord(%equ, %a);
switch$(%o)
{
case "x":
%equ = removeWord(removeWord(setWord(%equ, %a, %f * %l), %a+1), %a-1);
%a--;
case "/":
%equ = removeWord(removeWord(setWord(%equ, %a, %f / %l), %a+1), %a-1);
%a--;
}
}
}
for(%a = 0; %a < getWordCount(%equ); %a++)
{
if(getWord(%equ, %a) $= "+" || getWord(%equ, %a) $= "-" && %a != 0)
{
%f = getWord(%equ, %a - 1);
%l = getWord(%equ, %a + 1);
%o = getWord(%equ, %a);
switch$(%o)
{
case "+":
%equ = removeWord(removeWord(setWord(%equ, %a, %f + %l), %a+1), %a-1);
%a--;
case "-":
%equ = removeWord(removeWord(setWord(%equ, %a, %f - %l), %a+1), %a-1);
%a--;
}
}
}
return %equ;
}

Here's one that supports powers on top of what brian's offers.
mine also supports powers.

A nice fella named Gravity Cat's TDM (BL_ID 23300) built some nice decoration to show our support!

A nice fella named Gravity Cat's TDM (BL_ID 23300) built some nice decoration to show our support!

thats a bunch of national socialist symbols (or whatever they are called) Sub...
... :o

thats a bunch of national socialist symbols (or whatever they are called) Sub...
... :o
I know that.
[/facepalm]
I cleared it and banned him as soon as I saw.

thats a bunch of national socialist symbols (or whatever they are called) Sub...
... :o
Swasticas.

I know that.
[/facepalm]
I cleared it and banned him as soon as I saw.
So how'd you get the screenie...?
The plot thickens!

p.s. will post code in reguard to assisting you with this post tomorrow:
I'm still puzzled, what do I use instead of messageClient? Also, can it detect variables?:
Just saw that post.
Will help tomorrow


So how'd you get the screenie...?
The plot thickens!
Its a server preview image

p.s. will post code in reguard to assisting you with this post tomorrow:Just saw that post.
Will help tomorrow
I figure it out
Also not doing client sided version anymore.



UPDATE (Not update of add-on.)
I won't be implementing Brian Smithers' code.

1.5 will be released very soon.

You say v1.5 will be released soon yet you don't tell us what is new in it

You say v1.5 will be released soon yet you don't tell us what is new in it
1.5
Okay guys, I haven't been working on calculator commands recently because my computer has turned to stuff. I updated to windows 8, which I'm loving, but when I host I will get a BSOD. Also, blockland has been broken for a while, but I fixed it.
Quote from: v1.4.2 to v1.5.0
This update does not contain any new features, but I still see it as an important one.
*Re-did half the code to reduce the amount of lines and wedge pattern (see bottom of post).
*/calc is now /calc help. /calc will not work.
*Message now says CC <type>: instead of CC (<type>):

Wedge Pattern Fix
So if you ever looked at the server.cs it would sometimes like a bit like this:
Code: [Select]
if(blah = 1)
{
   if(blahhj = 1)
   {
      dothis;
   }
}
Now it is like this:
Code: [Select]
if(blah = 1 && blahhj = 1)
{
   dothis;
}

download link is different.
https://dl.dropbox.com/u/96011435/Script_CalculatorCommands.zip
« Last Edit: November 24, 2012, 08:38:21 PM by Subpixel »


Hey
What's the benefits of this