Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Trade Station Controller
- local protocol = "AUTOBUYER"
- local gui = require("SmallGUI");
- rednet.open("top");
- file = fs.open("data.dat", "r");
- data = textutils.unserialize(file.readAll());
- local hostname = data["itemID"];
- local side = "back";
- rednet.host(hostname, protocol);
- local uptime = 0;
- local currentLog = {};
- function log(input)
- local tempOut = "[" .. gui.parseTime(uptime) .. "] " .. input;
- table.insert(currentLog, tempOut);
- end
- function enableMachine()
- if redstone.getOutput(side) == false then
- redstone.setOutput(side, true);
- log("Enabling Trading Station");
- end
- end
- function disableMachine()
- if redstone.getOutput(side) == true then
- redstone.setOutput(side, false);
- log("Disabling Trading Station");
- end
- end
- disableMachine();
- function waitForMessage()
- while true do
- address, message = rednet.receive(protocol);
- if message == "enable" then
- enableMachine();
- elseif message == "disable" then
- disableMachine();
- elseif message == "getData" then
- log("Sending Data...");
- rednet.send(address, textutils.serialize(data), protocol);
- end
- end
- end
- function setUptime()
- while true do uptime = uptime + 1; sleep(1) end
- end
- function tradeStationStatus()
- if redstone.getOutput(side) == false then return "Disabled" else return "Enabled" end
- end
- function updateScreen()
- term.clear()
- while true do
- gui.printf(string.rep("=", term.getSize()),1,1);
- gui.printf("Trade Station Controller [Ver 2.0]|Uptime: " .. gui.parseTime(uptime),1,2);
- gui.printf(string.rep("=", term.getSize()),1,3);
- gui.printf("Item: " .. data["displayName"],1,4);
- gui.printf("Trade Station Status: " .. tradeStationStatus() .. " ",1,5);
- gui.printf(string.rep("=", term.getSize()),1,6);
- for i = 1, 12, 1 do
- tableLength = table.getn(currentLog);
- if currentLog[tableLength - i] ~= nil then
- gui.printf(currentLog[tableLength - i] .. string.rep(" ", term.getSize()), 1, 6+i);
- end
- end
- gui.printf(string.rep("=", term.getSize()),1,19);
- sleep(0);
- end
- end
- parallel.waitForAny(waitForMessage, setUptime, updateScreen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement