Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Autos
- Official API File
- --]]
- -- Function to draw a box on the screen
- function draw_Box(X,Y,W,H,bCol,tCol,title,bExit)
- moveY = Y
- setCursor(X,Y)
- tColor(tCol)
- bColor(bCol)
- for i=1,H do
- setCursor(X,moveY)
- print(string.rep(" ",W))
- moveY = moveY + 1
- end
- setCursor(X+math.max(math.floor(W/2)-(#title/2))+1,Y)
- print(title)
- if bExit == true then
- tColor(colors.red)
- setCursor(X+W-1,Y)
- print("X")
- end
- end
- -- Function to draw a loading bar
- -- cPercent is the percentage it has done (goes up 1-10)
- -- fColor is the color it loads with
- function draw_loadingBar(X,Y,bCol,fCol,cPercent)
- drawX = X
- for i=1,21 do
- paintutils.drawPixel(drawX,Y,bCol)
- drawX = drawX+1
- end
- drawX = X
- for i=1,21 do
- paintutils.drawPixel(drawX,Y+2,bCol)
- drawX = drawX+1
- end
- paintutils.drawPixel(X,Y+1,bCol)
- paintutils.drawPixel(X+20,Y+1,bCol)
- if cPercent == 1 then
- paintutils.drawPixel(X+1,Y+1,fCol)
- elseif cPercent == 2 then
- paintutils.drawPixel(X+2,Y+1,fCol)
- elseif cPercent == 3 then
- paintutils.drawPixel(X+3,Y+1,fCol)
- elseif cPercent == 4 then
- paintutils.drawPixel(X+4,Y+1,fCol)
- elseif cPercent == 5 then
- paintutils.drawPixel(X+5,Y+1,fCol)
- elseif cPercent == 6 then
- paintutils.drawPixel(X+6,Y+1,fCol)
- elseif cPercent == 7 then
- paintutils.drawPixel(X+7,Y+1,fCol)
- elseif cPercent == 8 then
- paintutils.drawPixel(X+8,Y+1,fCol)
- elseif cPercent == 9 then
- paintutils.drawPixel(X+9,Y+1,fCol)
- elseif cPercent == 10 then
- paintutils.drawPixel(X+10,Y+1,fCol)
- elseif cPercent == 11 then
- paintutils.drawPixel(X+11,Y+1,fCol)
- elseif cPercent == 12 then
- paintutils.drawPixel(X+12,Y+1,fCol)
- elseif cPercent == 13 then
- paintutils.drawPixel(X+13,Y+1,fCol)
- elseif cPercent == 14 then
- paintutils.drawPixel(X+14,Y+1,fCol)
- elseif cPercent == 15 then
- paintutils.drawPixel(X+15,Y+1,fCol)
- elseif cPercent == 16 then
- paintutils.drawPixel(X+16,Y+1,fCol)
- elseif cPercent == 17 then
- paintutils.drawPixel(X+17,Y+1,fCol)
- elseif cPercent == 18 then
- paintutils.drawPixel(X+18,Y+1,fCol)
- else
- error("LoadingBar: Invalid load percentage")
- end
- end
- -- Function to upload a file to Pastebin
- -- Return True: Successfully uploaded
- -- Return False-"failed": Connection to Pastebin lost
- -- Return False-"inexistent": File does not exist
- function pbAdd(fName)
- if fs.exists(fName) then
- local file = fs.open(fName,"r")
- local fText = file.readAll()
- file.close()
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post("http://pastebin.com/api/api_post.php","api_option=paste&".."api_dev_key="..key.."&".."api_paste_format=lua&".."api_paste_name="..textutils.urlEncode(fName).."&".."api_paste_code="..textutils.urlEncode(fText))
- if response then
- local tResponse = response.readAll()
- tResponse.close()
- local code = string.match(sResponse,"[^/]+$")
- return true,code
- else
- return false,"connection_lost"
- end
- else
- return false,"file_inexistent"
- end
- end
- -- Function to download a file from Pastebin
- -- Return True: Successfully downloaded
- -- Return False: Connection to Pastebin lost
- function pbGet(code,filename)
- if not fs.exists(filename) then
- local httpCode = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code))
- local contents = httpCode.readAll()
- local file = assert(fs.open(filename,"w"))
- file.write(contents)
- file.close()
- return true
- else
- return false
- end
- end
- -- Function to 'clean' the screen
- function clean(x,y)
- if x == "current" and y == "current" then
- local x,y = term.getCursorPos()
- elseif x == "current" then
- local x,Y = term.getCursorPos()
- elseif y == "current" then
- local X,y = term.getCursorPos()
- end
- term.clear()
- setCursor(x,y)
- end
- -- Function to change the Cursor Position
- function setCursor(x,y)
- term.setCursorPos(x,y)
- end
- -- Function to change the Text Color
- function tColor(color)
- term.setTextColor(color)
- end
- -- Function to change the Background Color
- function bColor(color)
- term.setBackgroundColor(color)
- end
- -- Function to print an error
- function pError(type,err)
- autos.tColor(colors.red)
- local x,y = term.getCursorPos()
- print("["..type.."]")
- term.setCursor(x+6,y)
- textutils.slowPrint("["..type.."] "..err)
- end
- -- Function to Write to a File
- -- Return True: File existed
- -- Return False: File did not exist
- function fileWriteTo(file,string)
- if not fs.exists(file) then
- local file = fs.open(file,"w")
- file.writeLine(string)
- file.close()
- return false
- elseif fs.exists(file) then
- local file = fs.open(file,"a")
- file.writeLine(string)
- file.close()
- return true
- end
- end
- -- Function to skip to the next line
- function skipLine(lines)
- local x,y = term.getCursorPos()
- term.setCursorPos(x,y+lines)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement