kamilosxd678

[MC-CC] Elevator Client

Aug 28th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. myFloor = 0         -- Self floor number
  2.  
  3. rednet.open("back") -- Opening modem located at back
  4.  
  5. doorsOpened = true
  6. maxLevel = 2
  7. minLevel = 0
  8. request = "null"    -- Global variable for requests
  9.  
  10. function callElevator()
  11.  msg = tostring(myFloor)
  12.  rednet.send(84,msg)
  13.  os.sleep(10)
  14. end
  15.  
  16. function moveDoors()
  17.  if doorsOpened then
  18.   for i = 1, 3 do
  19.    rs.setBundledOutput("right", colors.blue)
  20.    os.sleep(1)
  21.    rs.setBundledOutput("right", colors.black)
  22.    os.sleep(1)
  23.   end
  24.   doorsOpened = false
  25.  else
  26.   for i = 1, 3 do
  27.    rs.setBundledOutput("right", colors.green)
  28.    os.sleep(1)
  29.    rs.setBundledOutput("right", colors.black)
  30.    os.sleep(1)
  31.   end
  32.   doorsOpened = true
  33.  end
  34. end
  35.  
  36. function go()
  37.  input = read()
  38.  input = tonumber(input)
  39.  if input > maxLevel then
  40.   return
  41.  elseif input < minLevel then
  42.   return
  43.  elseif rs.getInput("bottom") then
  44.   msg = tostring(input)
  45.   rednet.send(84,msg)
  46.   moveDoors()
  47.   while rs.getInput("bottom") do
  48.    os.sleep(1)
  49.   end
  50.  else
  51.   moveDoors()
  52.   return
  53.  end
  54. end
  55.  
  56. while true do
  57.  if rs.getInput("left") then
  58.   callElevator()
  59.  end
  60.  if rs.getInput("bottom") then
  61.   if doorsOpened == false then
  62.    moveDoors()
  63.   end
  64.   go()
  65.  end
  66.  os.sleep(1)
  67. end
Advertisement
Add Comment
Please, Sign In to add comment