Advertisement
gbrnt

Command receiver

Nov 27th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. --Code for computer which receives destinations
  2. --It then outputs redstone on a certain side and activates a command block
  3.  
  4. receive_channel = 3
  5. display_transmit_channel = 4
  6. last_pressed = 0
  7.  
  8. -- Start modem
  9. local modem = peripheral.wrap("bottom")
  10. modem.open(receive_channel)
  11.  
  12. -- Wrap command block
  13. local commandBlock = peripheral.wrap("top")
  14.  
  15. function run_command(side)
  16.     if side == 1 then commandBlock.setCommand("tp @p[r=5] -1321 64 528")
  17.     elseif side == 2 then commandBlock.setCommand("tp @p[r=5] -123 64 53")
  18.     elseif side == 3 then commandBlock.setCommand("tp @p[r=5] -1493 63 644")
  19.     elseif side == 4 then commandBlock.setCommand("tp @p[r=5] -1497 63 640")
  20.     elseif side == 0 then print("No destination set")
  21.     else print("Side is wrong format! ", side)
  22.     end
  23.  
  24.     commandBlock.runCommand()
  25. end
  26.  
  27. function pressure_plate()
  28.     -- Wait for pressure plate input on front
  29.     -- Upon receiving it, send a redstone_pulse
  30.  
  31.     while redstone.getInput("left") == false do
  32.         sleep(0.1)
  33.     end
  34.     run_command(last_pressed)
  35.     print("tp to destination "..last_pressed)
  36. end
  37.  
  38. function modem_wait()
  39.     local event, modemSide, senderChannel, replyChannel,
  40.         message, senderDistance = os.pullEvent("modem_message")
  41.  
  42.     last_pressed = tonumber(message)
  43.     disp_print(last_pressed)
  44.     print(last_pressed)
  45. end
  46.  
  47. function disp_print(text)
  48.     modem.transmit(display_transmit_channel, 1, text)
  49. end
  50.  
  51. while true do
  52.     parallel.waitForAny(pressure_plate, modem_wait)
  53.     sleep(0.1)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement