Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- K_VERSION = 0.093 -- Version of program. Need for auto-update
- --===========================================================
- -- Inline help functions
- --===========================================================
- local function clearScreen() term.clear(); term.setCursorPos(1,1) end
- local function tblLen(tbl) local n=0; for _,_ in pairs(tbl) do n = n + 1 end return n end
- local function makeSet(list) local set = {}; for _, v in pairs(list) do set[v] = true end return set end
- local function pressAnyKey() local event, param1 = os.pullEvent ("key") end
- local function getChar(str, pos) return string.sub(str, pos, pos) end
- -- Redefine global function for faster acces
- local floor = math.floor
- local ceil = math.ceil
- local insert= table.insert
- local min = math.min
- local max = math.max
- local scrW, scrH = term.getSize() -- Get screen params
- local source = "http://pastebin.com/raw.php?i=dsQ8c2UR"
- -- ==============================
- -- Auto-update
- -- Download and replace running file
- -- ==============================
- local function autoUpdate()
- -- Get version of last
- if not http then return end
- local httpResponce = http.get(source)
- local allText = httpResponce.readAll()
- httpResponce.close()
- local newVersion = 0
- local _,verPos = string.find(allText, 'K_VERSION *= *')
- if verPos then
- newVersion = tonumber(string.match(allText, '%d+[%.?%d*]*', verPos+1))
- end
- -- Compare and replace
- if K_VERSION < newVersion then
- local sFile = shell.getRunningProgram()
- local f = fs.open(sFile, "w")
- f.write(allText)
- f.close()
- clearScreen()
- print("New version downloaded!")
- print("Rebooting to apply changes...")
- sleep(0.1)
- os.reboot()
- sleep(10)
- end
- end
- -- ################################################################################## --
- -- ## Main ## --
- -- ################################################################################## --
- local function setAllOutput(state)
- for k,v in pairs(redstone.getSides()) do
- redstone.setOutput(v, state)
- end
- end
- function main()
- -- Update on background
- autoUpdate()
- local sensor = peripheral.find('openperipheral_sensor')
- local maxPlayers = 1
- local whitelist = {}
- local pl
- while true do
- -- Start the timer
- local timer
- timer = os.startTimer( 3 )
- while true do
- local sEvent, p1, p2, p3, p4, p5 = os.pullEvent()
- if sEvent == "key" then
- if p1 == keys.minus then
- maxPlayers = math.max(0, maxPlayers - 1)
- elseif p1 == keys.equals then
- maxPlayers = maxPlayers + 1
- elseif p1 == keys.insert then
- if pl then
- for k,v in pairs(pl) do
- whitelist[v.name] = true
- end
- end
- elseif p1 == keys.delete then
- whitelist = {}
- end
- elseif sEvent == "timer" and p1 == timer then
- pl = sensor.getPlayers()
- local catchedPlayers = {}
- clearScreen()
- print("Players found:")
- for k,v in pairs(pl) do
- print(v.name)
- if not whitelist[v.name] then
- table.insert(catchedPlayers, v.name)
- end
- end
- term.setCursorPos(scrW-20, 1)
- write("Whitelisted players:")
- local i=1
- for k,v in pairs(whitelist) do
- term.setCursorPos(scrW-20, 1+i)
- write(k)
- i=i+1
- end
- if #catchedPlayers>maxPlayers then
- setAllOutput(true)
- else
- setAllOutput(false)
- end
- term.setCursorPos(1, scrH-3)
- write("MaxPlayers: "..maxPlayers)
- term.setCursorPos(1, scrH-2)
- print("Press -/+ to change max player")
- print("Press [insert] to add all players to whitelist")
- write("Press [delete] to clear whitelist")
- break
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement