Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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";
    
x = 300;
    
y = 200;
    
    new 
GuiTextEditCtrl("Calculator_input")
    {
      
profile = GuiBlueTextEditProfile;
      
useownprofile = true;
      
profile.align = "right"; 
      
x = 5;
      
y = 5;
      
width = 155;
      
height = 30;
      
text="0";
      
text.align = "right";
    }
    new 
GuiButtonCtrl("Calculator_clear")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "Clear";
      
width = 35;
      
x = 5;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_plusmin")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "+/-";
      
width = 35;
      
x = 45;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_divide")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "/";
      
width = 35;
      
x = 85;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_multiply")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "X";
      
width = 35;
      
x = 125;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_seven")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "7";
      
width = 35;
      
x = 5;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_eight")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "8";
      
width = 35;
      
x = 45;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_nine")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "9";
      
width = 35;
      
x = 85;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_subtract")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "-";
      
width = 35;
      
x = 125;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_four")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "4";
      
width = 35;
      
x = 5;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_five")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "5";
      
width = 35;
      
x = 45;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_six")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "6";
      
width = 35;
      
x = 85;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_add")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "+";
      
width = 35;
      
x = 125;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_one")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "1";
      
width = 35;
      
x = 5;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_two")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "2";
      
width = 35;
      
x = 45;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_three")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "3";
      
width = 35;
      
x = 85;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_equals")
    {
      
profile = GuiBlueButtonProfile;
      
height = 55;
      
text = "=";
      
width = 35;
      
x = 125;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_zero")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "0";
      
width = 75;
      
x = 5;
      
y = 165;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_dot")
    {
    
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = ".";
      
width = 35;
      
x = 85;
      
y = 165;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }   
  }
}
function 
ButtonPressed(obj)
{
  if(
obj.text in |0, 9|)
  {
    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 -= 2 * 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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.