infiniteblock

Untitled

Jun 19th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local uri = ""
  2. local sides = peripheral.getNames()
  3. local shipcores = {}
  4. for _, side in pairs(sides) do
  5.     if peripheral.getType(side) == "warpdriveShipController" then
  6.         print("Wrapping " .. side)
  7.         table.insert(shipcores, peripheral.wrap(side))
  8.     elseif peripheral.getType(side) == "modem" then
  9.         rednet.open(side)
  10.     end
  11. end
  12. while true do
  13.     for _, shipcore in pairs(shipcores) do
  14.         local name = shipcore.name()
  15.         file = name:gsub(" ","")
  16.         local shipdim = shipcore.isInHyperspace() and "Hyperspace"or"Space/Planet"
  17.         timeout = 10
  18.         repeat
  19.             local pos
  20.             pos = shipcore.getLocalPosition()
  21.             local x, y, z
  22.             x, y, z = shipcore.getLocalPosition()
  23.             sleep(0.05)
  24.             timeout = timeout - 1
  25.         until pos ~= nil or timeout < 0
  26.         if timeout < 0 then
  27.             print(name.." Position Error")
  28.         else
  29.             text = x.." "..y.." "..z
  30.             oldText = ""
  31.             local mass = shipcore.getShipSize()
  32.             local energyStored, energyMax, energyUnits = shipcore.getEnergyStatus()
  33.             if fs.exists("disk/ships/"..file) then
  34.                 local f = fs.open("disk/ships/"..file,"r")
  35.                 oldText = f.readAll()
  36.                 f.close()
  37.             end
  38.             if string.find(oldText, text) then
  39.                 print(name.." No Movement")
  40.             else
  41.                 stt = "disk/ships/"..file
  42.                 local f2 = fs.open(stt,"w")
  43.                 f2.write("Shipname: "..name.."\n")
  44.                 if energyMax <= 2057142 then core = "Shuttle" elseif energyMax <= 41142857 then core = "Corvette" else core = "Frigate"
  45.                 end
  46.                 f2.write("Type: "..core.."\n")
  47.                 f2.write("Dimension: "..shipdim.."\n")
  48.                 f2.write("Location: "..pos.."\n")
  49.                 f2.write("Energy: "..energyStored.." "..energyUnits.."\n")
  50.                 f2.write("Tons: "..mass.."\n")
  51.                 print(name.." Movment Detected")
  52.                 http.post(uri,"{\"content\":\"```yaml\\nShipname: "..name.." \\nType: "..core.." \\nDimension: "..shipdim.." \\nLocation: "..text.."\\nEnergy: "..energyStored.." "..energyUnits.."\\nTons: "..mass.."```\"}",{['content-type']="application/json"})
  53.                 output ="\1672".."CoreNET: ".."\1674".."Movement Detected.\nShipname: "..name.." \nType: "..core.." \nDimension: "..shipdim.." \nLocation: "..text.."\nEnergy: "..energyStored.." "..energyUnits.."\nTons: "..mass
  54.                 rednet.broadcast(output)
  55.                 f2.close()
  56.             end
  57.         end
  58.         sleep(5)
  59.     end
  60. end
  61. os.reboot()
Add Comment
Please, Sign In to add comment