Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function playSoundCoroutine(...)
- local args = {...}
- parallel.waitForAny((function() playSound(unpack(args)) end))
- end
- function playSound(...)
- local args = {...}
- --Pitch, Length
- side2 = nil
- if (#args == 1) then
- local sides = rs.getSides()
- for i = 1, #sides do
- if (peripheral.getType(sides[i]) == "speaker") then
- side2 = sides[i]
- break
- end
- end
- else
- side2 = args[2]
- end
- if (side2 ~= nil) then
- local speaker = peripheral.wrap(side2)
- local sound2 = args[1]
- sound2 = split(sound2,":")
- speaker.shutdown()
- for i = 1, #sound2, 2 do
- speaker.start(1,tonumber(sound2[i]))
- sleep(tonumber(sound2[i + 1]))
- end
- speaker.shutdown()
- return true
- else
- return false
- end
- end
- function quickRead(file)
- if (fs.exists(file)) then
- local file2 = fs.open(file,"r")
- local file3 = file2.readAll()
- file2.close()
- return file3
- else
- return nil
- end
- end
- function quickWrite(file,text)
- local file2 = fs.open(file,"w")
- file2.write(text)
- file2.close()
- end
- function dbGetAll(file)
- if (fs.exists(file)) then
- local db2 = fs.open(file,"r")
- local db = textutils.unserialize(db2.readAll())
- db2.close()
- return db
- end
- end
- function dbSetValue(file,user,valueName,value)
- local db2 = fs.open(file,"r")
- local db = textutils.unserialize(db2.readAll())
- db2.close()
- db[user][valueName] = value
- local db2 = fs.open(file,"w")
- db2.write(textutils.serialize[db])
- db2.close()
- end
- function split(pString, pPattern)
- local Table = {}
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- function tf(t,c)
- if (t == c) then
- return 2
- else
- return 1
- end
- end
- function printCenter(str,y,clear)
- if (str ~= nil) then
- local x3, y3 = term.getCursorPos()
- local x2, y2 = term.getSize()
- term.setCursorPos((x2/2)-(string.len(str)/2),y)
- if (clear == nil) then
- term.clearLine()
- end
- write(str)
- term.setCursorPos(x3,y3)
- end
- end
- function menu(choices,title, bg, tcolor, text, ccolor)
- if (term.isColor() and bg ~= nil) then
- term.setBackgroundColor(bg)
- end
- term.clear()
- choice = 1
- if (term.isColor() and tcolor ~= nil) then
- term.setTextColor(tcolor)
- end
- printCenter(title,1)
- z, c = term.getSize()
- for i = 1, #choices do
- choices[i] = {choices[i],"> "..choices[i].." <"}
- if (term.isColor() and text ~= nil) then
- term.setTextColor(text)
- end
- printCenter(choices[i][1],i + 2)
- if (i == 1 and term.isColor() and ccolor ~= nil) then
- term.setTextColor(ccolor)
- end
- if (i == 1) then
- term.setCursorPos(((z/2) - (string.len(choices[i][1])/2))-2,i + 2)
- write("> ")
- term.setCursorPos(((z/2) + (string.len(choices[i][1])/2)), i + 2)
- write(" <")
- end
- end
- dun = false
- while dun == false do
- event, key = os.pullEvent("key")
- if (key == 28) then
- dun = true
- elseif (key == 208) then
- if (term.isColor()) then
- term.setTextColor(text)
- end
- printCenter(choices[choice][1],choice + 2)
- if (choice == #choices) then
- choice = 1
- else
- choice = choice + 1
- end
- if (term.isColor()) then
- term.setTextColor(text)
- end
- printCenter(choices[choice][1],choice + 2)
- if (term.isColor()) then
- term.setTextColor(ccolor)
- end
- term.setCursorPos(((z/2) - (string.len(choices[choice][1])/2)) - 2,choice + 2)
- write("> ")
- term.setCursorPos(((z/2) + (string.len(choices[choice][1])/2)),choice + 2)
- write(" <")
- elseif (key == 200) then
- if (term.isColor()) then
- term.setTextColor(text)
- end
- printCenter(choices[choice][1],choice + 2)
- if (choice == 1) then
- choice = #choices
- else
- choice = choice - 1
- end
- printCenter(choices[choice][1],choice + 2)
- if (term.isColor()) then
- term.setTextColor(ccolor)
- end
- term.setCursorPos(((z/2) - (string.len(choices[choice][1])/2)) - 2, choice + 2)
- write("> ")
- term.setCursorPos(((z/2) + (string.len(choices[choice][1])/2)), choice + 2)
- write(" <")
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- return choice, choices[choice][1]
- end
Advertisement
Add Comment
Please, Sign In to add comment