Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Modem = peripheral.wrap("back")
- local Eng = peripheral.wrap("minecraft:furnace_1")
- local FuelStore = peripheral.wrap("minecraft:chest_1")
- local TChest = peripheral.wrap("minecraft:chest_2")
- local Delay = 3--for Item toggle
- local UpTimes = {5,22}
- local FuelI = {"minecraft:charcoal",5}--(set as false for no fuel). itemtag, targetamount
- local A_Pwr = {1,43200,false,false,false}--GenRole(1-Main,2-Backup,3-starter),MaxPwr(perhour),State,Run,usesUptimes
- local ID = 1
- local function Switch()
- local Items = TChest.list()
- if Items[1].count > 0 then TChest.pushItems(Eng,1) else TChest.pullItems(Eng,1) end
- end
- local function CheckEng()
- local list = Eng.list()
- local Fuel = list[2].count
- if Fuel < FuelI[2] and A_Pwr[4] == true then
- for slot, item in pairs(FuelStore.list()) do
- if item.name == FuelI[1] and Fuel < FuelI[2] then FuelStore.pushItems(Eng,1,1) Fuel = Fuel + 1 end
- end
- end
- return Fuel
- end
- local function Action(D)
- local Ac = textutils.unserialize(D)
- local Response = {}
- if (Ac[1][1] == "G" and Ac[1][2] ~= A_Pwr[1]) or (Ac[1][1] == "ID" and Ac[1][2] ~= ID) then
- print("msg not for unit")
- elseif Ac[2] == "shutdown" then
- A_Pwr[3] = false
- A_Pwr[4] = false
- Response = {true}
- elseif Ac[2] == "startup" then
- A_Pwr[3] = true
- Response = {true}
- elseif Ac[2] == "starter" then
- A_Pwr[3] = true
- A_Pwr[4] = true
- CheckEng()
- Switch()
- os.sleep(Ac[3])
- Switch()
- A_Pwr[3] = false
- A_Pwr[4] = false
- Response = {true}
- elseif Ac[2] == "status" then
- Response = {ID,A_Pwr[3],A_Pwr[4],A_Pwr[5],CheckEng()}
- end
- return textutils.serialize(Response)
- end
- local function Loop()
- Modem.open(223)
- local S = os.setAlarm(os.time("ingame") + (Delay * 0.01))
- local E = os.setAlarm(os.time("ingame") + 1)
- while true do
- local a, b, c, d, e = os.pullEvent()
- if a == "alarm" and A_Pwr[4] == true then
- if b == S then
- Switch()
- S = os.setAlarm(os.time("ingame") + (Delay * 0.01))
- elseif b == E then
- CheckEng()
- E = os.setAlarm(os.time("ingame") + 1)
- end
- elseif a == "modem_message" then
- Modem.transmit(c,223,Action(e))
- else
- if os.time("ingame") > UpTimes[2] or os.time("ingame") < UpTimes[1] and A_Pwr[5] == true then A_Pwr[4] = false elseif A_Pwr[3] == true then A_Pwr[4] = true end
- end
- os.queueEvent("pass")
- end
- end
- Loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement