Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- modem = peripheral.wrap("right")
- sg = peripheral.wrap("stargate_0") --change this to a side of your computer or the adress of the interface of your network
- -- stargate_0 is the default name and will probably work if you have never used a Stargate Computer Interface in a CC wired network
- buttons = {
- {text = "Test", sg="zfqq-uei-pe"}, --change the adresses to your destinations
- {text = " ", sg=" "},
- {text = " ", sg=" "}, -- you can add a lot more
- {text = "CLOSE STARGATE", action=true} -- you probably want this one down
- }
- function writeButtons(_table)
- ycount = 2
- for i,v in pairs(_table) do
- term.setCursorPos(1, ycount)
- term.write(" * ".. v.text) -- nice list style
- v.y = ycount --adds buttons height to the main table
- ycount = ycount + 1
- end
- end
- function isValidClick(_table, mx, my)
- for i, v in pairs(_table) do
- if mx >= 1 and mx <= (3 + #v.text) and my == v.y then -- checks if you clicked on the text
- return true, v.text, v.y
- end
- end
- return false, nil
- end
- function init()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Choose destination :")
- writeButtons(buttons)
- end
- function Dial(address,dy)
- init()
- term.setCursorPos(2,ycount)
- if(sg.stargateState() == "Connected" or sg.stargateState() == "Dialling") then
- --you can change your mind without waiting for the stargate to dial and closing it
- sg.disconnect()
- term.write("Closing")
- sleep(1)
- end
- term.setCursorPos(1,dy)
- term.write("-->") --little indicator so you know when the stargate leads to if you left it open
- term.setCursorPos(2,ycount)
- term.write("Dialing stargate!") --I failed to add something else after, no idea why
- sg.dial(address)
- modem.transmit(0, 0,address)
- sleep(15)
- sg.openIris()
- sleep(15)
- sg.disconnect()
- sg.closeIris()
- end
- init()
- sg.disconnect()
- while true do
- _, but, x, y = os.pullEvent("mouse_click")
- bClick, dest = isValidClick(buttons, x, y)
- if bClick then
- for k,v in pairs(buttons) do
- if(dest == v.text and #v.sg > 5) then
- Dial(v.sg, v.y)
- elseif v.action and sg.stargateState() == "Connected" then -- when you press "CLOSE"
- sg.disconnect()
- init() --restores the UI to initial state
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement