Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ProgramName = "Tank/TankSlave.lua"
- Version = "1.0"
- Date = "5/12/2021"
- Time = "15:20"
- Author = "Jetro"
- -- Peripherals
- local peripherals = peripheral.getNames()
- for i = 1, #peripherals do
- if peripheral.getType(peripherals[i]) == "modem" then
- ModemSide = peripherals[i]
- end
- end
- if ModemSide == nil then
- error("no modem")
- end
- rednet.open(ModemSide)
- -- Variables
- local MainPCID = 0
- local TankName
- local LastAmount
- local Update = false
- -- Functions
- function RednetSend( toID, SendMSG)
- WaitTime = 0
- id = nil
- msg = nil
- while id == nil and msg ~= "received" do
- rednet.send(toID,SendMSG)
- print("SND: #"..toID..": "..SendMSG)
- id, msg = rednet.receive(1)
- end
- end
- -- Main
- if fs.exists("Tank/TankName.lua") then
- myTankName = fs.open("Tank/TankName.lua","r")
- TankName = myTankName.readAll()
- myTankName.close()
- else
- error("No TankName file")
- end
- if not(fs.exists("startup.lua")) then
- os.setComputerLabel(TankName)
- myStartup = fs.open("startup.lua","w")
- myStartup.write("shell.run('"..ProgramName.."')")
- myStartup.close()
- os.reboot()
- end
- while true do
- id, msg = rednet.receive(1)
- if msg == "Update" then
- Update = true
- elseif msg == "UpdateProgram" then
- fs.delete(ProgramName)
- shell.run("pastebin get nAS2Debh "..ProgramName)
- os.reboot()
- else
- end
- Tank = peripheral.find("railcraft:tank_steel_valve")
- Tank = Tank.getTanks()[1]
- if Tank.amount then
- if (LastAmount ~= Tank.amount) or (Update == true) then
- RednetSend(MainPCID,TankName.."|"..Tank.name.."|"..Tank.amount.."|"..Tank.capacity)
- LastAmount = Tank.amount
- end
- else
- if (LastAmount ~= 0) or (Update == true) then
- Tank.name = "empty"
- Tank.amount = 0
- RednetSend(MainPCID,TankName.."|"..Tank.name.."|"..Tank.amount.."|"..Tank.capacity)
- LastAmount = 0
- end
- end
- Update = false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement