Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local API = {}
- --[[ If the 'Canon' argument is true, measurements will be returned according to an official 2012 blogpost.
- Keep in mind this blogpost states that a robloxian is 25 cm tall, roughly 1/5th an earthlike scale... ]]--
- --[[ If the 'Canon' argument is false OR nil, measurements will be returned as experienced estimations.
- They will also be closer to true earthlike scale ]]--
- API.RealMultipliers = {
- F = 0.97012098544007168083155285088634,
- I = 11.641451825280860169978634210636,
- Y = 2.910362956320215042494658552659,
- MI = 5122.2388031235784747905990526799,
- MM = 0.0031828117338712047733393918553019,
- CM = 0.031828117338712047733393918553019,
- M = 3.1828117338712047733393918553019,
- KM = 8243.4237954188997826195026794399,
- }
- API.CanonMultipliers = {
- F = 7.2907334,
- I = 87.4888,
- Y = 21.8722,
- MI = 38495.072352,
- MM = 2000,
- CM = 200,
- M = 20,
- KM = 2,
- }
- API.TranslationTable = {
- FT = "F",
- FEET = "F",
- IN = "I",
- INCHES = "I",
- YARDS = "Y",
- YD = "Y",
- YRD = "Y",
- MILES = "MI",
- MILIMETERS = "MM",
- CENTIMETERS = "CM",
- METERS = "M",
- MT = "M",
- MTR = "M",
- KILOMETERS = "KM",
- KMT = "KM"
- }
- local Ref = "Real"
- local function DeferToWhat(Canon) if Canon ~= nil and Canon == true then Ref = "Canon" else Ref = "Real" end end
- local function ParseUnit(Unit) Unit = string.upper(Unit) if API.TranslationTable[Unit] ~= nil then Unit = API.TranslationTable[Unit] elseif API.TranslationTable[Unit.."S"] ~= nil then Unit = API.TranslationTable[Unit.."S"] end return Unit end
- function API.Help(Req)
- print("Roblox Unit Conversion v1.0 Help: ")
- if Req == nil then Req = "General" end
- Req = string.lower(Req)
- if Req == "unit" then
- print("You can only convert to and from the following units of measurement: ")
- print("feet, f")
- print("inches, i")
- print("yards, y")
- print("miles, mi")
- print("milimeters, mm")
- print("centimeters, cm")
- print("meters, m")
- print("kilometers, km")
- elseif Req == "api" then
- print("There are two separate functions you can call: ")
- print("StudsTo( number Amount of studs, string Unit you're converting to, bool Canon or Realistic conversion )")
- print'and'
- print("ToStuds( number Amount of your unit, string Unit you're converting to, bool Canon or Realistic conversion )")
- print"Leaving the thrid argument blank will always result in 'Realistic' conversions."
- else
- print('Welcome to the full help guide on converting ROBLOX studs to and from realistic units!')
- print''
- print''
- print("There are two separate functions you can call: ")
- print("StudsTo( number Amount of studs, string Unit you're converting to, bool Canon or Realistic conversion )")
- print'and'
- print("ToStuds( number Amount of your unit, string Unit you're converting to, bool Canon or Realistic conversion )")
- print"Leaving the thrid argument blank will always result in 'Realistic' conversions."
- print''
- print''
- print("You can only convert to and from the following units of measurement: ")
- print("feet, f")
- print("inches, i")
- print("yards, y")
- print("miles, mi")
- print("milimeters, mm")
- print("centimeters, cm")
- print("meters, m")
- print("kilometers, km")
- print''
- print''
- end
- end
- function API.StudsTo(Amount,Unit,Canon)
- DeferToWhat(Canon)
- if API[Ref.."Multipliers"][Unit] == nil then Unit = ParseUnit(Unit) end
- if API[Ref.."Multipliers"][Unit] == nil then
- print("Sorry pal, I can't convert to that unit") API.Help("Unit") return 0.0
- elseif Amount == nil then
- print("Sorry pal, you didn't give me a number...") API.Help("API") return 0.0
- elseif Amount == 0 or math.abs(Amount) >= 4294967295 then
- print("Very funny, nobody can convert that!") API.Help("API") return 0.0
- else
- return Amount/API[Ref.."Multipliers"][Unit]
- end
- end
- function API.ToStuds(Amount,Unit,Canon)
- DeferToWhat(Canon)
- if API[Ref.."Multipliers"][Unit] == nil then Unit = ParseUnit(Unit) end
- if API[Ref.."Multipliers"][Unit] == nil then
- print("Sorry pal, I can't convert from that unit") API.Help("Unit") return 0.0
- elseif Amount == nil then
- print("Sorry pal, you didn't give me a number...") API.Help("API") return 0.0
- elseif Amount == 0 or math.abs(Amount) >= 4294967295 then
- print("Very funny, nobody can convert that!") API.Help("API") return 0.0
- else
- return Amount*API[Ref.."Multipliers"][Unit]
- end
- end
- return API
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement