Advertisement
NanoBob

Spatial IO teleporter

May 20th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. local drive = 256
  2. local chest = peripheral.find("ender_chest")
  3. local spatialSide = "right"
  4. local spatial = peripheral.wrap(spatialSide)
  5. local chestPush = "east"
  6. local chestOpose = "west"
  7.  
  8. local selected = 1
  9. local destinations = {
  10.     {name="Ardron's room",frequency=258,},
  11.     {name="ME System",frequency=257,},
  12. }
  13.  
  14. local this = {name="Deep Dark Miner",frequency=259,}
  15.  
  16. if fs.exists("event")==false then
  17.        shell.run("pastebin get L7KYC10V event")
  18. end
  19. os.loadAPI("event")
  20.  
  21.  
  22. function storePlayer()
  23.     redstone.setOutput(spatialSide,true)
  24.     sleep(0.1)
  25.     redstone.setOutput(spatialSide,false)
  26.     spatial.pushItem(chestOpose,2,1,1)
  27. end
  28.  
  29. function loadPlayer()
  30.     setDestination(drive)
  31.     redstone.setOutput(spatialSide,true)
  32.     sleep(0.1)
  33.     redstone.setOutput(spatialSide,false)
  34.     spatial.pushItem(chestOpose,2,1,1)
  35.     setDestination(this.frequency)
  36. end
  37.  
  38. function getCell(frequency)
  39.     chest.setFrequency(frequency)
  40.     chest.pushItem(chestPush,1,1,1)
  41. end
  42.  
  43. function setDestination(frequency)
  44.     chest.setFrequency(frequency)
  45. end
  46.  
  47. function teleport(destination)
  48.     getCell(drive)
  49.     setDestination(destinations[destination].frequency)
  50.     storePlayer()
  51.     setDestination(this.frequency)
  52. end
  53.  
  54. function receiveTeleport()
  55.     getCell(this.frequency)
  56.     loadPlayer()
  57. end
  58.  
  59. function drawPositions()
  60.     term.clear()
  61.     for i,data  in ipairs(destinations) do
  62.         term.setCursorPos(4,i)
  63.         term.write(data.name)
  64.     end
  65. end
  66.  
  67. function drawSelection(old,new)
  68.     term.setCursorPos(2,old)
  69.     term.write(" ")
  70.     term.setCursorPos(2,new)
  71.     term.write(">")
  72. end
  73.  
  74. function onkey(key)
  75.     if key==200 then
  76.         --up
  77.         if selected>1 then
  78.             selected = selected - 1
  79.         end
  80.         drawSelection(selected + 1, selected)
  81.     elseif key==208 then
  82.         --down
  83.         if #destinations>selected then
  84.             selected = selected +1
  85.         end
  86.         drawSelection(selected - 1, selected)
  87.     elseif key==28 then
  88.         --enter
  89.         teleport(selected)
  90.     end
  91. end
  92. event.addHandler("key",onkey)
  93.  
  94. function checkPendingTeleports()
  95.     local item = chest.getStackInSlot(1)
  96.     if item==nil then return end
  97.     receiveTeleport()
  98. end
  99. event.addHandler("timer",checkPendingTeleports)
  100.  
  101. drawPositions()
  102. drawSelection(1,1)
  103. while true do
  104.     event.handleCCEvents(0.5)
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement