Advertisement
Guest User

startup

a guest
Nov 19th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. term.clear()
  2. modem = peripheral.wrap("right")
  3. sg = peripheral.wrap("stargate_0") --change this to a side of your computer or the adress of the interface of your network
  4. -- stargate_0 is the default name and will probably work if you have never used a Stargate Computer Interface in a CC wired network
  5. buttons = {
  6.   {text = "Test", sg="zfqq-uei-pe"}, --change the adresses to your destinations
  7.   {text = " ", sg=" "},
  8.   {text = " ", sg=" "}, -- you can add a lot more
  9.   {text = "CLOSE STARGATE",  action=true} -- you probably want this one down
  10. }
  11. function writeButtons(_table)
  12. ycount = 2
  13.   for i,v in pairs(_table) do
  14.     term.setCursorPos(1, ycount)
  15.     term.write(" * ".. v.text) -- nice list style
  16.     v.y = ycount --adds buttons height to the main table
  17.     ycount = ycount + 1
  18.   end
  19. end
  20.  
  21. function isValidClick(_table, mx, my)
  22.     for i, v in pairs(_table) do
  23.         if mx >= 1 and mx <= (3 + #v.text) and my == v.y then -- checks if you clicked on the text
  24.              return true, v.text, v.y
  25.         end
  26.     end
  27.     return false, nil
  28. end
  29. function init()
  30.   term.clear()
  31.   term.setCursorPos(1,1)
  32.   term.write("Choose destination :")
  33.   writeButtons(buttons)
  34. end
  35.  
  36. function Dial(address,dy)
  37.  init()
  38.  term.setCursorPos(2,ycount)
  39.  if(sg.stargateState() == "Connected" or sg.stargateState() == "Dialling") then
  40. --you can change your mind without waiting for the stargate to dial and closing it
  41.   sg.disconnect()
  42.   term.write("Closing")
  43.   sleep(1)
  44.  end
  45.  term.setCursorPos(1,dy)
  46.  term.write("-->") --little indicator so you know when the stargate leads to if you left it open
  47.  term.setCursorPos(2,ycount)
  48.  term.write("Dialing stargate!") --I failed to add something else after, no idea why
  49.  sg.dial(address)
  50.  modem.transmit(0, 0,address)
  51.  sleep(15)
  52.  sg.openIris()
  53.  sleep(15)
  54.  sg.disconnect()
  55.  sg.closeIris()
  56. end
  57.  
  58. init()
  59. sg.disconnect()
  60. while true do
  61.     _, but, x, y = os.pullEvent("mouse_click")
  62.     bClick, dest = isValidClick(buttons, x, y)
  63.     if bClick then
  64.      for k,v in pairs(buttons) do
  65.       if(dest == v.text and #v.sg > 5) then
  66.        Dial(v.sg, v.y)
  67.       elseif v.action and sg.stargateState() == "Connected" then -- when you press "CLOSE"
  68.        sg.disconnect()
  69.        init() --restores the UI to initial state
  70.       end
  71.      end
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement