Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function wrap(name,w)
- for k,v in pairs(peripheral.getNames()) do
- if peripheral.getType(v)==name then
- if w=="wireless" then
- if peripheral.call(v,"isWireless") then
- return peripheral.wrap(v)
- end
- else
- return peripheral.wrap(v)
- end
- end
- end
- end
- local server=...~="client"
- local ioc=wrap("tilespatialioport")
- local m=wrap("monitor")
- m.setTextScale(0.9)
- local modem=wrap("modem","wireless")
- modem.open(13005)
- local conf={
- s={
- "left",
- "bottom",
- "right",
- },
- n={
- "main",
- "wiiplay",
- "lur",
- },
- }
- local function materialize()
- rs.setOutput("front",true)
- sleep(0.2)
- rs.setOutput("front",false)
- end
- local function update()
- local i=ioc.getStackInSlot(2)
- if i then
- return ioc.swapStacks(1,2)
- else
- return true
- end
- end
- local function tp(a,b)
- if not server then
- modem.transmit(13005,a,tostring(b))
- else
- update()
- rs.setOutput(conf.s[a],true)
- sleep(0.2)
- materialize()
- if not update() then
- error("failed to dematerialize")
- end
- rs.setOutput(conf.s[a],false)
- sleep(0.2)
- rs.setOutput(conf.s[b],true)
- sleep(0.2)
- materialize()
- rs.setOutput(conf.s[b],false)
- if not update() then
- error("failed to materialize")
- end
- end
- end
- local Mx,My=m.getSize()
- local Cx,Cy=math.ceil(Mx/2),math.ceil(My/2)
- local function rMain()
- m.setBackgroundColor(colors.gray)
- m.clear()
- m.setBackgroundColor(colors.lightBlue)
- m.setCursorPos(1,1)
- m.clearLine()
- m.setCursorPos(1,2)
- m.clearLine()
- m.setCursorPos(1,3)
- m.clearLine()
- m.setCursorPos(Cx-9,2)
- m.setTextColor(colors.black)
- m.write("teleporter control")
- end
- local pPos={}
- local sel1,sel2=0,0
- local function rPorts()
- local cnt=#conf.n
- local mul=Mx/(cnt+1)
- m.setTextColor(colors.white)
- for l1=1,cnt do
- local s=mul*l1
- local x=math.floor(s-2)
- pPos[l1]=x
- m.setCursorPos((x+3)-math.floor(#conf.n[l1]/2),4)
- m.setBackgroundColor(colors.gray)
- m.write(conf.n[l1])
- for l2=-2,1 do
- if sel1==l1 then
- m.setBackgroundColor(colors.lightBlue)
- else
- m.setBackgroundColor(colors.red)
- end
- m.setCursorPos(x,8+l2)
- m.write((" "):rep(5))
- if sel1~=0 then
- if sel1==l1 then
- m.setBackgroundColor(colors.gray)
- elseif sel2==l1 then
- m.setBackgroundColor(colors.lightBlue)
- else
- m.setBackgroundColor(colors.red)
- end
- m.setCursorPos(x,16+l2)
- m.write((" "):rep(5))
- end
- end
- end
- if sel2~=0 then
- m.setBackgroundColor(colors.green)
- else
- m.setBackgroundColor(colors.lightGray)
- end
- for l1=21,23 do
- local s=pPos[1]
- m.setCursorPos(s,l1)
- m.write((" "):rep((pPos[#pPos]-s)+5))
- end
- m.setTextColor(colors.black)
- m.setCursorPos(Cx-4,22)
- m.write("teleport")
- end
- rMain()
- rPorts()
- while true do
- local p={os.pullEvent()}
- if p[1]=="monitor_touch" then
- for l1=1,#conf.n do
- if p[4]>5 and p[4]<10 and p[3]>pPos[l1]-1 and p[3]<pPos[l1]+6 then
- sel1=l1
- if sel1==sel2 then
- sel2=0
- end
- rPorts()
- elseif p[4]>13 and p[4]<18 and p[3]>pPos[l1]-1 and p[3]<pPos[l1]+6 and l1~=sel1 then
- sel2=l1
- rPorts()
- end
- end
- if sel2~=0 and p[4]>20 and p[4]<24 and
- p[3]>pPos[1]-1 and
- p[3]<(pPos[#pPos]-pPos[1])+6 then
- m.setBackgroundColor(colors.gray)
- m.clear()
- tp(sel1,sel2)
- rMain()
- rPorts()
- end
- elseif server and p[1]=="modem_message" and p[3]==13005 then
- tp(p[4],tonumber(p[5]))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement