Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- A simple members-only Lozinka system for ComputerCraft doors.
- Leaders get a special message, while blacklisted users get ridiculed.
- ]]
- -- vars a server would be interested in..
- local members = {"Cow"}
- local leaders = {"Pig", "Dog"}
- local blacklist = {"Zombie", "Creeper", "Skeleton"}
- local Lozinka = "chicken"
- -- Concatenates two tables.
- -- http://rosettacode.org/wiki/Array_Concatenation#Lua
- function concatTables(aTable, target)
- table.foreach(aTable, function(i,v) table.insert(target,v) end)
- for i,v in next,target do io.write (v..' ') end
- end
- concatTables(leaders, members)
- -- Returns location of value in an array if found.
- -- Note: function is non-case sensitive.
- function match(value, array)
- value = string.lower(value)
- for i in ipairs(array) do
- if value == string.lower(array[i]) then
- return i
- end
- end
- return nil
- end
- function power(aSide, aTime)
- rs.setOutput(aSide, true)
- sleep(aTime)
- rs.setOutput(aSide, false)
- end
- function getInput(message, isLozinka)
- write(message)
- if isLozinka then return read('*') end
- return read()
- end
- function main()
- local openTime = 7
- local waitTime = 2
- local side = "left"
- local trapSide = "back"
- repeat repeat -- allows 'break' to act like a 'continue'
- term.clear()
- term.setCursorPos(1,1)
- local Ime = getInput("Ime: ")
- if match(Ime, blacklist) then
- print("Odlazi!.")
- power(trapSide, waitTime)
- break
- end
- Ime = members[match(Ime,members)]
- if getInput("Lozinka: ",true) ~= Lozinka or not Ime then
- pring("Netocno ime ili lozinka")
- rs.setOutput(side,false)
- sleep(waitTime)
- break
- end
- if match(Ime, leaders) then
- print("Pozdrav "..ime.."!")
- else
- print("Dobrodosli "..ime.."!")
- end
- power(side, openTime)
- until false until false
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement