Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local floorname = "top";
- local doorside = "top";
- local redside = "right";
- local butside = "front";
- local height = "01";
- local isatlevel = false;
- local requested = false;
- peripheral.find("modem", rednet.open);
- function gethost()
- while true do
- local tmphost = rednet.lookup("elevator", "elevator.api");
- if (type(tmphost) == "number") then
- return tmphost;
- end
- end
- end
- local host = gethost();
- -- print("host: " .. tostring(host));
- -- local host = 7;
- print("start");
- function iam()
- -- host = rednet.lookup("elevator", "elevator.api");
- -- host = gethost();
- rednet.send(host, "iamfloor" .. height .. floorname);
- end
- iam();
- redstone.setOutput(doorside, true);
- sleep(0.1);
- redstone.setOutput(doorside, false);
- local function msgs()
- com, msg = rednet.receive(nil, 5);
- if(not com) then
- return;
- end
- print("Msg: " .. tostring(msg));
- if(msg == "open") then
- requested = false;
- redstone.setOutput(doorside, true);
- elseif(msg == "close") then
- requested = false;
- redstone.setOutput(doorside, true);
- sleep(0.1);
- redstone.setOutput(doorside, false);
- end
- end
- local function redstoneinput()
- if(host == nil) then return end;
- while true do
- if(redstone.getInput(redside) and not isatlevel) then
- rednet.send(host, "at" .. floorname);
- isatlevel = true;
- elseif(not redstone.getInput(redside)) then
- isatlevel = false;
- end
- if(redstone.getInput(butside) and not requested) then
- requested = true;
- rednet.send(host, "request" .. floorname);
- end
- -- elseif(not redstone.getInput(butside) and not closed) then
- -- rednet.send(host, "doorclose");
- -- closed = true;
- -- end
- sleep(0.25);
- end
- end
- -- local function waitsleep()
- -- sleep(0.5);
- -- end
- while true do
- print("running");
- iam();
- parallel.waitForAny(msgs, redstoneinput);
- -- redstoneinput();
- -- msgs();
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement