Advertisement
EliteGaming

RednetReceiver

Dec 17th, 2014
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. defaultSide = "left"
  2. autoModeBool = false
  3. pocketID = 36
  4. pocketID2 = 60
  5.  
  6. -- BundledCable Color Declarations
  7. local witherColor = colors.black
  8. local forwardColor = colors.blue
  9. local autoModeColor = colors.green
  10. local autoModeCheckColor = colors.brown
  11. local autoModeCheckColor2 = colors.magenta
  12.  
  13. -- Fixes some API changes
  14. function colors.subtract(r, ...)
  15.         for n, c in ipairs({ ... }) do
  16.                 r = bit.band(r, bit.bnot(c)%2^31)
  17.         end
  18.         return r
  19. end
  20.  
  21. -- Pulses a bundled redstone color
  22. function redstonePulse(color, side)
  23. addColor(color, side)
  24. sleep(.5)
  25. delColor(color, side)
  26. end
  27.  
  28. -- Turns on a color of a bundled cable
  29. function addColor(color , side)
  30.  rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side) + color))
  31. end
  32.  
  33. -- Turns a color off of a bundled cable
  34. function delColor(color, side)
  35.    rs.setBundledOutput(side, colors.subtract(redstone.getBundledOutput(side), color))
  36. end
  37.  
  38. -- Turns on the UberMiner AutoMode
  39. function autoMode()
  40.     bool = checkColor(autoModeColor, defaultSide)
  41.     bool2 = checkColor(autoModeCheckColor, defaultSide)
  42.    
  43.     -- If Kilo's server is running the AutoMode this will cancel it from running again.
  44.     if bool2 then
  45.         term.setTextColor(colors.red)
  46.         print("Already Running Somewhere else, remaining off @ nearest Server")
  47.         rednet.send(pocketID, "running")
  48.         rednet.send(pocketID2, "running")
  49.  
  50.     -- If the Server is running the AutoMode it'll turn it on
  51.     else if bool then
  52.         print("AutoMode now Online!")
  53.         delColor(autoModeColor, defaultSide)
  54.         addColor(autoModeCheckColor2, defaultSide)
  55.         rednet.send(pocketID, true)
  56.         rednet.send(pocketID2, true)
  57.  
  58.     -- Or Else it'll turn AutoMode off.
  59.     else
  60.         addColor(autoModeColor, defaultSide)
  61.         delColor(autoModeCheckColor2, defaultSide)
  62.         print("AutoMode now Offline!")
  63.         rednet.send(pocketID, false)
  64.         rednet.send(pocketID2, false)
  65.    
  66.            
  67.     end
  68.     end
  69. end
  70.  
  71.  -- Edit's the startup to boot up on this pastebin
  72.  function startupClear()
  73.                 f = fs.open("startup", "w")
  74.                 f.write("shell.run('pastebin run J1ErE7pj')")
  75.                 f.close()
  76.                 end
  77.  
  78.     --Asks and saves where the bundled cable is locatated
  79.     function redstoneVar()
  80.         print("Where will the redstone output be? [left,right,bottom,top]")
  81.         command = read()
  82.         if command == "left" or command == "right" or command == "bottom" or command == "top" then
  83.             print("Redstone set to "..command.." side")
  84.             f = fs.open("redstoneVar", "w")
  85.             f.writeLine(command)
  86.             f.close()
  87.             os.reboot()
  88.         else
  89.             term.setTextColor(colors.red)
  90.             print("Invalid Input")
  91.             sleep(1)
  92.             redstoneVar()
  93.     end
  94.     end
  95.  
  96.     -- Asks and saves where the modem is located
  97.     function modemVars()
  98.             print("Where's the Modem? , [left,right,bottom,top]")
  99.             command = read()
  100.             if command == "left" or command == "right" or command == "bottom" or command == "top" then
  101.                 print("Modem set to "..command.." side")
  102.                 r = fs.open("modemVar", "w")
  103.                 r.writeLine(tostring(command))
  104.                 r.close()
  105.                 redstoneVar()
  106.         else
  107.             term.setTextColor(colors.red)
  108.             print("Invalid Input")
  109.             modemVar()
  110.     end
  111. end
  112.  
  113. -- Checks if a file containing where the modem exists, and where the bundled redstone side is, if not
  114. -- Then it asks the user where they want it to be and saves it to modemVar and redstoneVar
  115.  function startupVars()
  116.     if fs.exists("modemVar") == false then
  117.         modemVars()
  118.     else
  119.     -- If they have already been configured than it loads the configs,
  120.     -- and Prints the current configs to the screen.
  121.         f = fs.open("modemVar", "r")
  122.         sideM = f.readLine()
  123.         rednet.open(sideM)
  124.  
  125.         f1 = fs.open("redstoneVar", "r")
  126.         defaultSide = f1.readLine()
  127.         f1.close()
  128.         term.setTextColor(colors.cyan)
  129.         print("Loaded with configuration :")
  130.         term.setTextColor(colors.red)
  131.         print("Redstone Side : "..defaultSide)
  132.         term.setTextColor(colors.gray)
  133.         print("Wireless Modem Side : "..sideM)
  134.         term.setTextColor(colors.blue)
  135. end
  136. end
  137.  
  138. -- Checks if a specific color in bundled cable is on or off / Returns a boolean
  139. function checkColor(color, side)
  140.     boolean = rs.testBundledInput(side, color)
  141.     --print("CheckColor : "..side.." - Side Color - "..color.." Bool -"..tostring(boolean))
  142. return boolean
  143. end
  144.  
  145. -- Check's if Kilo's UberMiner is on.
  146. function checkCancel() 
  147.     bool = checkColor(autoModeCheckColor, defaultSide)
  148.     bool2 = checkColor(autoModeColor, defaultSide)
  149.     if bool == true and bool2 == false then
  150.     autoMode()
  151. end
  152. end
  153.  
  154. addColor(autoModeColor, defaultSide)
  155. startupClear()
  156. startupVars()
  157.  
  158. -- Checks if a rednet message was received.
  159. function rednetReceive()
  160. senderID, message = rednet.receive()
  161.    if senderID == pocketID1  or senderID == pocketID2 then
  162.  
  163.        if message == "wither" then
  164.             redstonePulse(witherColor, defaultSide)
  165.  
  166.        else if message == "autoMode" then
  167.         autoMode()
  168.  
  169.        else if message == "forward" then
  170.             redstonePulse(forwardColor, defaultSide)  
  171.    
  172.        else if message == "forceshut" then
  173.         rs.setBundledOutput(defaultSide, 0)
  174.         os.reboot()
  175.        
  176. end
  177. end
  178. end
  179. end
  180. end
  181. end
  182.  
  183. while true do
  184. rednetReceive()
  185. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement