Advertisement
Guest User

Server

a guest
Apr 9th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. function rednetOpen()
  2.     for _,v in pairs( rs.getSides() ) do
  3.       if peripheral.getType( v ) == "modem" then
  4.             rednet.open( v )
  5.       end
  6.     end
  7. end
  8.  
  9. function clear()
  10.   term.setBackgroundColor(colors.black)
  11.   term.clear()
  12.   term.setCursorPos(1, 1)
  13. end
  14.  
  15. function draw()
  16.   print("Turtle Worldeater Server")
  17.   print("")
  18.   print("1 Mining")
  19.   print("")
  20.   print("2 exit")
  21. end
  22.  
  23. function DrawWaiting() 
  24.     print("Gebe eine Zahl ein")
  25.     print("")
  26.     print("Verbunden sind insgesammt: "..count-1)
  27. end
  28.  
  29. function receive()
  30.     message = nil
  31.     id, message = rednet.receive()
  32.     if (message == "turtle") or not (message == nil) then
  33.         Arr_ID[count] = id
  34.         count = count + 1
  35.     end
  36. end
  37.  
  38. function commands()
  39.     i = io.read()
  40.     for j = 1, count do
  41.         if not (Arr_ID[j] == nil) then
  42.             rednet.send(tonumber(Arr_ID[j]), i)
  43.             print("ID: "..Arr_ID[j])
  44.         end
  45.     end
  46.     print("Es wurden ", count-1," Nachrichten gesendet!")
  47.     sleep(1)
  48. end
  49.  
  50. function Mining()
  51.     while true do
  52.         clear()
  53.         DrawWaiting()
  54.         parallel.waitForAny(receive, commands)
  55.         print("Pupsen")
  56.     end
  57. end
  58.  
  59. function input()
  60.   local i = io.read()
  61.   if i == "1" then
  62.     Mining()
  63.     return true
  64.   elseif i == "2" then
  65.     return false
  66.   end
  67.   print("Gib was gueltiges ein!")
  68.   sleep(1)
  69.   return true
  70. end
  71.  
  72. function loop()
  73.   while true do
  74.     clear()
  75.     draw()
  76.     if not input() then break end
  77.   end
  78.   clear()
  79. end
  80.  
  81. Arr_ID = {}
  82. count = 1
  83. rednetOpen()
  84. loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement