Advertisement
Guest User

CPD

a guest
Apr 19th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. --[[
  2. A simple members-only Lozinka system for ComputerCraft doors.
  3. Leaders get a special message, while blacklisted users get ridiculed.
  4. ]]
  5. -- vars a server would be interested in..
  6. local members = {"Cow"}
  7. local leaders = {"Pig", "Dog"}
  8. local blacklist = {"Zombie", "Creeper", "Skeleton"}
  9. local Lozinka = "chicken"
  10. -- Concatenates two tables.
  11. -- http://rosettacode.org/wiki/Array_Concatenation#Lua
  12. function concatTables(aTable, target)
  13. table.foreach(aTable, function(i,v) table.insert(target,v) end)
  14. for i,v in next,target do io.write (v..' ') end
  15. end
  16. concatTables(leaders, members)
  17. -- Returns location of value in an array if found.
  18. -- Note: function is non-case sensitive.
  19. function match(value, array)
  20. value = string.lower(value)
  21. for i in ipairs(array) do
  22. if value == string.lower(array[i]) then
  23. return i
  24. end
  25. end
  26. return nil
  27. end
  28. function power(aSide, aTime)
  29. rs.setOutput(aSide, true)
  30. sleep(aTime)
  31. rs.setOutput(aSide, false)
  32. end
  33. function getInput(message, isLozinka)
  34. write(message)
  35. if isLozinka then return read('*') end
  36. return read()
  37. end
  38.  
  39. function main()
  40. local openTime = 7
  41. local waitTime = 2
  42. local side = "left"
  43. local trapSide = "back"
  44.  
  45. repeat repeat -- allows 'break' to act like a 'continue'
  46. term.clear()
  47. term.setCursorPos(1,1)
  48. local Ime = getInput("Ime: ")
  49.  
  50. if match(Ime, blacklist) then
  51. print("Odlazi!.")
  52. power(trapSide, waitTime)
  53. break
  54. end
  55.  
  56. Ime = members[match(Ime,members)]
  57. if getInput("Lozinka: ",true) ~= Lozinka or not Ime then
  58. pring("Netocno ime ili lozinka")
  59. rs.setOutput(side,false)
  60. sleep(waitTime)
  61. break
  62. end
  63. if match(Ime, leaders) then
  64. print("Pozdrav "..ime.."!")
  65. else
  66. print("Dobrodosli "..ime.."!")
  67. end
  68. power(side, openTime)
  69. until false until false
  70. end
  71. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement