Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local masterID
- local armed = false
- local function getMissileType()
- peripheral.call("back", "getMissile")
- end
- local function getArmStatus()
- local armed
- end
- local function setArmState(newState)
- --# peripheral stuff
- end
- local function fire()
- id, msg, distance = rednet.receive(masterID)
- if (msg == "ping") then
- print(" master=", id)
- masterID = id;
- rednet.send(masterID, "pong")
- elseif type(msg) == "table" and id == masterID then
- if type(msg.x) == "number" and type(msg.y) == "number" and type(msg.z) == "number" then
- print(" launching to x=" .. msg.x .. ", y=" .. msg.y .. ", z=" .. msg.z)
- icbm.setTarget(msg.x, msg.y, msg.z)
- if (armed) then
- peripheral.call("back","launch")
- end
- else
- print(" invalid table command")
- end
- else
- print(" invalid message", msg, " from ", id, ", distance=", distance)
- end
- end
- local function getSiloState()
- return {os.getComputerID, peripheral.call("back", "getMissile")}
- end
- rednet.send(masterID, getSiloState())
- while true do
- local message = {rednet.receive()}
- if message[1] == masterID then
- if message[2] == "arm" then setArmState(true)
- elseif message[2] == "disarm" then setArmState(false)
- elseif message[2] == "fire" then fire()
- else --# bad message, ignore
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement