Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --## Zanqual API v0.3 COPYRIGHT (c) ##--
- --## by DaloDaloDalo/XxCubegamerxX ##--
- function p(text) return print(text) end
- function scp(x,y) return term.setCursorPos(x,y) end
- function stc(clr) return term.setTextColor(clr) end
- function sbc(clr) return term.setBackgroundColor(clr) end
- function c() return term.clear() end
- function cl() return term.clearLine() end
- function w(text) return write(text) end
- function rednet.checkModem()
- for n,sModem in ipairs(peripheral.getNames()) do
- if peripheral.getType(sModem) == "modem" then
- return sModem
- end
- end
- return false
- end
- local oldTostring = tostring
- tostring = function(numberTable,more)
- if type(numberTable) == "table" then
- local extractedText = ""
- if not more then
- more = " "
- end
- for _,tableExtract in pairs(numberTable) do
- extractedText = extractedText..tableExtract..more
- end
- return extractedText
- else
- return oldTostring(numberTable)
- end
- end
- local function rednetAll(var)
- local output = 0
- for n,sModem in ipairs(peripheral.getNames()) do
- if peripheral.getType(sModem) == "modem" then
- if not rednet.isOpen(sModem) then
- output = output+1
- if var == "open" then
- rednet.open(sModem)
- elseif var == "close" then
- rednet.close(sModem)
- end
- end
- end
- end
- if output == 0 then
- return false
- end
- return output
- end
- function rednet.openAll() return rednetAll("open") end
- function rednet.closeAll() return rednetAll("close") end
- function colors.random()
- local colorTable4Bit = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
- local colorTable2Bit = {1,128,256,32768}
- if term.isColor() then
- return colorTable4Bit[math.random(1,16)]
- end
- return colorTable2Bit[math.random(1,4)]
- end
- function textutils.delayWrite(text,delay)
- if type(text) ~= "string" or type(delay) ~= "number" then
- error("string,number expected.")
- end
- for stringSub = 1, string.len(text) do
- write(string.sub(text,stringSub,stringSub))
- sleep(delay)
- end
- end
- function colors.getTable()
- if term.isColor() then
- return {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
- end
- return {1,128,256,32768}
- end
- function textutils.delayPrint(text,delay)
- textutils.delayWrite(text,delay)
- print("")
- end
- function string.random(nStringLen)
- if nStringLen ~= "number" then
- error("number expected.")
- end
- local aviableChars = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@|\\/%&()=?}][{´`'#*~+,.-;:_<>^°\"$!"}
- local output = ""
- for returnOutput = 1, nStringLen do
- subRandom = math.random(1,string.len(aviableChars))
- output = output..string.sub(aviableChars,subRandom,subRandom)
- end
- return output
- end
- function fs.write(path,text)
- if type(path) ~= "string" or type(text) ~= "string" then
- error("string,string expected.")
- end
- local file = assert(fs.open(path,"w"))
- file.write(text)
- file.close()
- end
- function fs.writeFromTable(path,t)
- if type(path) ~= "string" or type(t) ~= "table" then
- error("string,table expected.")
- end
- fs.write(path,tostring(t,"\n"))
- end
- function fs.getLine(path,ln)
- if type(path) ~= "string" or type(ln) ~= "number" then
- error("string,number expected.")
- end
- if not fs.exists(path) then
- error("file "..path.." doesn't exist.")
- end
- local file = fs.open(path,"r")
- return file.readLine(ln)
- end
- function fs.getTable(path)
- if type(path) ~= "string" then
- error("string expected.")
- end
- if not fs.exists(path) then
- error("file "..path.." doesn't exist.")
- end
- local file = fs.open(path,"r")
- local nLine = 1
- local lines = {}
- local line = file.readLine("*1")
- while line ~= nil do
- lines[nLine] = line
- nLine = nLine+1
- line = file.readLine("*1")
- end
- return lines
- end
- function fs.getString(path)
- if type(path) ~= "string" then
- error("string expected.")
- end
- if not fs.exists(path) then
- error("file "..path.." doesn't exist.")
- end
- local file = fs.open(path,"r")
- return file.readAll()
- end
- function fs.replaceLine(path,ln,text)
- if type(path) ~= "string" or type(ln) ~= "number" or type(text) ~= "string" then
- error("string,number,string expected.")
- end
- if not fs.exists(path) then
- error("file "..path.." doesn't exists")
- end
- local lines = fs.getTable(path)
- lines[ln] = text
- fs.writeFromTable(path,lines)
- end
- function fs.append(path,text)
- if type(path) ~= "string" or type(path) ~= "string" then
- error("string,string expected.")
- end
- if not fs.exists(path) then
- error("file "..path.." doesn't exist.")
- end
- local file = assert(fs.open(path,"a"))
- file.write(text)
- file.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement