Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- * I don't know what cB would have been, but one thing
- -- I know is that the player detectors emit the player
- -- event even if they are not wrapped up
- -- * Somehow I realized that the cB is the chatbox, but that
- -- does emit chat and other events without being wrapped
- -- up as well
- -- * By the way, use locals
- -- * Here is the default configuration - this is saved if
- -- the program cannot find playerData
- local playerData = {
- admins = {
- ["yourname"] = true, -- * note the comma here
- ["some other name"] = true
- }, -- * note the comma here as well
- authorized = {
- -- * this is the part you're going to fill up with names
- -- using the chat commands
- }
- }
- local function saveData()
- local handle = fs.open("playerData", "w")
- handle.write(textutils.serialize(playerData))
- handle.close()
- end
- local function readData()
- local handle = fs.open("playerData", "r")
- playerData = textutils.unserialize(handle.readAll())
- handle.close()
- end
- if not fs.exists("playerData") then saveData() end
- readData()
- -- * I'll use timers instead of sleep so the computer won't
- -- freeze until it closes the door (sleep would freeze it)
- local doorTimer
- -- * You're messing with multiple event here, so I put them
- -- into one block for the sake of simplicity
- while true do
- -- * nothing complicated - just puts the
- -- values returned by .pullEvent into a table
- local eventData = {os.pullEvent()}
- if eventData[1] == "player" then
- if playerData.authorized[eventData[2]] then
- rs.setOutput("bottom", true)
- doorTimer = os.startTimer(4.5) -- * here's the actual sleep
- end
- elseif eventData[1] == "timer" and eventData[2] == doorTimer then
- rs.setOutput("bottom", false)
- elseif eventData[1] == "chat" and playerData.admins[eventData[2]] then
- local words = {}
- for word in string.gmatch(eventData[3], "%w+") do table.insert(words, word) end
- if words[1] == "door" then
- playerData.authorized[words[3]] = (words[2] == "on" and true or nil)
- saveData()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement