AR2000

OpenComputers Stargate

Jul 5th, 2016 (edited)
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. component=require("component")
  2. term=require("term")
  3. io=require("io")
  4.  
  5. local function irisChange(iris_state)
  6.   if iris_state == "Open" then
  7.     component.stargate.closeIris()
  8.   else
  9.     component.stargate.openIris()
  10.   end
  11. end
  12.  
  13. names={}
  14. name = io.open("/usr/name.txt")
  15. i = 1
  16. namet =" "
  17. while namet ~= nill do
  18.   namet = name:read()
  19.   if namet ~= nill then
  20.     table.insert(names,namet)
  21.     i = i+1
  22.   end
  23. end
  24.  
  25. addr={}
  26. add = io.open("/usr/add.txt")
  27. i = 1
  28. addt =" "
  29. while addt ~= nill do
  30.   addt = add:read()
  31.   if addt ~= nill then
  32.     table.insert(addr,addt)
  33.     i = i+1
  34.   end
  35. end
  36. i_max =tostring(i-1)
  37.  
  38. on = "on"
  39.  
  40. while on == "on" do
  41.  
  42.   term.clear()
  43.  
  44.   sta = component.stargate.address
  45.   loc = component.stargate.localAddress()
  46.   iris = component.stargate.irisState()
  47.   state = component.stargate.stargateState()
  48.  
  49.   energie = component.stargate.energyAvailable()
  50.   energie_max = 24576000
  51.   if energie ~= 0 then
  52.     energie_p = energie / energie_max * 100
  53.   end
  54.  
  55.   print("========================")
  56.   print("Adresse locale : ",loc)
  57.   print("Iris : ",iris)
  58.   print("Etat : ",state)
  59.   print("Energie : ",math.floor(energie_p),"%")
  60.   print("========================")
  61.  
  62.   if state == "Idle" then
  63.     for i = 1,i_max do
  64.       print(i,names[i])
  65.     end
  66.     print("=====================")
  67.     print("iris")
  68.     print("manual")
  69.     print("help")
  70.     print("exit")
  71.     print("=======================")
  72.     input = io.read()
  73.  
  74.     if input == "exit" then
  75.       on = "off"
  76.     end
  77.  
  78.     if input>="1" and input<=i_max  then
  79.       component.stargate.dial(addr[tonumber(input)])
  80.     end
  81.  
  82.     if input == "iris" then
  83.       irisChange(iris)
  84.     end
  85.  
  86.     if input == "manual" then
  87.       print("Adresse ? :")
  88.       addresse = io.read()
  89.       component.stargate.dial(addresse)
  90.     end
  91.  
  92.     if input == "help" then
  93.       print("Coming soon")
  94.     end
  95.   end
  96.  
  97.   if state == "Dialling" or state == "Connected" or state == "Opening" then
  98.     print("Connected to : ",component.stargate.remoteAddress())
  99.     print("=====================")
  100.     print("disconnect")
  101.     print("iris")
  102.     print("=====================")
  103.     input = io.read()
  104.  
  105.     if input == "disconnect" then
  106.       component.stargate.disconnect()
  107.     end
  108.  
  109.     if input == "iris" then
  110.       irisChange(iris)
  111.     end
  112.   end
  113. end
Add Comment
Please, Sign In to add comment