Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chanel = 104 --Chanel of this teleporter
- chest = peripheral.wrap("bottom")
- modem = peripheral.wrap("right")
- modem.open(chanel)
- target = {
- chanel = nil,
- timeout = 0,
- locked = false
- }
- targetTimeoutDelay = 100
- targets = {
- {101,"test 1"},
- {102,"test 2"},
- {103,"test 3"}
- }
- monitors = {}
- scale = 0.5
- function redstone.pulse(side, delay, pulse)
- delay, pulse = delay or 0.1, pulse or true
- redstone.setOutput(side, pulse)
- sleep(delay)
- redstone.setOutput(side, not pulse)
- end
- function activate()
- print("Pushing Disk")
- chest.pushItems("top",1)
- sleep(1)
- print("Activating Spacial IO")
- redstone.pulse("back",0.2,true)
- waitForDisk()
- print("Done")
- drawScreens()
- end
- function waitForDisk()
- print("Waiting for Disk")
- while not chest.getItemDetail(1) do
- sleep(0.2)
- end
- print("Disk Recieved")
- end
- function touchscreen(x,y)
- end
- function selectTarget(x,y)
- for i,v in ipairs(targets) do
- if y == i+1 then
- return v[1]
- end
- end
- return nil
- end
- function requestTarget(n)
- target.chanel = n
- target.timeout = targetTimeoutDelay
- print("Pinging target")
- modem.transmit(target.chanel,chanel,"PING")
- end
- function timeoutTarget()
- target.timeout = 0
- target.chanel = nil
- target.locked = false
- end
- function handleMessage(message, reply)
- if message == "activate" then
- print("Remote activation requested")
- activate()
- modem.transmit(reply,chanel,"activated")
- print("Confirmation sent")
- elseif message == "activated" then
- print("Confirmation recieved")
- print("Transfering target here")
- activate()
- target.chanel = nil
- elseif message == "PING" then
- print("Remote request incoming, answering")
- modem.transmit(reply,chanel,"PONG")
- elseif message == "PONG" then
- print("Target answered")
- if reply == target.chanel then
- target.locked = true
- target.timeout = 0
- activate()
- sendTarget()
- end
- end
- end
- function sendTarget()
- print("Sending remote activation request")
- modem.transmit(target.chanel,chanel,"activate")
- target.locked = false
- target.timeout = targetTimeoutDelay
- end
- function writeText(monitor, text,y,align,margin,padding)
- text = text or ""
- y = y or 1
- align = align or "left"
- margin = margin or 0
- padding = padding or 0
- local x = margin
- if align == "center" then
- --text = (string.len(text)%2 == 0) and text or text.." "
- text = padText(text,padding,padding," ")
- x = monitor.size.x/2-(string.len(text)/2-1)
- elseif align == "right" then
- text = padText(text,0,padding," ")
- x = monitor.size.x-(string.len(text)-1)-margin
- else
- text = padText(text,padding,0," ")
- end
- monitor.setCursorPos(x,y)
- monitor.write(text)
- end
- function padText(text,left,right,char)
- left,right,char = left or 0,right or 0,char or " "
- return string.rep(char,left)..text..string.rep(char,right)
- end
- function setColors(monitor, fg, bg)
- fg,bg = fg or colors.white,bg or colors.black
- monitor.setTextColor(fg)
- monitor.setBackgroundColour(bg)
- end
- function setupMonitors()
- print("Setting up Monitors")
- monitors = {}
- for i,v in ipairs(peripheral.getNames()) do
- if string.sub(v,1,7) == "monitor" then
- local monitor = peripheral.wrap(v)
- setColors(monitor)
- monitor.clear()
- monitor.setCursorBlink(false)
- monitor.setTextScale(scale)
- table.insert(monitors,monitor)
- monitor.size = {}
- monitor.size.x,
- monitor.size.y = monitor.getSize()
- print(monitor.size.x,monitor.size.y)
- end
- end
- drawScreens()
- end
- function drawScreens()
- for i,monitor in ipairs(monitors) do
- drawScreen(monitor)
- end
- end
- function drawScreen(monitor)
- if target.chanel then
- setColors(monitor)
- monitor.clear()
- elseif target.locked then
- setColors(monitor)
- monitor.clear()
- else
- setColors(monitor,colors.red,colors.gray)
- writeText(monitor, "Destination",1,"center",0,1)
- end
- end
- do --First Time Setup
- setupMonitors()
- end
- while true do
- local eventData = {os.pullEvent()}
- local event = eventData[1]
- if event ~= "key" and event ~= "key_up" then
- print(table.unpack(eventData))
- end
- if event == "modem_message" then
- local event, side, channel, reply, message, distance = table.unpack(eventData)
- print(message)
- handleMessage(message, reply)
- elseif target.chanel and not target.locked then
- target.timeout = target.timeout-1
- if target.timeout <= 0 then
- timeoutTarget()
- end
- elseif event == "monitor_touch" then
- activate()
- elseif event == "peripheral" or
- event == "peripheral_detach" or
- event == "monitor_resize" then
- setupMonitors()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement