Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FLEET AGENT v1.0
- -- CC:Tweaked
- -- Install on each turtle.
- -- Change SLOT to 1 through 6.
- local SLOT = 1
- local PROTOCOL = "mountain_fleet_v1"
- local DEPLOY_DISTANCE = 3
- local HOME_FILE = "fleet_home.dat"
- local id = os.getComputerID()
- local state = {
- slot = SLOT,
- status = "STARTING",
- steps = 0,
- home = nil,
- error = nil
- }
- -- Open wireless modem
- local modemName = nil
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.hasType(name, "modem") then
- local modem = peripheral.wrap(name)
- if modem.isWireless() then
- modemName = name
- break
- end
- end
- end
- if not modemName then
- error("Wireless modem not found")
- end
- rednet.open(modemName)
- -- Persistent state
- local function saveHome()
- local f = fs.open(HOME_FILE, "w")
- f.write(textutils.serialize({
- home = state.home,
- steps = state.steps
- }))
- f.close()
- end
- local function loadHome()
- if not fs.exists(HOME_FILE) then
- return false
- end
- local f = fs.open(HOME_FILE, "r")
- local contents = f.readAll()
- f.close()
- local data = textutils.unserialize(contents)
- if type(data) ~= "table"
- or type(data.home) ~= "table"
- or type(data.steps) ~= "number" then
- return false
- end
- state.home = data.home
- state.steps = data.steps
- return true
- end
- local function locate()
- local x, y, z = gps.locate(2)
- if not x then
- return nil
- end
- return {
- x = math.floor(x + 0.5),
- y = math.floor(y + 0.5),
- z = math.floor(z + 0.5)
- }
- end
- local function sendStatus()
- local position = locate()
- rednet.broadcast({
- type = "status",
- slot = SLOT,
- id = id,
- status = state.status,
- position = position,
- home = state.home,
- steps = state.steps,
- fuel = turtle.getFuelLevel(),
- error = state.error
- }, PROTOCOL)
- end
- -- Initialize the dock record.
- if not loadHome() then
- local position = locate()
- if not position then
- error("GPS unavailable. Dock not saved.")
- end
- state.home = position
- state.steps = 0
- saveHome()
- end
- if state.steps == 0 then
- state.status = "DOCKED"
- else
- state.status = "ACTIVE"
- end
- local function deploy()
- if state.steps > 0 then
- state.error = "Already deployed"
- sendStatus()
- return
- end
- local current = locate()
- if not current or not state.home
- or current.x ~= state.home.x
- or current.y ~= state.home.y
- or current.z ~= state.home.z then
- state.status = "ERROR"
- state.error = "Dock position mismatch"
- sendStatus()
- return
- end
- state.status = "DEPLOYING"
- state.error = nil
- sendStatus()
- while state.steps < DEPLOY_DISTANCE do
- if turtle.forward() then
- state.steps = state.steps + 1
- saveHome()
- sendStatus()
- else
- state.status = "BLOCKED"
- state.error = "Forward path blocked"
- sendStatus()
- return
- end
- end
- state.status = "ACTIVE"
- sendStatus()
- end
- local function recall()
- state.error = nil
- if state.steps == 0 then
- state.status = "DOCKED"
- sendStatus()
- return
- end
- state.status = "RETURNING"
- sendStatus()
- while state.steps > 0 do
- if turtle.back() then
- state.steps = state.steps - 1
- saveHome()
- sendStatus()
- else
- state.status = "BLOCKED"
- state.error = "Return path blocked"
- sendStatus()
- return
- end
- end
- local current = locate()
- local home = state.home
- if current and home
- and current.x == home.x
- and current.y == home.y
- and current.z == home.z then
- state.status = "DOCKED"
- else
- state.status = "ERROR"
- state.error = "Dock GPS verification failed"
- end
- sendStatus()
- end
- -- Start communications
- print("Fleet Turtle " .. SLOT)
- print("Computer ID: " .. id)
- print("Modem: " .. modemName)
- print("GPS home registered")
- sendStatus()
- local heartbeat = os.startTimer(3)
- while true do
- local event, a, b, c = os.pullEvent()
- if event == "timer" and a == heartbeat then
- sendStatus()
- heartbeat = os.startTimer(3)
- elseif event == "rednet_message" then
- local sender = a
- local message = b
- local protocol = c
- if protocol == PROTOCOL
- and type(message) == "table"
- and message.type == "command"
- and message.slot == SLOT then
- if message.action == "deploy" then
- deploy()
- elseif message.action == "recall" then
- recall()
- elseif message.action == "ping" then
- sendStatus()
- end
- end
- end
- end
Advertisement
Comments
-
- Nice brother, do you have telegram?
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=baazahxrfy
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment