Advertisement
AquaJD

[AUT] AutosAPI

May 3rd, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.93 KB | None | 0 0
  1. --[[
  2.  
  3.     Autos
  4.     Official API File
  5.  
  6. --]]
  7.  
  8.  
  9. -- Function to draw a box on the screen
  10. function draw_Box(X,Y,W,H,bCol,tCol,title,bExit)
  11.   moveY = Y
  12.   setCursor(X,Y)
  13.   tColor(tCol)
  14.   bColor(bCol)
  15.   for i=1,H do
  16.     setCursor(X,moveY)
  17.     print(string.rep(" ",W))
  18.     moveY = moveY + 1
  19.   end
  20.   setCursor(X+math.max(math.floor(W/2)-(#title/2))+1,Y)
  21.   print(title)
  22.   if bExit == true then
  23.     tColor(colors.red)
  24.     setCursor(X+W-1,Y)
  25.     print("X")
  26.   end
  27. end
  28.  
  29. -- Function to draw a loading bar
  30. -- cPercent is the percentage it has done (goes up 1-10)
  31. -- fColor is the color it loads with
  32. function draw_loadingBar(X,Y,bCol,fCol,cPercent)
  33.   drawX = X
  34.   for i=1,21 do
  35.     paintutils.drawPixel(drawX,Y,bCol)
  36.     drawX = drawX+1
  37.   end
  38.   drawX = X
  39.   for i=1,21 do
  40.     paintutils.drawPixel(drawX,Y+2,bCol)
  41.     drawX = drawX+1
  42.   end
  43.   paintutils.drawPixel(X,Y+1,bCol)
  44.   paintutils.drawPixel(X+20,Y+1,bCol)
  45.   if cPercent == 1 then
  46.     paintutils.drawPixel(X+1,Y+1,fCol)
  47.   elseif cPercent == 2 then
  48.     paintutils.drawPixel(X+2,Y+1,fCol)
  49.   elseif cPercent == 3 then
  50.     paintutils.drawPixel(X+3,Y+1,fCol)
  51.   elseif cPercent == 4 then
  52.     paintutils.drawPixel(X+4,Y+1,fCol)
  53.   elseif cPercent == 5 then
  54.     paintutils.drawPixel(X+5,Y+1,fCol)
  55.   elseif cPercent == 6 then
  56.     paintutils.drawPixel(X+6,Y+1,fCol)
  57.   elseif cPercent == 7 then
  58.     paintutils.drawPixel(X+7,Y+1,fCol)
  59.   elseif cPercent == 8 then
  60.     paintutils.drawPixel(X+8,Y+1,fCol)
  61.   elseif cPercent == 9 then
  62.     paintutils.drawPixel(X+9,Y+1,fCol)
  63.   elseif cPercent == 10 then
  64.     paintutils.drawPixel(X+10,Y+1,fCol)
  65.   elseif cPercent == 11 then
  66.     paintutils.drawPixel(X+11,Y+1,fCol)
  67.   elseif cPercent == 12 then
  68.     paintutils.drawPixel(X+12,Y+1,fCol)
  69.   elseif cPercent == 13 then
  70.     paintutils.drawPixel(X+13,Y+1,fCol)
  71.   elseif cPercent == 14 then
  72.     paintutils.drawPixel(X+14,Y+1,fCol)
  73.   elseif cPercent == 15 then
  74.     paintutils.drawPixel(X+15,Y+1,fCol)
  75.   elseif cPercent == 16 then
  76.     paintutils.drawPixel(X+16,Y+1,fCol)
  77.   elseif cPercent == 17 then
  78.     paintutils.drawPixel(X+17,Y+1,fCol)
  79.   elseif cPercent == 18 then
  80.     paintutils.drawPixel(X+18,Y+1,fCol)
  81.   else
  82.     error("LoadingBar: Invalid load percentage")
  83.   end
  84. end
  85.  
  86. -- Function to upload a file to Pastebin
  87. -- Return True: Successfully uploaded
  88. -- Return False-"failed": Connection to Pastebin lost
  89. -- Return False-"inexistent": File does not exist
  90. function pbAdd(fName)
  91.   if fs.exists(fName) then
  92.     local file = fs.open(fName,"r")
  93.     local fText = file.readAll()
  94.     file.close()
  95.     local key = "0ec2eb25b6166c0c27a394ae118ad829"
  96.     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))
  97.     if response then
  98.       local tResponse = response.readAll()
  99.       tResponse.close()
  100.       local code = string.match(sResponse,"[^/]+$")
  101.       return true,code
  102.     else
  103.       return false,"connection_lost"
  104.     end
  105.   else
  106.     return false,"file_inexistent"
  107.   end
  108. end
  109.  
  110. -- Function to download a file from Pastebin
  111. -- Return True: Successfully downloaded
  112. -- Return False: Connection to Pastebin lost
  113. function pbGet(code,filename)
  114.   if not fs.exists(filename) then
  115.     local httpCode = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code))
  116.     local contents = httpCode.readAll()
  117.     local file = assert(fs.open(filename,"w"))
  118.     file.write(contents)
  119.     file.close()
  120.     return true
  121.   else
  122.     return false
  123.   end
  124. end
  125.  
  126. -- Function to 'clean' the screen
  127. function clean(x,y)
  128.   if x == "current" and y == "current" then
  129.     local x,y = term.getCursorPos()
  130.   elseif x == "current" then
  131.     local x,Y = term.getCursorPos()
  132.   elseif y == "current" then
  133.     local X,y = term.getCursorPos()
  134.   end
  135.   term.clear()
  136.   setCursor(x,y)
  137. end
  138.  
  139. -- Function to change the Cursor Position
  140. function setCursor(x,y)
  141.   term.setCursorPos(x,y)
  142. end
  143.  
  144. -- Function to change the Text Color
  145. function tColor(color)
  146.   term.setTextColor(color)
  147. end
  148.  
  149. -- Function to change the Background Color
  150. function bColor(color)
  151.   term.setBackgroundColor(color)
  152. end
  153.  
  154. -- Function to print an error
  155. function pError(type,err)
  156.   autos.tColor(colors.red)
  157.   local x,y = term.getCursorPos()
  158.   print("["..type.."]")
  159.   term.setCursor(x+6,y)
  160.   textutils.slowPrint("["..type.."] "..err)
  161. end
  162.  
  163. -- Function to Write to a File
  164. -- Return True: File existed
  165. -- Return False: File did not exist
  166. function fileWriteTo(file,string)
  167.   if not fs.exists(file) then
  168.     local file = fs.open(file,"w")
  169.     file.writeLine(string)
  170.     file.close()
  171.     return false
  172.   elseif fs.exists(file) then
  173.     local file = fs.open(file,"a")
  174.     file.writeLine(string)
  175.     file.close()
  176.     return true
  177.   end
  178. end
  179.  
  180. -- Function to skip to the next line  
  181. function skipLine(lines)
  182.   local x,y = term.getCursorPos()
  183.   term.setCursorPos(x,y+lines)
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement