Advertisement
Guest User

Problematic door lock (cut to minimum)

a guest
Feb 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | None | 0 0
  1. local component = require("component");
  2. local event = require("event");
  3. local computer = require("computer");
  4. local redstone = component.redstone;
  5. local gpu = component.gpu;
  6. local modem = component.modem;
  7. local InPort = 114;
  8. local OutPort = 1984;
  9. local CommPort = 3666;
  10.  
  11. local Captain = "Aex";
  12. local userlist = {};
  13. local TrustedAddr = "";
  14.  
  15. modem.open(InPort);
  16.  
  17. local resX = 30
  18. local resY = 10
  19. gpu.setResolution(resX, resY);
  20.  
  21. local sMode = 1;    -- -1 - Wait Menu, 0 - Admin, 1 - Main Menu,
  22. local cTask = 0;    -- 0 - Nothing, 1 - Door open, 2 - Message pending
  23. local TimeOut = 0;
  24. local sCL = 0;
  25. local GuestName = "";
  26. local timestamp = computer.uptime();
  27.  
  28. local DefMsg = "    WELCOME TO METROPOLIS"
  29. local RSside = 3;
  30. local Defcon = 4; -- 5 - open doors, _4_ - Only friends, 3 - Only owner, 2 - Ignore, radar sweeps, 1 - Exterminate
  31. local MailBlock = -1;       -- 0 - allowed, 1 - blocked
  32.  
  33. modem.setStrength(0);
  34.        
  35. function getUptime(tTime)
  36.   local tTime = computer.uptime();
  37.   local tDays = math.floor(tTime/86400);
  38.   local tHours = math.floor((tTime%86400)/3600);
  39.   local tMinutes = math.floor((tTime%3600)/60);
  40.   local tSeconds = math.floor(tTime%60);
  41.   return tDays.."d, "..tHours..":"..tMinutes..":"..tSeconds;
  42. end    
  43.  
  44. function ClrScr()
  45.     gpu.setBackground(0x000000);
  46.     gpu.fill(1,1, resX, resY, " ");
  47. end
  48.  
  49. function ClrMsg()
  50.     gpu.setBackground(0x000000);
  51.     gpu.setForeground(0xFFFFFF);
  52.     gpu.fill(2, 2, 28, 3, " ");
  53. end
  54.  
  55. function DisplayDefMsg()
  56.     ClrMsg();
  57.     DisplayMsg(DefMsg, 2, 0);
  58. end
  59.  
  60. function OpenDoor()
  61.     redstone.setOutput(3, 16);
  62.     cTask = 1;
  63.     WaitMenu(3);
  64. end
  65.  
  66. function ShowMenu()
  67.     ClrScr();
  68.     -- Draw message pane
  69.     gpu.setForeground(0xFFFFFF);
  70.     gpu.fill(1,1,resX, 1, "=");
  71.     gpu.fill(1,2,1,3,"|");
  72.     gpu.fill(resX,2,1,3,"|");
  73.     gpu.fill(1,5,resX,1,"=");
  74.    
  75.     gpu.set(10, 1, "METROPOLIS");
  76.    
  77.     --gpu.set(3, 3, "WELCOME TO METROPOLIS");
  78.    
  79.     -- Draw buttons
  80.     gpu.setBackground(0xFFFFFF);
  81.     gpu.setForeground(0x000000);
  82.     gpu.fill(2,7,12,3, " ");
  83.     gpu.fill(16,7,12,3, " ");
  84.    
  85.     -- Button captions
  86.     gpu.set(7, 8, "VISIT");
  87.     gpu.set(18, 8, "MSG");
  88.    
  89.     gpu.setForeground(0xFFFFFF);
  90.     gpu.setBackground(0x000000);
  91.    
  92.     DisplayDefMsg();
  93.    
  94.     TimeOut = 0;
  95.     sMode = 1;
  96.     cTask = 0;
  97. end
  98.  
  99. function AdminMenu()
  100.  
  101. end
  102.  
  103. function WaitMenu(delay)
  104.     gpu.fill(1,7, resX, resY, " ");
  105.     gpu.set(8, 9, "PLEASE WAIT");
  106.    
  107.     sMode = -1;
  108.     TimeOut = delay;
  109.     timestamp = computer.uptime();
  110. end
  111.  
  112. function InitHost()
  113.  
  114. end
  115.  
  116. function InitRobot()
  117.  
  118. end
  119.  
  120. function VisitRequest()
  121.     sGuestName = GuestName;
  122.     if (GuestName == Captain) then
  123.         DisplayMsg("Welcome back, "..Captain.."!", 1);
  124.         OpenDoor();
  125.         WaitMenu(3);                   
  126.     end;
  127. end
  128.  
  129.  
  130. function MsgRequest()
  131.  
  132. end
  133.    
  134. ShowMenu();
  135. while true do
  136.     local msg = {event.pull(1)};
  137.     if (msg[1] == "touch") then
  138.         GuestName = msg[6];
  139.         if (msg[4] < 3) and (msg[6] == Captain) then
  140.             AdminMenu();
  141.         else
  142.             if (sMode == 1) and (msg[4] > 6) then
  143.                 -- Main Menu
  144.                 if (msg[3] < 15) then
  145.                     -- VISIT
  146.                     VisitRequest(msg[6]);
  147.                 else
  148.                     MsgRequest(msg[6]);
  149.                 end
  150.             end
  151.         end
  152.     end -- IF Event
  153.    
  154.     if (computer.uptime() - timestamp > TimeOut) and (TimeOut > 0) then
  155.         if (cTask == 1) then
  156.             redstone.setOutput(3, 0);
  157.         elseif (cTask == 2) then
  158.             modem.close(CommPort);
  159.             modem.setStrength(0);
  160.         end
  161.         ShowMenu();
  162.     end
  163.     if (TimeOut == 0) and (redstone.getOutput(3) > 0) then
  164.         redstone.setOutput(3, 0);
  165.     end
  166.    
  167.     gpu.fill(1, 10, 20, 1, " ");
  168.     gpu.set(1, 10, tostring(getUptime()).." "..tostring(TimeOut));
  169.     os.sleep(0);
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement