Wiiplay123

Teleporter v2.0

Jan 13th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. -- Teleporter v2.0
  2. if (fs.exists("tp_settings") ~= true) then
  3.   local f = fs.open("tp_settings","w")
  4.   f.write([[local modem = "top"
  5. local port = "tilespatialioport_4"
  6. local chest = "right"
  7. local pipe = "bottom"
  8. local rtele = "front"
  9. local rdir = "south"
  10. return modem, port, chest, pipe, rtele, rdir]])
  11.   f.close()
  12.   error("Settings not setup.",0)
  13. else
  14.   local f = fs.open("tp_settings","r")
  15.   local f2 = f.readAll()
  16.   f.close()
  17.   modem, port, chest, pipe, rtele, rdir = loadstring(f2)()
  18. end
  19. rednet.open(modem)
  20. function pulse(side)
  21.   sleep(0.5)
  22.   rs.setOutput(side,true)
  23.   sleep(0.5)
  24.   rs.setOutput(side,false)
  25.   sleep(0.5)
  26. end
  27. while true do
  28.   term.clear()
  29.   term.setCursorPos(1,1)
  30.   print("Wii's Teleship Port v2.0")
  31.   print("ID: "..os.getComputerID())
  32.   print("Press any key to bring up teleport prompt.")
  33.   local event, idd, msg = os.pullEvent()
  34.   if (event == "key") then
  35.     --print("Teleporter v2.0")
  36.     write("Countdown: ")
  37.     count = tonumber(read())
  38.     repeat
  39.       write("Storage device slot: ")
  40.       slot = tonumber(read())
  41.     until peripheral.call(chest,"getStackInSlot",slot) ~= nil
  42.     write("(0 for same) Teleporter ID: ")
  43.     id = tonumber(read())
  44.     write("(0 for infinite) Teleport time: ")
  45.     time = tonumber(read())
  46.     for i = count, 1, -1 do
  47.       print(i.."...")
  48.       sleep(1)
  49.     end
  50.     peripheral.call(port,"pullItemIntoSlot",rdir,slot,1,1)
  51.     sleep(0.2)
  52.     pulse(rtele)
  53.     --peripheral.call(port,"swapStacks",1,2)
  54.     if (time > 0) then
  55.       for i = time, 1, -1 do
  56.         print(i.."...")
  57.         sleep(1)
  58.       end
  59.       peripheral.call(port,"swapStacks",1,2)
  60.       sleep(0.2)
  61.       pulse(rtele)
  62.       sleep(0.2)
  63.       pulse(pipe)
  64.       repeat
  65.         sleep(0.2)
  66.       until peripheral.call(chest,"getStackInSlot",slot) ~= nil
  67.       if (id > 0) then
  68.         rednet.send(id,"tp"..slot)
  69.         ia, msg = rednet.receive(3)
  70.         print(msg)
  71.         sleep(2)
  72.         if (msg ~= "ready") then
  73.           peripheral.call(port,"pullItemIntoSlot",rdir,slot,1,1)
  74.           --port.swapStack(1,2)
  75.           sleep(0.1)
  76.           pulse(rtele)
  77.           sleep(0.2)
  78.           pulse(pipe)
  79.         end
  80.       end
  81.     else
  82.       sleep(0.5)
  83.       pulse(pipe)
  84.     end
  85.   elseif (event == "rednet_message") then
  86.     --event,idd,msg
  87.     if (string.sub(msg,1,2) == "tp") then
  88.       local thing = tonumber(string.sub(msg,3))
  89.       rednet.send(idd,"ready")
  90.       repeat
  91.         sleep(0.1)
  92.       until peripheral.call(chest,"getStackInSlot",thing) ~= nil
  93.       peripheral.call(port,"pullItemIntoSlot",rdir,thing,1,1)
  94.       sleep(0.5)
  95.       pulse(rtele)
  96.       sleep(0.5)
  97.       pulse(pipe)
  98.       sleep(0.5)
  99.     end
  100.   end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment