GravityCube

SignProgram

May 27th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function peripheral.find(pType)
  2.     pList = {}
  3.     for _,pName in pairs(peripheral.getNames()) do
  4.         if peripheral.getType(pName) == pType then
  5.             table.insert(pList, peripheral.wrap(pName))
  6.         end
  7.     end
  8.     return unpack(pList)
  9. end
  10. local sign = peripheral.find("sign")
  11. local colorSymbol = string.char(194) .. string.char(167)
  12.  
  13. function saveSign(file_name)
  14.     local file = fs.open(file_name, "w")
  15.     for y=1, 4 do
  16.         file.writeLine( sign.getLine(y) )
  17.     end
  18.     file.close()
  19. end
  20.  
  21. function pasteSign(file_name)
  22.     local file = fs.open(file_name, "r")
  23.     for y=1, 4 do
  24.         txt[y] = sign.setLine(y, file.readLine() or "")
  25.     end
  26.     file.close()
  27. end
  28.  
  29. local args = {...}
  30. if args[1] then  
  31.     local line = tonumber(args[1])
  32.     if line and args[2] then
  33.         local text = ""
  34.         for i=2, #args, 1 do
  35.             text = text .. args[i]
  36.             if args[i+1] then
  37.                 text = text .. " "
  38.             end
  39.         end
  40.         text = text:gsub("&", colorSymbol)
  41.         sign.setLine(line,text)
  42.         return
  43.     end
  44.    
  45.     if args[1] == "save" then
  46.         saveSign(args[2] or "savedSign")
  47.         return
  48.     end
  49.    
  50.     if args[1] == "paste" then
  51.         pasteSign(args[2] or "savedSign")
  52.         return
  53.     end
  54. end
  55.  
  56. print("Usage 1: sign <line> <text>")
  57. print("Usage 2: sign save <filename>")
  58. print("Usage 3: sign paste <filename>")
Add Comment
Please, Sign In to add comment