Advertisement
soulgriever

Tesla Turtle

Dec 20th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. --Turtle Teslas
  2. version = "0.9.3"
  3.  
  4. --Load peripherals
  5. sensor = peripheral.wrap("right")
  6. modem = peripheral.wrap("left")
  7.  
  8. --Initilaze
  9. local armed = "on"
  10. for i = 1, 64 do
  11.  modem.open(i)
  12. end
  13.  
  14. --Functions
  15. function scan()
  16.  mob = sensor.getEntityIds("mob")
  17.  player = sensor.getPlayers()
  18.  status = {}
  19.  status[0] = os.getComputerLabel()
  20.  status[1] = armed
  21.  status[2] = #player
  22.  status[3] = #mob
  23. end
  24.  
  25. function transmit()
  26.  term.clear()
  27.  term.setCursorPos(1,1)
  28.  print("Version: "..version)
  29.  term.write("Status: ")
  30.  print(armed)
  31.  term.write("Players: ")
  32.  print(#player)
  33.  term.write("Entities: ")
  34.  print(#mob)
  35.  modem.transmit(2, 1, textutils.serialize(status))
  36. end
  37.  
  38. function receive()
  39.  local event, side, rec, reply, message, distance = os.pullEvent("modem_message")
  40.  
  41.  if message == "teslaOn" then
  42.   scan()
  43.   armed = "on"
  44.   transmit()
  45.  end
  46.  if message == "teslaOff" then
  47.   scan()
  48.   armed = "off"
  49.   transmit()
  50.  end
  51.  if message == "update" then
  52.   os.reboot()
  53.  end
  54. end
  55.  
  56. function trigger()
  57.  scan()
  58.  transmit()
  59.  if armed == "on" then
  60.   if #player == 0 then
  61.    if #mob > 0 then
  62.     redstone.setAnalogOutput("bottom", 9)
  63.    end
  64.    if #mob == 0 then
  65.     redstone.setAnalogOutput("bottom", 0)
  66.    end
  67.   end
  68.   if #player > 0 then
  69.    redstone.setAnalogOutput("bottom", 0)
  70.   end
  71.  end
  72.  sleep(3)
  73. end
  74.  
  75.  
  76.  
  77. --Start Loop
  78. while true do
  79. parallel.waitForAny(receive, trigger)
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement