Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-24-2007, 07:39 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Metric Converter

Well, I got bored and suddenly got this idea of making a metric converter... o.O

Convertion Types:
Weight
Length
Pressure

Weight
kilograms
pounds
grams

Length
meter
centimeters
miles
feet
inches
yards

Pressure
bar
kg
cm
psi

And the function..
PHP Code:
function convertMetric(valuefromtoo) {
  if (
from == too) {
    return 
value;
  }
  
temp.category = new[2];
  
temp.weight = {"kilograms""pounds""grams"};
  
temp.length = {"meter""centimeters""miles""feet""inches""yards"};
  
temp.pressure = {"bar""kg""cm""psi"};
  
  if (
weight.index(@ from) >= 0category[0] = "weight";
  else if (
length.index(@ from) >= 0category[0] = "length";
  else if (
pressure.index(@ from) >= 0category[0] = "pressure";
    
  if (
weight.index(@ too) >= 0category[1] = "weight";
  else if (
length.index(@ too) >= 0category[1] = "length";
  else if (
pressure.index(@ too) >= 0category[1] = "pressure";

  if (
category[0] != category[1]) {
    return -
1;
  }
  
temp.var = value;
  
// Create metric chart with wanted value
  // CHART START
  
temp.metric = new TStaticVar();
  
// Weight Conversion
  
metric.kilograms_pounds = (var * 2.2046);
  
metric.kilograms_grams = (var * 453.53);
  
metric.pounds_kilograms = (var * 0.4536);
  
metric.pounds_grams = (var * 453.59);
  
metric.grams_kilograms = (var * 0.001);
  
metric.grams_pounds = (var * 0.0022);
  
// Length Conversion
  
metric.meter_centimeters = (var * 100);
  
metric.meter_miles = (var * 0.00062);
  
metroc.meter_feet = (var * 3.28084);
  
metric.meter_inches = (var * 39.3701);
  
metric.meter_yards = (var * 1.09361);
  
metric.centimeters_meter = (var * 0.01000);
  
metric.centimeters_miles = (var * 0.00001);
  
metric.centimeters_feet = (var * 0.03281);
  
metric.centimeters_inches = (var * 0.39370);
  
metric.centimeters_yards = (var * 0.01094);
  
metric.miles_meter = (var * 1609.34);
  
metric.miles_centimeters = (var * 160934);
  
metric.miles_feet = (var * 5280);
  
metric.miles_inches = (var * 63360);
  
metric.miles_yards = (var * 1760);
  
metric.feet_meter = (var * 0.30480);
  
metric.feet_centimeters = (var * 30.4800);
  
metric.feet_miles = (var * 0.00019);
  
metric.feet_inches = (var * 12);
  
metric.feet_yards = (var * 0.33333);
  
metric.inches_meter = (var * 0.02540);
  
metric.inches_centimeters = (var * 2.54000);
  
metric.inches_miles = (var * 0.00002);
  
metric.inches_feet = (var * 0.08333);
  
metric.inches_yards = (var * 0.02778);
  
metric.yards_meter = (var * 0.91440);
  
metric.yards_centimeters = (var * 91.4400);
  
metric.yards_miles = (var * 0.00057);
  
metric.yards_feet = (var * 3);
  
metric.yards_inches = (var * 36);
  
// Pressure Conversion
  
metric.bar_kg = (var * 1.0197);
  
metric.bar_cm = (var * 1.0197);
  
metric.bar_psi = (var * 14.500);
  
metric.kg_bar = (var * 0.9807);
  
metric.kg_cm = (var * 1);
  
metric.kg_psi = (var * 14.22);
  
metric.cm_bar = (var * 0.9807);
  
metric.cm_kg = (var * 1);
  
metric.cm_psi = (var * 14.22);
  
metric.psi_bar = (var * 0.0690);
  
metric.psi_kg = (var * 0.0703);
  
metric.psi_cm = (var * 0.0703);
  return 
metric.(@ from "_" too);

and Celsius <-> Fahreinheit
PHP Code:
public function celstiusToFahrenheit(c) {
  return (
9/5)*(c+32);
}
public function 
fahrenheitToCelsius(f) {
  return (
5/9)*(f-32);

Example of use:

NPC Code:

function onCreated() {
temp.value = convertMetric(8, "feet", "yards");
echo(value);
}



would output
2.66664

Note
I was bored when I made this, will probably improve it later..
Oh, and feel free to post how I can improve it later or any bugs/wrong convertions
__________________
Reply With Quote
  #2  
Old 06-24-2007, 09:33 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
That takes a lot of boredom to make :O.
Weirdo , I mean that in a good way.
__________________
Reply With Quote
  #3  
Old 06-24-2007, 09:46 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Inverness View Post
That takes a lot of boredom to make :O.
Weirdo , I mean that in a good way.
<3, thanks
__________________
Reply With Quote
  #4  
Old 06-24-2007, 11:24 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Awesome, Chompy
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #5  
Old 06-25-2007, 02:46 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by coreys View Post
Awesome, Chompy
thanks
__________________
Reply With Quote
Reply


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 11:30 PM.


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