Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local internet = require("internet")
- local term = require ("term")
- local json = require("json")
- local AllEntities = component.world_link.getLoadedEntities()
- local TcpIP = "84.65.32.30"
- local TcpSendPort = 6667
- local TcpRecvPort = 6667
- local wait = 0.1
- local stocktypes = {
- "immersiverailroading:locomotivediesel",
- "immersiverailroading:locomotivesteam"
- }
- function overArray()
- local b = {}
- count = 0
- for i0, typeX in pairs(stocktypes) do
- AllofType = AllEntities.whereProperty("name", typeX).asList()
- if AllofType ~= nil then
- for i1, entity in pairs(AllofType) do
- rollingstock = entity.getAPI("immersiverailroading:locomotive")
- local posit_array = {}
- local a = {}
- uuid = rollingstock.getUUID()
- position = rollingstock.getLocation()
- xpos = position.getX()
- ypos = position.getY()
- zpos = position.getZ()
- speed = rollingstock.getCurrentSpeed()
- setspeed = 0 -- add later
- tag = "" -- add later
- c = {["x"] = xpos, ["y"] = ypos, ["z"] = zpos}
- a = {}
- a["uuid"] = uuid
- a["method"] = "Manual"
- a["speed"] = speed
- a["setspeed"] = setspeed
- a["posit_array"] = c
- a["name"] = rollingstock.getName()
- a["tag"] = "" --rollingstock.getTag()
- table.insert(b,1,a)
- end
- end
- end
- data = json:encode(b)
- if data ~= "" then
- con:write("#01,"..data.."\r\n")
- con:flush()
- end
- end
- -- Main loop --
- con = internet.open(TcpIP,TcpSendPort)
- while true do
- if (con) then
- overArray()
- end
- os.sleep(wait)
- end
Advertisement
Add Comment
Please, Sign In to add comment