$convert(). (temp/length/vol/weight/area)

By vaseline28 on Jun 08, 2008

This script returns the conversion from one Temperature/Length/Volume/Weight/Area to another.

Usage:
$convert(Temp1,Temp2,Amount).temp << Converts Amount from Temp1 to Temp2
$convert(Length1,Length2,Amount).Length << Converts Length
$convert(Volume1,Volume2,Amount).Vol << Converts Volume
$convert(Weight1,Weight2,Amount).Weight << Converts Weights
$convert(Area1,Area2,Amount).Area << Converts Area

Available Options for:
Temperature:
Kel = Kelvin || C = Celcius/Centigrade || F = Farenheit
Length:
km = Kilometer || m = meter || cm = centimeter || mile = mile || yard = yard || ft = foot || in = inch
Volume:
l = Litre || m3 = Cubic Meter || cm3 = Cubic Centimeter || gal = Gallon || yd3 = Cubic Yard
Weight:
ton = tonne || kg = kilogram || g = gram || lb = pound || oz = ounce
Area:
A = Are || m2 = Square Meters || cm2 = square centimeters || acre = acre || yd2 = square yards || ft2 = Square Foot

alias convert {
  if ($isid) {
    if ((!$3) || ($3 !isnum)) { return ( Invalid Parameter $ $+ convert().temp/length ) | halt }
    if ($prop == Temp) {
      if ($1 == Kel) {
        $iif($2 == C,set %Conversions $calc(-273 + $3),)
        $iif($2 == F,set %Conversions $calc(-459.4 + $calc(3.6 * $3)),)
      }
      elseif ($1 == C) {
        $iif($2 == Kel,set %Conversions $calc(273  + $3),)
        $iif($2 == F,set %Conversions $calc(($3 * 9/5) + 32),)
      }
      elseif ($1 == F) {
        $iif($2 == C,set %Conversions $calc(($3 - 32) * 5/9),)
        $iif($2 == Kel,set %Conversions $calc(($3 - 32) * 5/9 + 273.15),)
      }
    }
    if ($prop == Length) {
      if ($1 == km) var %x $3
      if ($1 == m) var %x $calc($3 * 0.0001) 
      if ($1 == cm) var %x $calc($3 * 0.000001)
      if ($1 == yard) var %x $calc($3 * 0.0009144)
      if ($1 == ft) var %x $calc($3 * 0.0003048)
      if ($1 == in) var %x $calc(0.0000254 * $3)
      if ($1 == mile) var %x $calc($3 * 1.609344)
      if ($2 == yard) var %y 1093.6133
      if ($2 == ft) var %y 3280.8399
      if ($2 == in) var %y 39370.0787
      if ($2 == mile) var %y 0.621371192
      if ($2 == m) var %y 1000
      if ($2 == cm) var %y 100000
      if ($2 == km) set %Conversions %x
      else set %Conversions $calc(%x * %y)
    }
    if ($prop == Vol) {
      if ($1 == km) var %x $3
      if ($1 == m3) var %x $calc($3 * 1000)
      if ($1 == cm3) var %x $calc($3 * 0.001)
      if ($1 == gal) var %x $calc($3 * 3.785412)
      if ($1 == yd3) var %x $calc($3 * 764.5549)
      if ($2 == m3) var %y 0.001
      if ($2 == cm3) var %y 1000
      if ($2 == gal) var %y 0.2641721
      if ($2 == yd3) var %y 0.001307951
      if ($2 == l) set %Conversions %x
      else set %Conversions $calc(%x * %y)
    }
    if ($prop == Weight) {
      if ($1 == ton) var %x $calc($3 / 1000)
      if ($1 == kg) var %x $3
      if ($1 == g) var %x $calc($3 * 0.001)
      if ($1 == lb) var %x $calc($3 * 0.4536)
      if ($1 == oz) var %x $calc($3 * 0.02835)
      if ($2 == ton) var %y 0.001
      if ($2 == g) var %y 1000 
      if ($2 == lb) var %y 2.205
      if ($2 == oz) var %y 35.27
      if ($2 == kg) set %Conversions %x
      else set %Conversions $calc(%x * %y)
    }
    if ($prop == Area) {
      if ($1 == A) var %x $calc($3 * 100)
      if ($1 == m2) var %x $3
      if ($1 == cm2) var %x $calc($3 * 0.0001)
      if ($1 == acre) var %x $calc($3 * 4046.85642)
      if ($1 == yd2) var %x $calc($3 * 0.83612)
      if ($1 == ft2) var %c $calc($3 * 0.0929030)
      if ($2 == A) var %y 0.01
      if ($2 == cm2) var %y 10000
      if ($2 == acre) var %y 0.0002471
      if ($2 == yd2) var %y 1.1959900
      if ($2 == ft2) var %y 10.7639104
      if ($2 == m2) set %Conversions %x
      else set %Conversions $calc(%x * %y)
    }
    var %x %Conversions
    unset %Conversions
    return %x
  }
}

Comments

Sign in to comment.
cptpan   -  Jul 24, 2012

what the fuck

How do i make this activated by a trigger

 Respond  
PuNkTuReD   -  Apr 03, 2010

i know its an old script, but you show a good use of
if elseif in temp
why not in other conversions?

 Respond  
Redly   -  Apr 03, 2010

....

 Respond  
vaseline28   -  Jun 11, 2008

Area Added!

 Respond  
vaseline28   -  Jun 10, 2008

Volume now added, usage:
$convert(Volume1,Volume2,Ammount).Vol
**
Weight Also:
$convert(Weight1,Weight2,Amount).Weight

 Respond  
vaseline28   -  Jun 10, 2008

Fixed, thanks. What were the other errors? I had a / instead of a * this time.

 Respond  
Nomader   -  Jun 09, 2008

some errors in it... for example $convert(mile,ft,1).Length gives 2038.61877, not 5280 like it should

 Respond  
vaseline28   -  Jun 09, 2008

Update:

Now converts Length

 Respond  
vaseline28   -  Jun 09, 2008

As I said in the introduction, not there yet, Imperial measurements are being a pain and holding me up. But they\'ll definitely be in there by this afternoon.

 Respond  
BlueThen   -  Jun 09, 2008

Where\'s the \"Length/Volume/Weight/Area\" part? This only converts temperatures.

 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.