Advertisement
theinsekt

detector lock

Sep 16th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1.  --theinsekt's player detector lock
  2. --pastebin get juRJgwTe startup
  3.  
  4. --function to set to enable or disable ctrl-t
  5. --http://www.computercraft.info/forums2/index.php?/topic/2732-disable-ctrlt/
  6. local pullEventCopy = os.pullEvent
  7. function setCtrlT(value)
  8.  if value then
  9.   os.pullEvent = pullEventCopy
  10.  else
  11.   os.pullEvent = os.pullEventRaw
  12.  end
  13. end
  14.  
  15. function loadIntoTable(path)
  16. if  not fs.exists(path) then
  17.   return nil
  18.  end
  19.  local h=fs.open(path, "r")
  20.  if h==nil then
  21.   return nil
  22.  end
  23.  local table={}
  24.  while(true) do
  25.   local value=h.readLine()
  26.   if value==nil then break end
  27.   table[value]=true
  28.  end
  29.  h.close()
  30.  return table
  31. end
  32.  
  33.  
  34.  
  35.  
  36. function adminClick(admin, adminSide, openSide)
  37.  print()
  38.  print("right click open side to add player")
  39.  print("right click admin side to go to admin mode")
  40.  local event, dside, player=os.pullEvent("player")
  41.  if dside==adminSide then
  42.   if player==admin then
  43.    print()
  44.    print("hold ctrl-t to terminate program")
  45.    print("right click a detector to exit admin mode")
  46.    setCtrlT(true)--enable ctrl-t
  47.    os.pullEvent("player")
  48.    setCtrlT(false)--enable ctrl-t
  49.   else
  50.    return
  51.   end
  52.  elseif dside==openSide then
  53.   print("not yet implemented")
  54.   print("should try to add to openers")
  55.   sleep(3)
  56.   return
  57.  end
  58.  print("Unknown side")
  59. end
  60.  
  61. function clear()
  62.  term.clear()
  63.  term.setCursorPos(1, 1)
  64. end
  65.  
  66. local openers={
  67. }
  68.  
  69. local admins={
  70. ["theinsekt"]=true,
  71. }
  72.  
  73. local savePath="dataValues"
  74.  
  75. local doorSide="bottom"
  76. local openSide="back"
  77. local adminSide="right"
  78. local doorTime=3
  79. local testing=true
  80.  
  81. setCtrlT(false)--disable ctrl-t
  82. clear()
  83. print("booting...")
  84. sleep(1)
  85. while(true) do
  86.  clear()
  87.  if testing then
  88.   print("debug mode...")
  89.   setCtrlT(true)--enable ctrl-t
  90.  end
  91.  print("adminSide: ",adminSide, " openSide: ",openSide, " doorSide: ",doorSide)
  92.  print()
  93.  print("right click openDide to open door")
  94.  print("right click adminSide to add player, or twice to enter admin mode")
  95.  print()
  96.  local event,dside,player = os.pullEvent("player")
  97.  if dside==adminSide and admins[player]~=nil then
  98.   local admin=player
  99.   print("admin stuff*****")
  100.   adminClick(admin, adminSide, openSide)
  101.  elseif dside==openSide and (openers[player]~=nil or admins[player]~=nil) then
  102.   print("Opening!")
  103.   redstone.setOutput(doorSide,true)
  104.   sleep(doorTime)
  105.   redstone.setOutput(doorSide,false)
  106.  else
  107.   print("Not allowed!")
  108.  end
  109.  sleep(1)
  110. end
  111.  
  112. setCtrlT(true)--enable ctrl-t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement