Last active
September 3, 2020 11:48
-
-
Save CaptainPRICE/132fd12cf45a24b39176 to your computer and use it in GitHub Desktop.
Unit converter made for Garry's Mod.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UNIT = setmetatable({}, { | |
__index = { | |
KILOMETRE = 1; | |
METER = 2; | |
CENTIMETRE = 3; | |
MILE = 3; | |
INCH = 4; | |
FOOT = 5; | |
}; | |
__metatable = false; | |
__newindex = function( self ) error( "Invalid operation. Attempt to modify '" .. tostring( self ) .. "' table." ) end; | |
__tostring = function() return "UNIT" end; | |
}) | |
ConvertToUnit = function( units, unit, speed ) | |
assert( isnumber( units ) ) | |
assert( type( unit ) == tostring( UNIT ) ) | |
if ( unit == UNIT.KILOMETRE ) then | |
if ( speed ) then | |
return units * 1.905 / 100000 * 3600 | |
end | |
return units * 1.905 / 100000 | |
end | |
if ( unit == UNIT.METER ) then | |
return units * 1.905 / 100 | |
end | |
if ( unit == UNIT.CENTIMETRE ) then | |
return units * 1.905 | |
end | |
if ( unit == UNIT.MILE ) then | |
if ( speed ) then | |
return units * ( 1 / 16 ) / 5280 * 3600 | |
end | |
return units * ( 1 / 16 ) / 5280 | |
end | |
if ( unit == UNIT.INCH ) then | |
return units * 0.75 | |
end | |
if ( unit == UNIT.FOOT ) then | |
return units * ( 1 / 16 ) | |
end | |
return units | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment