Advertisement
Guest User

Zanqual

a guest
Jan 9th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.76 KB | None | 0 0
  1. --## Zanqual API v0.3 COPYRIGHT (c) ##--
  2. --## by DaloDaloDalo/XxCubegamerxX ##--
  3.  
  4. function p(text) return print(text) end
  5. function scp(x,y) return term.setCursorPos(x,y) end
  6. function stc(clr) return term.setTextColor(clr) end
  7. function sbc(clr) return term.setBackgroundColor(clr) end
  8. function c() return term.clear() end
  9. function cl() return term.clearLine() end
  10. function w(text) return write(text) end
  11.  
  12. function rednet.checkModem()
  13.   for n,sModem in ipairs(peripheral.getNames()) do
  14.     if peripheral.getType(sModem) == "modem" then
  15.       return sModem
  16.     end
  17.   end
  18.   return false
  19. end
  20.  
  21. local oldTostring = tostring
  22. tostring = function(numberTable,more)
  23.   if type(numberTable) == "table" then
  24.     local extractedText = ""
  25.     if not more then
  26.       more = " "
  27.     end
  28.     for _,tableExtract in pairs(numberTable) do
  29.       extractedText = extractedText..tableExtract..more
  30.     end
  31.     return extractedText
  32.   else
  33.     return oldTostring(numberTable)
  34.   end
  35. end
  36.  
  37. local function rednetAll(var)
  38.   local output = 0
  39.   for n,sModem in ipairs(peripheral.getNames()) do
  40.     if peripheral.getType(sModem) == "modem" then
  41.       if not rednet.isOpen(sModem) then
  42.         output = output+1
  43.         if var == "open" then
  44.           rednet.open(sModem)
  45.         elseif var == "close" then
  46.           rednet.close(sModem)
  47.         end
  48.       end
  49.     end
  50.   end
  51.   if output == 0 then
  52.     return false
  53.   end
  54.   return output
  55. end
  56.  
  57. function rednet.openAll() return rednetAll("open") end
  58. function rednet.closeAll() return rednetAll("close") end
  59.  
  60. function colors.random()
  61.   local colorTable4Bit = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  62.   local colorTable2Bit = {1,128,256,32768}
  63.   if term.isColor() then
  64.     return colorTable4Bit[math.random(1,16)]
  65.   end
  66.   return colorTable2Bit[math.random(1,4)]
  67. end
  68.  
  69. function textutils.delayWrite(text,delay)
  70.   if type(text) ~= "string" or type(delay) ~= "number" then
  71.     error("string,number expected.")
  72.   end
  73.   for stringSub = 1, string.len(text) do
  74.     write(string.sub(text,stringSub,stringSub))
  75.     sleep(delay)
  76.   end
  77. end
  78.  
  79. function colors.getTable()
  80.   if term.isColor() then
  81.     return {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  82.   end
  83.   return {1,128,256,32768}
  84. end
  85.  
  86. function textutils.delayPrint(text,delay)
  87.   textutils.delayWrite(text,delay)
  88.   print("")
  89. end
  90.  
  91. function string.random(nStringLen)
  92.   if nStringLen ~= "number" then
  93.     error("number expected.")
  94.   end
  95.   local aviableChars = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@|\\/%&()=?}][{´`'#*~+,.-;:_<>^°\"$!"}
  96.   local output = ""
  97.   for returnOutput = 1, nStringLen do
  98.     subRandom = math.random(1,string.len(aviableChars))
  99.     output = output..string.sub(aviableChars,subRandom,subRandom)
  100.   end
  101.   return output
  102. end
  103.  
  104. function fs.write(path,text)
  105.   if type(path) ~= "string" or type(text) ~= "string" then
  106.     error("string,string expected.")
  107.   end
  108.   local file = assert(fs.open(path,"w"))
  109.   file.write(text)
  110.   file.close()
  111. end
  112.  
  113. function fs.writeFromTable(path,t)
  114.   if type(path) ~= "string" or type(t) ~= "table" then
  115.     error("string,table expected.")
  116.   end
  117.   fs.write(path,tostring(t,"\n"))
  118. end
  119.  
  120. function fs.getLine(path,ln)
  121.   if type(path) ~= "string" or type(ln) ~= "number" then
  122.     error("string,number expected.")
  123.   end
  124.   if not fs.exists(path) then
  125.     error("file "..path.." doesn't exist.")
  126.   end
  127.   local file = fs.open(path,"r")
  128.   return file.readLine(ln)
  129. end
  130.  
  131. function fs.getTable(path)
  132.   if type(path) ~= "string" then
  133.     error("string expected.")
  134.   end
  135.   if not fs.exists(path) then
  136.     error("file "..path.." doesn't exist.")
  137.   end
  138.   local file = fs.open(path,"r")
  139.   local nLine = 1
  140.   local lines = {}
  141.   local line = file.readLine("*1")
  142.   while line ~= nil do
  143.     lines[nLine] = line
  144.     nLine = nLine+1
  145.     line = file.readLine("*1")
  146.   end
  147.   return lines
  148. end
  149.  
  150. function fs.getString(path)
  151.   if type(path) ~= "string" then
  152.     error("string expected.")
  153.   end
  154.   if not fs.exists(path) then
  155.     error("file "..path.." doesn't exist.")
  156.   end
  157.   local file = fs.open(path,"r")
  158.   return file.readAll()
  159. end
  160.  
  161. function fs.replaceLine(path,ln,text)
  162.   if type(path) ~= "string" or type(ln) ~= "number" or type(text) ~= "string" then
  163.     error("string,number,string expected.")
  164.   end
  165.   if not fs.exists(path) then
  166.     error("file "..path.." doesn't exists")
  167.   end
  168.   local lines = fs.getTable(path)
  169.   lines[ln] = text
  170.   fs.writeFromTable(path,lines)
  171. end
  172.  
  173. function fs.append(path,text)
  174.   if type(path) ~= "string" or type(path) ~= "string" then
  175.     error("string,string expected.")
  176.   end
  177.   if not fs.exists(path) then
  178.     error("file "..path.." doesn't exist.")
  179.   end
  180.   local file = assert(fs.open(path,"a"))
  181.   file.write(text)
  182.   file.close()
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement