Advertisement
Tommo5261

RAVServer

May 19th, 2020
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. rednet.open("front")
  2.  
  3. textutils.slowPrint("Loading system diagnostics..")
  4. sleep(1.5)
  5. textutils.slowPrint("Welcome to the RA-v Network")
  6. sleep(1)
  7.  
  8. function callData()
  9.     rednet.send(35, "call.data") -- Reactor
  10.     rID1,rMessage1 = rednet.receive()
  11.     rednet.send(73, "call.data") -- Reactor 2
  12.     rID2,rMessage2 = rednet.receive()
  13.     rednet.send(36, "call.data") -- ME System
  14.     meID,meMessage = rednet.receive()
  15. end
  16.  
  17. function calculateData()
  18.     function calculateReactor(id,message)
  19.         local data = textutils.unserialise(message)
  20.         local heat = data[1]
  21.         local output = data[2]
  22.         local status = data[3]
  23.  
  24.         local dHeat = tostring(math.floor((heat/10000)*100))
  25.         local table = {dHeat,output,status}
  26.         local data2 = textutils.serialise(table)
  27.         return data2
  28.     end
  29.  
  30.     rData1 = calculateReactor(rID1,rMessage1)
  31.     rData2 = calculateReactor(rID2,rMessage2)
  32.  
  33. end
  34.  
  35. function interfaceAction() -- will have the response and actions interfaces
  36.     function interfaceResponse(id, message)
  37.         if message == "Shutdown Reactors" then
  38.             rednet.send(id,"success")
  39.             -- add actons
  40.         elseif message == "Reboot system" then
  41.             rednet.send(id,"success")
  42.         else
  43.             rednet.send(id,"failure")
  44.         end
  45.  
  46.     end
  47.  
  48.     interfaceArray = {}
  49.     rednet.send(41,"call.interface")
  50.     local id,message = rednet.receive(1)
  51.     interfaceArray[id] = textutils.unserialise(message)
  52.  
  53.     rednet.send(42,"call.interface")
  54.     local id,message = rednet.receive(1)
  55.     interfaceArray[id] = textutils.unserialise(message)
  56.  
  57.     for i, m in pairs(interfaceArray) do
  58.         interfaceResponse(i, m)
  59.     end
  60. end
  61.  
  62. function sendData() -- Sending data to monitors, receivers
  63.     rPackage = {rData1,rData2}
  64.  
  65.     rednet.send(40,rPackage) -- Change 40 to monitor id
  66.     rednet.send(41,meMessage)
  67. end
  68.  
  69. while true do
  70.     callData()
  71.     calculateData()
  72.     sendData()
  73.  
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement