Guest User

engines

a guest
Aug 22nd, 2019
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. args = {...}
  2. if #args > 0 then
  3.   name = table.concat(args, " ")
  4. else
  5.   error("Provide a name")
  6. end  
  7.  
  8. shell.run("clear")
  9. local rside = "front"
  10. rednet.open("top")
  11.  
  12. uID = name..":"..os.getComputerID()
  13.  
  14. while true do
  15.   print(uID," - Waiting for input...")
  16.   sId, msg, prot = rednet.receive("engines")
  17.   local replymsg
  18.   local trim = msg:find(" ")
  19.   if trim ~= nil then
  20.     isvalid = true
  21.     cmd = msg:sub(trim):gsub("%s+","")
  22.    
  23.     if cmd == "on" then
  24.       rs.setOutput(rside, true)
  25.     elseif cmd == "off" then
  26.       rs.setOutput(rside, false)
  27.     elseif cmd == "status" then
  28.       -- do nothing
  29.     elseif cmd == "ids" then
  30.       replymsg = uID
  31.     else
  32.       isvalid = false
  33.     end
  34.    
  35.     if isvalid and replymsg == nil then
  36.       replymsg = uID.." - Engines Running: "..tostring(rs.getOutput(rside)).."|green"
  37.     elseif replymsg ~= nil then
  38.       -- do nothing
  39.     else
  40.       replymsg = uID.." - Invalid Command|red"
  41.     end
  42.   else
  43.     replymsg = uID.." - Invalid Command|red"
  44.   end
  45.  
  46.   rednet.send(sId, replymsg, prot)
  47.   print(replymsg:sub(1,replymsg:find("|")-1))
  48. end
  49.  
  50. rednet.close("top")
RAW Paste Data