Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define default base channel
- local defaultBaseChannel = 200
- -- Prompt user for base channel input
- print("Enter base channel (press Enter to use default: " .. defaultBaseChannel .. "):")
- local inputChannel = read()
- -- If the user inputs a number, use it as the base channel, otherwise use the default
- local baseChannel = tonumber(inputChannel) or defaultBaseChannel
- -- Calculate channels based on the base channel
- local stressChannel = baseChannel
- local leftEngineChannel = baseChannel + 1
- local rightEngineChannel = baseChannel + 2
- local fuelChannel = baseChannel + 3
- local accChannel = baseChannel + 4
- local engineLeft = peripheral.wrap("left")
- local engineRight = peripheral.wrap("right")
- local fuel = peripheral.find("create_connected:item_silo")
- local stress = peripheral.find("Create_Stressometer")
- local acc = peripheral.find("modular_accumulator")
- local modem = peripheral.wrap("front")
- if not engineLeft then
- error("Left rotation controller not found")
- elseif not engineRight then
- error("Right rotation controller not found")
- elseif not modem then
- error("modem not found")
- end
- if stress then
- modem.open(stressChannel)
- else
- print("Warning: Stressometer not found. Skipping stress monitoring.")
- end
- if fuel then
- modem.open(fuelChannel)
- else
- print("Warning: Fuel silo not found. Skipping fuel monitoring.")
- end
- if acc then
- modem.open(accChannel)
- else
- print("Warning: Accumulator not found. Skipping accumulator monitoring.")
- end
- modem.open(leftEngineChannel)
- modem.open(rightEngineChannel)
- local totalBlazeCakes = 0
- local secretKey = "YourSecretKey123"
- local leftSpeed = 0
- local rightSpeed = 0
- local function isValidMessage(message)
- local key, msg = tostring(message):match("^(%w+)%:(.+)$")
- return key == secretKey, msg
- end
- local function listenForCoordinates()
- while true do
- local event, side, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local valid, validatedMessage = isValidMessage(message)
- if valid then
- if senderChannel == leftEngineChannel then
- leftSpeed = tonumber(validatedMessage)
- elseif senderChannel == rightEngineChannel then
- rightSpeed = tonumber(validatedMessage)
- elseif senderChannel == fuelChannel and fuel then
- totalBlazeCakes = tonumber(validatedMessage)
- elseif senderChannel == stressChannel and stress then
- usedSU, SUCapacity = validatedMessage:match("^(%d+)%:(%d+%.?%d*)$")
- elseif senderChannel == accChannel and acc then
- accEnergy, accCapacity = validatedMessage:match("^(%d+)%:(%d+%.?%d*)$")
- end
- end
- end
- end
- parallel.waitForAny(
- listenForCoordinates,
- function()
- while true do
- -- Fuel monitoring
- if fuel then
- local totalBlazeCakes = 0
- local total = fuel.size() * 64
- local items = fuel.list()
- for slot, itemDetail in pairs(items) do
- if itemDetail.name == "create:blaze_cake" then
- totalBlazeCakes = totalBlazeCakes + itemDetail.count
- end
- end
- modem.transmit(fuelChannel, 0, secretKey..":"..totalBlazeCakes..":"..total)
- print("Total number of blaze cakes: ", totalBlazeCakes.." / "..total)
- end
- -- Stress monitoring
- if stress then
- local usedSU = stress.getStress()
- local SUCapacity = stress.getStressCapacity()
- modem.transmit(stressChannel, 0, secretKey..":"..usedSU..":"..SUCapacity)
- print("Used SU: ", usedSU)
- print("SU Capacity: ", SUCapacity)
- end
- -- Accumulator monitoring
- if acc then
- local accCapacity = acc.getCapacity()
- local accEnergy = acc.getEnergy()
- modem.transmit(accChannel, 0, secretKey..":"..accEnergy..":"..accCapacity)
- print("Accumulator Capacity: ", accCapacity)
- print("Accumulator Energy: ", accEnergy)
- end
- -- Engine control
- print("Left speed: ", leftSpeed)
- print("Right speed: ", rightSpeed)
- engineLeft.setTargetSpeed(leftSpeed)
- engineRight.setTargetSpeed(rightSpeed)
- sleep(0.2)
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment