Advertisement
LBPHacker

Door controller for popdog15

Aug 20th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. -- * I don't know what cB would have been, but one thing
  2. --   I know is that the player detectors emit the player
  3. --   event even if they are not wrapped up
  4. -- * Somehow I realized that the cB is the chatbox, but that
  5. --   does emit chat and other events without being wrapped
  6. --   up as well
  7. -- * By the way, use locals
  8.  
  9. -- * Here is the default configuration - this is saved if
  10. --   the program cannot find playerData
  11. local playerData = {
  12.     admins = {
  13.         ["yourname"] = true, -- * note the comma here
  14.         ["some other name"] = true
  15.     }, -- * note the comma here as well
  16.     authorized = {
  17.         -- * this is the part you're going to fill up with names
  18.         --   using the chat commands
  19.     }
  20. }
  21.  
  22. local function saveData()
  23.     local handle = fs.open("playerData", "w")
  24.     handle.write(textutils.serialize(playerData))
  25.     handle.close()
  26. end
  27.  
  28. local function readData()
  29.     local handle = fs.open("playerData", "r")
  30.     playerData = textutils.unserialize(handle.readAll())
  31.     handle.close()
  32. end
  33.  
  34. if not fs.exists("playerData") then saveData() end
  35. readData()
  36.  
  37. -- * I'll use timers instead of sleep so the computer won't
  38. --   freeze until it closes the door (sleep would freeze it)
  39. local doorTimer
  40.  
  41. -- * You're messing with multiple event here, so I put them
  42. --   into one block for the sake of simplicity
  43. while true do
  44.     -- * nothing complicated - just puts the
  45.     --   values returned by .pullEvent into a table
  46.     local eventData = {os.pullEvent()}
  47.     if eventData[1] == "player" then
  48.         if playerData.authorized[eventData[2]] then
  49.             rs.setOutput("bottom", true)
  50.             doorTimer = os.startTimer(4.5) -- * here's the actual sleep
  51.         end
  52.     elseif eventData[1] == "timer" and eventData[2] == doorTimer then
  53.         rs.setOutput("bottom", false)
  54.     elseif eventData[1] == "chat" and playerData.admins[eventData[2]] then
  55.         local words = {}
  56.         for word in string.gmatch(eventData[3], "%w+") do table.insert(words, word) end
  57.         if words[1] == "door" then
  58.             playerData.authorized[words[3]] = (words[2] == "on" and true or nil)
  59.             saveData()
  60.         end
  61.     end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement