Posted 03 March 2014 - 08:32 PM
Hello, I've just finished my first API! Its very simple but useful (I hope). It includes 3 functions: Round, Percentage and PercentBar
pastebin get f1SyGYqN BarAPI
Please Note There is currently no error checking so incorrect values will cause issues.
Please report any issues and suggestions
CODE:
How to Call the functions:
How to call Percentage:
total = level if full
How to call Percentage:
idp = how many decimal places to round to
How to call PercentBar:
CursorX = X pos of where you want the bar
CursorY = Y pos of where you want the bar
InActiveColor = Color of empty bar HAS TO BE NUMBER CODE
ActiveColor = Color of full bar HAS TO BE NUMBER CODE
TextColor = Color of the "/" on the bar set to the same as ActiveColor if you dont want it HAS TO BE NUMBER CODE
n = Percentage to be full (Atm the program is only accurate to 10%) You can use my percentage function to work this out
Mon = Where to display the bar
Screenshots

pastebin get f1SyGYqN BarAPI
Please Note There is currently no error checking so incorrect values will cause issues.
Please report any issues and suggestions
CODE:
Spoiler
--[[BarAPI
ActiveColor = Full BarColor
InActiveColor = Empty Bar Color
n = Percentage that needs to be filled
CursorX = Bar start X pos
CursorY = Bar Start Y pos
TextColor = Color for stripes on bar set to same as ActiveColor if you dont want bars
Mon = Monitor to display on
Made By SteamPunk_Devil -- CCfourm Name Makeme -- Ingame Name SteamPunk_Angel
Special Thanks to CometWolf I would not have been able to make this without you!
]]--
function Percentage(current,total) --returns One number as a percentage of the second one
local No1 = current
local No2 = total
local Percent = (No1 / No2) * 100
return Percent
end
function Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function PercentBar(CursorX, CursorY, InActiveColor, ActiveColor, TextColor, n, Mon)
local n10 = n/10
local BarCursX = CursorX
local BarCursY = CursorY
local FormdN = Round(n10, 0)
local Paste = Mon
Paste.setCursorPos(CursorX, CursorY)
Paste.setBackgroundColor(InActiveColor)
Paste.write(" ")
Paste.setCursorPos(CursorX, CursorY)
Paste.setBackgroundColor(ActiveColor)
Paste.setTextColor(TextColor)
Paste.write(string.rep("/", formdN))
BarCursX = BarCursX + 10
Paste.setBackgroundColor(32768)
end
How to Call the functions:
How to call Percentage:
BarAPI.Percentage(current, total)
current = Current leveltotal = level if full
How to call Percentage:
BarAPI.Round(num, idp)
num = unrounded numberidp = how many decimal places to round to
How to call PercentBar:
BarAPI.PercentBar(CursorX, CursorY, InActiveColor, ActiveColor, TextColor, n,
Mon)
CursorX = X pos of where you want the bar
CursorY = Y pos of where you want the bar
InActiveColor = Color of empty bar HAS TO BE NUMBER CODE
ActiveColor = Color of full bar HAS TO BE NUMBER CODE
TextColor = Color of the "/" on the bar set to the same as ActiveColor if you dont want it HAS TO BE NUMBER CODE
n = Percentage to be full (Atm the program is only accurate to 10%) You can use my percentage function to work this out
Mon = Where to display the bar
Screenshots
Spoiler

Edited on 03 March 2014 - 07:39 PM