Advertisement
Axeer

minecraft_universal_library

Aug 12th, 2020 (edited)
2,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. LibraryOptions = {}
  2. Control = {}
  3. local component = require "component"
  4. local modem = component.modem
  5. local serialization = require"serialization"
  6. local thread = require"thread"
  7. local computer = require"computer"
  8. local filesystem = require"filesystem"
  9. local event = require "event"
  10. function sendFileToServer(dataString, pathToSave)
  11.  local filePath,dataString = read(file)
  12. modem.send(variableCurrentAddress, port, "receiveFile")--begin
  13. modem.send(variableCurrentAddress, port, pathToSave) --path
  14. os.sleep(0.5)
  15. modem.send(variableCurrentAddress, port, dataString) --data
  16. end
  17.  
  18. function connect()
  19.     addresses = {}
  20.     local addressesCount = 1
  21.     modem.broadcast(port, "connect")
  22.     for i = 0, 10,1 do
  23.         local _, _, from, _, _, _ = event.pull(1, "modem_message") --pull with timeout of 1 second(listen for 10 times)
  24.    
  25.     if from ~= nil then
  26.     print(from)
  27.  
  28.     addresses[addressesCount] = from
  29.     print(addressesCount)
  30.     addressesCount = addressesCount+1
  31.     return addresses[1]
  32. else
  33.     break
  34.     print("nil address")
  35. end end end
  36.  
  37. function currentAddress()
  38.     local counter = 1
  39.         for addressesCount = 0, 10, 1 do
  40.             if addresses[addressesCount] ~=nil then
  41.     print(counter..'.'..addresses[addressesCount])
  42.     counter = counter +1
  43.             else
  44.     break end end
  45.     print ("choose address")
  46.     while true do
  47.      local e = {event.pull()}
  48.      if e[1] == "key_down" then
  49.             local currentPosition = tonumber((e[4]-1))
  50.          CA = addresses[currentPosition]
  51.         print(currentPosition)
  52.     if (CA ~= nil) then
  53.     print("your chose: "..currentPosition..'.'..CA)
  54.     break
  55.     else print("wrong position")
  56.     end end
  57. end
  58.     return CA
  59. end
  60.  
  61. function LibraryOptions.communicateWithServer()
  62.  
  63.     modem.send(variableCurrentAddress, port, (io.read()))
  64.     repeat
  65.     local _, _, from, port, _, message = event.pull("modem_message")
  66.     print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  67. until message == "end"
  68. print ("end of cicle")
  69. end
  70.  
  71. function chose(key)
  72. if key ~= nil then
  73. return Control[key]
  74.  
  75. end
  76.     end
  77.  
  78. function LibraryOptions.sendData(addr,port, data, opt, path,fileName)
  79.     if(not opt) then
  80.         modem.send(addr, port, data)
  81.     elseif(opt == "command") then
  82.         modem.send(addr, port, data)
  83.     elseif(opt == "file") then
  84.         modem.send(addr, port, path)
  85.         os.sleep(1)
  86.         modem.send(addr, port, fileName)
  87.         os.sleep(1)
  88.         modem.send(addr, port, data)
  89.     end
  90. end
  91.  
  92. function sendCommand(comname)
  93.  
  94.     modem.send(variableCurrentAddress, port, comname)
  95.  
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement