DrFair

FairPad Door

May 4th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. doorName = "ThaumcraftDoor"
  2. updateTime = 5
  3. rSide = "back"
  4. rednet.open("top")
  5.  
  6. local Args = {...}
  7. if Args[1] == "update" then
  8. programName = shell.getRunningProgram()
  9. print("Updating.")
  10. fs.delete( programName )
  11. shell.run( "pastebin","get", "qMH0ZHZC", programName )
  12. print("Finished updating.")
  13. error()
  14. end
  15.  
  16. print("Hosting as "..doorName)
  17. if active == nil then active = true end
  18. print("Active: "..tostring(active))
  19. pos = vector.new(gps.locate(5))
  20. if pos == nil then print("Could not find position") else print("Position is "..tostring(pos)) end
  21. timer = os.startTimer( updateTime )
  22.  
  23. function update()
  24. rs.setOutput( rSide, active )
  25. end
  26.  
  27. update()
  28.  
  29. while true do
  30. event,pr1,pr2 = os.pullEvent()
  31. if event == "timer" and pr1 == timer then
  32. data = {}
  33. data["getActive"] = active
  34. data["getPosition"] = pos
  35. txtData = textutils.serialize( { [1] = "door", [2] = doorName, [3] = textutils.serialize( data ) } )
  36. rednet.broadcast( txtData )
  37. timer = os.startTimer( updateTime - 0.05 )
  38. update()
  39. elseif event == "rednet_message" then
  40. if textutils.unserialize(pr2)[1] == doorName then
  41. data = textutils.unserialize(pr2)
  42. if data[2] == "setActive" then
  43. active = data[3]
  44. if active then
  45. print("Active: true")
  46. else
  47. print("Active: false")
  48. end
  49. update()
  50. elseif data[2] == "toggle" then
  51. active = not active
  52. if active then
  53. print("Active: true")
  54. else
  55. print("Active: false")
  56. end
  57. update()
  58. end
  59. end
  60. end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment