PHOBOSS98 0 Posted March 25, 2019 Share Posted March 25, 2019 So... I'm back...you know radars are expensive... that makes radar upgrades for each drone more expensive...which defeats the purpose of having a dispensable army. This is my attempt at fixing this issue: Instead of having each of your drone fly around with equipment worth half of the US military budget, why not have a single radar and a computer to tell the swarm where to buzz around?. Here's the new stuff that you need: a Waypoint block named "yeet" -- or something else if you want, just don't forget to change it in the code Radar block --from computronics a computer-- preferably a server or something that can give you a portable interface to type in your commands atleast a tier 2 drone --for the survivalists note: they run out of power fast if you dont give them the right upgrades tho... thats why I prefer creative cases 1 Navigation upgrade for each drone and the code: this goes into your computer: local component = require("component") local event = require("event") local serialization= require("serialization") local computer= require("computer") local radar = component.radar local modem = component.modem modem.open(2412) modem.broadcast(2412,"n= component.proxy(component.list('navigation')())") modem.broadcast(2412,"d= component.proxy(component.list('drone')())") modem.broadcast(2412,"rbt= component.proxy(component.list(‘robot’)())") modem.broadcast(2412,"function sleep(timeout) checkArg(1, timeout, 'number', 'nil') local deadline = computer.uptime() + (timeout or 0) repeat computer.pullSignal(deadline - computer.uptime()) until computer.uptime() >= deadline end") local function sleep(timeout) checkArg(1, timeout, "number", "nil") local deadline = computer.uptime() + (timeout or 0) repeatcomputer.pullSignal(deadline - computer.uptime()) until computer.uptime() >= deadline end while true do local cmd=io.read() if not cmd then return end if cmd=="BZZ" then print("Target: ") tag=io.read() print("Drone No.: ") srm=io.read() repeat local cmd=select(1,event.pull(1)) for k, v in ipairs(radar.getEntities()) do if v.name==tag then x= v.x y=v.y z=v.z end if v.y>0 then y=v.y+1 end end modem.broadcast(2412,"for k, v in ipairs (n.findWaypoints(100)) do if v.label=='yeet' and d.name()=='"..srm.."' then a=-v.position[1]-'"..x.."'+ math.random(-3,3) math.abs(a) if ( -v.position[1]>"..x..") then a=-a elseif(-v.position[1]<="..x..")then a=math.abs(a) end b=-v.position[2]-'"..y.."'+ math.random(-3,3) math.abs(b) if ( -v.position[2]>"..y..") then b=-b elseif(-v.position[2]<="..y..")then b=math.abs(b) end c=-v.position[3]-'"..z.."'+ math.random(-3,3) math.abs(c) if ( -v.position[3]>"..z..") then c=-c elseif(-v.position[3]<="..z..")then c=math.abs(c) end d.move(a,b,c) end end") print (x,y,z)sleep(0.5) until cmd=="key_down" end if cmd=="SWARM" then print("Target: ") tag=io.read() repeat local cmd=select(1,event.pull(1)) for k, v in ipairs(radar.getEntities()) do if v.name==tag then x= v.x y=v.y z=v.z end if v.y>0 then y=v.y+1 end end modem.broadcast(2412,"for k, v in ipairs (n.findWaypoints(100)) do if v.label=='yeet' then a=-v.position[1]-'"..x.."'+ math.random(-3,3) math.abs(a) if ( -v.position[1]>"..x..") then a=-a elseif(-v.position[1]<="..x..")then a=math.abs(a) end b=-v.position[2]-'"..y.."'+ math.random(-3,3) math.abs(b) if ( -v.position[2]>"..y..") then b=-b elseif(-v.position[2]<="..y..")then b=math.abs(b) end c=-v.position[3]-'"..z.."'+ math.random(-3,3) math.abs(c) if ( -v.position[3]>"..z..") then c=-c elseif(-v.position[3]<="..z..")then c=math.abs(c) end d.move(a,b,c) end end") print (x,y,z)sleep(0.5) until cmd=="key_down" end if cmd=="RETURN" then print("Target: ") tag=io.read() repeat local cmd=select(1,event.pull(1)) for k, v in ipairs(radar.getEntities()) do if v.name==tag then x= v.x y=v.y z=v.z end if v.y>0 then y=v.y+1 end end modem.broadcast(2412,"for k, v in ipairs (n.findWaypoints(100)) do if v.label=='yeet' then a=-v.position[1]-'"..x.."' math.abs(a) if ( -v.position[1]>"..x..") then a=-a elseif(-v.position[1]<="..x..")then a=math.abs(a) end b=-v.position[2]-'"..y.."' math.abs(b) if ( -v.position[2]>"..y..") then b=-b elseif(-v.position[2]<="..y..")then b=math.abs(b) end c=-v.position[3]-'"..z.."' math.abs(c) if ( -v.position[3]>"..z..") then c=-c elseif(-v.position[3]<="..z..")then c=math.abs(c) end d.move(a,b,c) end end") print (x,y,z)sleep(0.5) until cmd=="key_down" end print(select(6, event.pull(3, "modem_message"))) end and for the drone (nothing really changed): local m=component.proxy(component.list("modem")()) local d=component.proxy(component.list("drone")()) d.setLightColor(0x00FFE8) -- the first character 's' of the method should have been in lower case d.setStatusText(d.name()) -- same here... my bad m.open(2412) m.setWakeMessage("RISE") local function respond(...) local args=table.pack(...) pcall(function() m.broadcast(2412, table.unpack(args)) end) end local function receive() while true do local evt,_,_,_,_,cmd=computer.pullSignal() if evt=="modem_message" then return load(cmd) end end end while true do local result,reason=pcall(function() local result,reason=receive() if not result then return respond(reason) end respond(result()) end) if not result then respond(reason) end end Back in the days where everything was simple, like when I made the original code, each drone had a Radar upgrade that tells it where everybody is relative to the drone itself... this had to change... The drones have to rely on a reference point to know where they are in space. With the waypoint block pointed to the radar block the drones can know their relative distance from the radar. (It should work wherever you place it, just have the side with the particle effects touch the radar block) With the radar knowing where entities are in space relative to the itself the computer can tell the drones where an entity is from the radars perspective. With some quick maths the drones know where an entity is relative to themselves.... and thats how science works... COMMANDS SO FAR: BZZ -- call a drone to fly randomly around you or another entity note: energy drains really fast when you let it fly around too long... SWARM -- calls the whole swarm to do the same thing RETURN -- calls the whole swarm to your feet. Much easier than going on a scavenger hunt for your lost drones have F.U.N. PS: the drones should all be powered on before running the program Quote Link to post Share on other sites