Gazer29

comms

Mar 17th, 2021 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local component = require("component")
  2. local internet = require("internet")
  3. local term = require ("term")
  4. local json = require("json")
  5. local AllEntities = component.world_link.getLoadedEntities()
  6. local TcpIP = "84.65.32.30"
  7. local TcpSendPort = 6667
  8. local TcpRecvPort = 6667
  9. local wait = 0.1
  10.  
  11. local stocktypes = {
  12.     "immersiverailroading:locomotivediesel",
  13.     "immersiverailroading:locomotivesteam"
  14.     }
  15.  
  16. function overArray()
  17.     local b = {}
  18.     count = 0
  19.     for i0, typeX in pairs(stocktypes) do
  20.         AllofType = AllEntities.whereProperty("name", typeX).asList()
  21.         if AllofType ~= nil then
  22.             for i1, entity in pairs(AllofType) do
  23.                 rollingstock = entity.getAPI("immersiverailroading:locomotive")
  24.                 local posit_array = {}
  25.                 local a = {}
  26.                 uuid = rollingstock.getUUID()
  27.                 position = rollingstock.getLocation()
  28.                 xpos = position.getX()
  29.                 ypos = position.getY()
  30.                 zpos = position.getZ()
  31.                 speed = rollingstock.getCurrentSpeed()
  32.                 setspeed = 0 -- add later
  33.                 tag = "" -- add later
  34.                 c = {["x"] = xpos, ["y"] = ypos, ["z"] = zpos}
  35.                 a = {}
  36.                 a["uuid"] = uuid
  37.                 a["method"] = "Manual"
  38.                 a["speed"] = speed
  39.                 a["setspeed"] = setspeed
  40.                 a["posit_array"] = c
  41.                 a["name"] = rollingstock.getName()
  42.                 a["tag"] = "" --rollingstock.getTag()
  43.                 table.insert(b,1,a)
  44.                 end
  45.             end
  46.         end
  47.     data = json:encode(b)
  48.     if data ~= "" then
  49.         con:write("#01,"..data.."\r\n")
  50.         con:flush()
  51.         end
  52. end
  53.  
  54. -- Main loop --
  55.  
  56. con = internet.open(TcpIP,TcpSendPort)
  57.  
  58. while true do
  59.     if (con) then
  60.         overArray()
  61.         end
  62.     os.sleep(wait)
  63. end
Advertisement
Add Comment
Please, Sign In to add comment