Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require('component')
- local ev = require('event')
- local ser = require('serialization')
- local fs = require('filesystem')
- local comp = require('computer')
- local term = require('term')
- local len = require('unicode').len
- local workDir = '/checkPlayer/'
- local clear = term.clear
- local uA = comp.addUser
- local rU = comp.removeUser
- local g = c.gpu
- local xOld, yOld = g.getResolution()
- local x, y = 50, 25
- local startX = 2
- local startY = 3
- local statusX = 39
- local maxPlayers = 20
- local work = true
- local buttons = { '[Добавить]', 'x', 'online', 'offline' }
- local config = { colors = {
- 0xFFFFFF, -- белый 1
- 0xff0066, -- розовый 2
- 0xff0000, -- красный 3
- 0x474747, -- серый 4
- 0x00ff00, -- зелёный 5
- 0xfff200, -- жёлтый 6
- 0xff00ff, -- пурпурный 7
- 0x0000ff, -- синий 8
- 0xff8800, -- оранжевый 9
- 0x00bbff, -- голубой 10
- 0x00ffff, -- бирюзовый 11
- 0x773d00, -- коричневый 12
- 0x770000, -- бордовый 13
- 0x007200, -- тёмно зелёный 14
- 0x00575b, -- тёмно бирюзовый 15
- 0x11007f, -- тёмно синий 16
- 0xb77979, -- тусклый красный 17
- 0xbc9ace, -- тусклый фиолетовый 18
- 0x9aa0ce, -- тусклый синий 19
- 0xcfd396 -- тусклый жёлтый 20
- }, players = { } }
- function check()
- g.setResolution(x,y)
- g.setBackground(0x000000)
- clear()
- g.setForeground(config.colors[4])
- g.set(18,1,'Список игроков:')
- g.set(1,y,buttons[1])
- g.set(x,y,buttons[2])
- for i = 1, #config.players do
- local nick = config.players[i].nick
- local prefix = config.players[i].prefix
- local nickColor = config.players[i].nickColor
- local prefixColor = config.players[i].prefixColor
- local isActiveScript = config.players[i].activeScript
- local LenP = len(prefix)
- local height = startY - 1 + i
- local test = uA(nick) rU(nick)
- g.setForeground(config.colors[1])
- g.set(startX, height, '[')
- g.set(startX + LenP + 1, height, '] - ')
- g.setForeground(prefixColor)
- g.set(startX + 1, height, prefix)
- g.setForeground(nickColor)
- g.set(startX + LenP + 5, height, nick)
- if test then
- if isActiveScript then pcall(loadfile(workDir..nick..'.lua')) config.players[i].activeScript = false end
- g.setForeground(config.colors[5])
- g.set(statusX,height,' '..buttons[3]..' ')
- g.setForeground(config.colors[4])
- g.set(x-1,height,buttons[2]..' ')
- else
- config.players[i].activeScript = true
- g.setForeground(config.colors[4])
- g.set(statusX,height,' '..buttons[4]..' ')
- g.set(x-1,height,buttons[2]..' ')
- end
- end
- end
- function link(bNum,bX,bY)
- comp.beep(1500)
- g.setForeground(config.colors[9])
- g.set(bX,bY,buttons[bNum])
- os.sleep(0.3)
- end
- function clicker(_,_,curX,curY)
- if curX == x and curY == y then link(2,x,y) work = false
- elseif curX == x-1 and curY >= startY and curY <= startY + #config.players - 1 then link(2,x-1,curY) local index = curY-startY+1 remover(index)
- elseif curX >= 1 and curX <= 10 and curY == y then link(1,1,y) if #config.players < maxPlayers then addPlayer() else playersLimitter() end
- end
- end
- function remover(index)
- fs.remove(workDir..config.players[index].nick..'.lua')
- table.remove(config.players,index)
- conf_S()
- end
- function playersLimitter()
- comp.beep(1700)
- g.set(1,y-1,'> Вы достигли лимита в '..maxPlayers..' игроков!')
- os.sleep(2)
- end
- function makeUserScript(name)
- local file = io.open(workDir..name..'.lua','w')
- file:flush()
- file:close()
- end
- function addPlayer()
- ev.ignore('touch',clicker)
- g.fill(1,10,100,100,' ')
- for col = 1, #config.colors do
- g.setForeground(config.colors[col])
- if col <= 10 then
- g.set(col*5-3, 24, '>'..tostring(col))
- else
- g.set(col*5-3-x, 25, '>'..tostring(col))
- end
- end
- g.setForeground(config.colors[9])
- g.fill(1,10,100,1,'─')
- g.fill(1,23,100,1,'─')
- g.set(23,22,'Цвета:')
- term.setCursor(1,11)
- io.write('> Новый ник: ')
- n = io.read()
- io.write('> Префикс: ')
- p = io.read()
- io.write('> Цвет ника (по номеру ниже): ')
- local input = tonumber(io.read())
- if input == nil or input > 20 or input < 1 then nC = 1
- else nC = math.floor(input) end
- io.write('> Цвет префикса (по номеру ниже): ')
- local input = tonumber(io.read())
- if input == nil or input > 20 or input < 1 then pC = 1
- else pC = math.floor(input) end
- io.write('> Создать скрипт '..workDir..'*ник игрока*.lua,\nвыполняющийся при заходе игрока? Y/N: ')
- local input = io.read()
- if input == 'y' or input == 'Y' then makeUserScript(n) end
- table.insert(config.players,{ nick = n, prefix = p, prefixColor = config.colors[pC], nickColor = config.colors[nC], activeScript = true }) conf_S()
- ev.listen('touch',clicker)
- end
- function conf_S()
- local file = io.open(workDir..'config.cfg','w')
- file:write(ser.serialize(config,false))
- file:flush()
- file:close()
- end
- function conf_R()
- local file = io.open(workDir..'config.cfg','r')
- config = ser.unserialize(file:read(fs.size(workDir..'config.cfg')))
- file:close()
- end
- function run()
- if not fs.exists(workDir) then fs.makeDirectory(workDir) conf_S() else conf_R() end
- ev.listen('touch',clicker)
- while work do
- check()
- os.sleep(1)
- end
- exit()
- end
- function exit()
- conf_S()
- ev.ignore('touch',clicker)
- clear()
- g.setForeground(config.colors[1])
- g.setResolution(xOld,yOld)
- end
- function start()
- if g.maxDepth() <= 4 then
- comp.beep(1500)
- print('CheckPlayer: Ошибка! Глубина цвета 4 и ниже не поддерживается! Наобходима видеокарта и монитор 3 уровня.')
- else
- run()
- end
- end
- function ev.shouldInterrupt()
- return false
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement