Advertisement
Guest User

Problem with variables in OpenComputers

a guest
Feb 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 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 DisplayMsg(msg, line)
  56.     gpu.setBackground(0x000000);
  57.     gpu.setForeground(0xFFFFFF);
  58.     gpu.fill(2, line+1, 28, 1, " ");
  59.     gpu.set(2, line+1, tostring(msg));
  60. end
  61.  
  62. function DisplayDefMsg()
  63.     ClrMsg();
  64.     DisplayMsg(DefMsg, 2, 0);
  65. end
  66.  
  67. function OpenDoor()
  68.     redstone.setOutput(3, 16);
  69.     cTask = 1;
  70.     WaitMenu(3);
  71. end
  72.  
  73. function ShowMenu()
  74.     ClrScr();
  75.     -- Draw message pane
  76.     gpu.setForeground(0xFFFFFF);
  77.     gpu.fill(1,1,resX, 1, "=");
  78.     gpu.fill(1,2,1,3,"|");
  79.     gpu.fill(resX,2,1,3,"|");
  80.     gpu.fill(1,5,resX,1,"=");
  81.    
  82.     gpu.set(10, 1, "METROPOLIS");
  83.    
  84.     --gpu.set(3, 3, "WELCOME TO METROPOLIS");
  85.    
  86.     -- Draw buttons
  87.     gpu.setBackground(0xFFFFFF);
  88.     gpu.setForeground(0x000000);
  89.     gpu.fill(2,7,12,3, " ");
  90.     gpu.fill(16,7,12,3, " ");
  91.    
  92.     -- Button captions
  93.     gpu.set(7, 8, "VISIT");
  94.     gpu.set(18, 8, "MSG");
  95.    
  96.     gpu.setForeground(0xFFFFFF);
  97.     gpu.setBackground(0x000000);
  98.    
  99.     DisplayDefMsg();
  100.    
  101.     TimeOut = 0;
  102.     sMode = 1;
  103.     cTask = 0;
  104. end
  105.  
  106. function AdminMenu()
  107.  
  108. end
  109.  
  110. function WaitMenu(delay)
  111.     sMode = -1;
  112.     TimeOut = delay;
  113.     timestamp = computer.uptime();
  114.     gpu.fill(1,7, resX, resY, " ");
  115.     gpu.set(8, 9, "PLEASE WAIT");
  116. end
  117.  
  118. function InitHost()
  119.  
  120. end
  121.  
  122. function InitRobot()
  123.  
  124. end
  125.  
  126. function VisitRequest()
  127.     sGuestName = GuestName;
  128.     if (GuestName == Captain) then
  129.         DisplayMsg("Welcome back, "..Captain.."!", 1);
  130.         OpenDoor();
  131.         WaitMenu(3);                   
  132.     end;
  133. end
  134.  
  135.  
  136. function MsgRequest()
  137.  
  138. end
  139.    
  140. ShowMenu();
  141. while true do
  142.     local msg = {event.pull(1)};
  143.     if (msg[1] == "touch") then
  144.         GuestName = msg[6];
  145.         if (msg[4] < 3) and (msg[6] == Captain) then
  146.             AdminMenu();
  147.         else
  148.             if (sMode == 1) and (msg[4] > 6) then
  149.                 -- Main Menu
  150.                 if (msg[3] < 15) then
  151.                     -- VISIT
  152.                     VisitRequest(msg[6]);
  153.                 else
  154.                     MsgRequest(msg[6]);
  155.                 end
  156.             end
  157.         end
  158.     end -- IF Event
  159.    
  160.     if (computer.uptime() - timestamp > TimeOut) and (TimeOut > 0) then
  161.         if (cTask == 1) then
  162.             redstone.setOutput(3, 0);
  163.         elseif (cTask == 2) then
  164.             modem.close(CommPort);
  165.             modem.setStrength(0);
  166.         end
  167.         ShowMenu();
  168.     end
  169.     if (TimeOut == 0) and (redstone.getOutput(3) > 0) then
  170.         redstone.setOutput(3, 0);
  171.     end
  172.    
  173.     gpu.fill(1, 10, 20, 1, " ");
  174.     gpu.set(1, 10, tostring(getUptime()).." "..tostring(TimeOut));
  175.     os.sleep(0);
  176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement