View Single Post
  #1  
Old 01-07-2010, 08:47 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
Calculator script

**UPDATED**
I made a simple calculator script, it's my biggest script so far.
this is what it looks like:

Updates planned for the future:

*I will make it more advanced so you will have a mem function, and a square root and ^2 function.


this is the code:
PHP Code:
//#CLIENTSIDE
function onWeaponFired()
{
  
this.number1 1;
  
this.number2 0;
  
this.divide 0;
  
this.add 0;
  
this.subtract 0;
  
this.multiply 0;
  new 
GuiWindowCtrl("Calculator_window")
  {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "165, 200";
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Calculator";
    
300;
    
200;
    
    new 
GuiTextEditCtrl("Calculator_input")
    {
      
profile GuiBlueTextEditProfile;
      
useownprofile true;
      
profile.align "right"
      
5;
      
5;
      
width 155;
      
height 30;
      
text="0";
      
text.align "right";
    }
    new 
GuiButtonCtrl("Calculator_clear")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "Clear";
      
width 35;
      
5;
      
45;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_plusmin")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+/-";
      
width 35;
      
45;
      
45;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_divide")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "/";
      
width 35;
      
85;
      
45;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_multiply")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "X";
      
width 35;
      
125;
      
45;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_seven")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "7";
      
width 35;
      
5;
      
75;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_eight")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "8";
      
width 35;
      
45;
      
75;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_nine")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "9";
      
width 35;
      
85;
      
75;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_subtract")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "-";
      
width 35;
      
125;
      
75;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_four")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "4";
      
width 35;
      
5;
      
105;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_five")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "5";
      
width 35;
      
45;
      
105;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_six")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "6";
      
width 35;
      
85;
      
105;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_add")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+";
      
width 35;
      
125;
      
105;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_one")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "1";
      
width 35;
      
5;
      
135;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_two")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "2";
      
width 35;
      
45;
      
135;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_three")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "3";
      
width 35;
      
85;
      
135;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_equals")
    {
      
profile GuiBlueButtonProfile;
      
height 55;
      
text "=";
      
width 35;
      
125;
      
135;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_zero")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "0";
      
width 75;
      
5;
      
165;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_dot")
    {
    
profile GuiBlueButtonProfile;
      
height 25;
      
text ".";
      
width 35;
      
85;
      
165;
      
thiso.catchEvent(this"onAction""buttonPressed");
    }   
  }
}
function 
ButtonPressed(obj)
{
  if(
obj.text in |09|)
  {
    if(
Calculator_input.text == "0")
    {
      
Calculator_input.text obj.text;
    }
    else
    {
      
Calculator_input.text @= obj.text;
    }
  }
  else if(
obj.text == ".")
  {
    
    
Calculator_input.text @= obj.text;
  }
  else if(
obj.text == "+/-")
  {
    
Calculator_input.text -= Calculator_input.text;
  }
  else if(
obj.text == "X")
  { 
    if(
this.divide == 1)
    {
      
this.divide 0;
      
Calculator_input.text = (this.number1 Calculator_input.text);
    }
    else if(
this.add == 1)
    {
      
this.add 0;
      
Calculator_input.text += this.number2;
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text this.number2 Calculator_input.text;
      
this.subtract 0;
    }
    
this.divide 0;
    
this.add 0;
    
this.subtract 0;
    
this.multiply 1;
    
this.number1 *= Calculator_input.text;
    
Calculator_input.text "0";
  }
  else if(
obj.text == "/")
  {
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.number1 1;
    }
    else if(
this.add == 1)
    {
      
this.add 0;
      
Calculator_input.text += this.number2;
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text this.number2 Calculator_input.text;
      
this.subtract 0;
    }
    
this.multiply 0;
    
this.add 0;
    
this.subtract 0;
    
this.divide 1;
    
this.number1 Calculator_input.text this.number1;
    
Calculator_input.text "0";
  }
  else if(
obj.text == "+")
  { 
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.number1 1;
    }
    else if(
this.divide == 1)
    {
      
this.divide 0;
      
Calculator_input.text = (this.number1 Calculator_input.text);
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text this.number2 Calculator_input.text;
      
this.subtract 0;
    }
    
this.multiply 0;
    
this.divide 0;
    
this.subtract 0;
    
this.add 1;
    
this.number2 += Calculator_input.text;
    
Calculator_input.text "0";
  }
  else if(
obj.text == "-")
  { 
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.multiply 0;
    }
    else if(
this.divide == 1)
    {
      
this.divide 0;
      
Calculator_input.text = (this.number1 Calculator_input.text);
    }
    else if(
this.add == 1)
    {
      
this.add 0;
      
Calculator_input.text += this.number2;
    }
    
this.subtract 1;
    
this.number2 Calculator_input.text this.number2;
    
Calculator_input.text "0";
  }
  else if(
obj.text == "=")
  {
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.number1 1;
      
this.multiply 0;
      
this.number2 0;
    }
    else if(
this.divide == 1)
    {
      
this.divide 0;
      
Calculator_input.text = (this.number1 Calculator_input.text);
      
this.number1 1;
      
this.number2 0;
    }
    else if(
this.add == 1)
    {
      
this.add 0;
      
Calculator_input.text += this.number2;
      
this.number2 0;
      
this.number1 1;
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text this.number2 Calculator_input.text;
      
this.subtract 0;
      
this.number1 1;  
      
this.number2 0;
    }
  }
  else if(
obj.text == "Clear")
  {
    
Calculator_input.text 0;
    
this.number1 1;  
    
this.number2 0;   
  } 
}
//Created by Miniman 
or in a handy text file.
any tips or critics are appreciated, i know i could've done *= with the multiply and add functions. but decided to leave it this way so they match with the divide and subtract functions.

thanks to chris, switch and fowlplay4 for the help.
Attached Files
File Type: txt Calculatorscript2.txt (8.5 KB, 257 views)
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.

Last edited by Liberated; 01-08-2010 at 07:09 PM..
Reply With Quote