Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. -- pastebin get VPXNisds checkplayer.lua
  2. local c = require('component')
  3. local ev = require('event')
  4. local ser = require('serialization')
  5. local fs = require('filesystem')
  6. local comp = require('computer')
  7. local term = require('term')
  8. local len = require('unicode').len
  9.  
  10. local workDir = '/checkPlayer/'
  11. local clear = term.clear
  12. local uA = comp.addUser
  13. local rU = comp.removeUser
  14. local g = c.gpu
  15. local xOld, yOld = g.getResolution()
  16. local x, y = 50, 25
  17. local startX = 2
  18. local startY = 3
  19. local statusX = 39
  20. local maxPlayers = 20
  21. local work = true
  22. local buttons = { '[Добавить]', 'x', 'online', 'offline' }
  23.  
  24. local config = { colors = {
  25.  
  26. 0xFFFFFF, -- белый 1
  27. 0xff0066, -- розовый 2
  28. 0xff0000, -- красный 3
  29. 0x474747, -- серый 4
  30. 0x00ff00, -- зелёный 5
  31. 0xfff200, -- жёлтый 6
  32. 0xff00ff, -- пурпурный 7
  33. 0x0000ff, -- синий 8
  34. 0xff8800, -- оранжевый 9
  35. 0x00bbff, -- голубой 10
  36. 0x00ffff, -- бирюзовый 11
  37. 0x773d00, -- коричневый 12
  38. 0x770000, -- бордовый 13
  39. 0x007200, -- тёмно зелёный 14
  40. 0x00575b, -- тёмно бирюзовый 15
  41. 0x11007f, -- тёмно синий 16
  42. 0xb77979, -- тусклый красный 17
  43. 0xbc9ace, -- тусклый фиолетовый 18
  44. 0x9aa0ce, -- тусклый синий 19
  45. 0xcfd396 -- тусклый жёлтый 20
  46.  
  47. }, players = { } }
  48.  
  49. function check()
  50. g.setResolution(x,y)
  51. g.setBackground(0x000000)
  52. clear()
  53. g.setForeground(config.colors[4])
  54. g.set(18,1,'Список игроков:')
  55. g.set(1,y,buttons[1])
  56. g.set(x,y,buttons[2])
  57. for i = 1, #config.players do
  58. local nick = config.players[i].nick
  59. local prefix = config.players[i].prefix
  60. local nickColor = config.players[i].nickColor
  61. local prefixColor = config.players[i].prefixColor
  62. local isActiveScript = config.players[i].activeScript
  63. local LenP = len(prefix)
  64. local height = startY - 1 + i
  65. local test = uA(nick) rU(nick)
  66. g.setForeground(config.colors[1])
  67. g.set(startX, height, '[')
  68. g.set(startX + LenP + 1, height, '] - ')
  69. g.setForeground(prefixColor)
  70. g.set(startX + 1, height, prefix)
  71. g.setForeground(nickColor)
  72. g.set(startX + LenP + 5, height, nick)
  73. if test then
  74. if isActiveScript then pcall(loadfile(workDir..nick..'.lua')) config.players[i].activeScript = false end
  75. g.setForeground(config.colors[5])
  76. g.set(statusX,height,' '..buttons[3]..' ')
  77. g.setForeground(config.colors[4])
  78. g.set(x-1,height,buttons[2]..' ')
  79. else
  80. config.players[i].activeScript = true
  81. g.setForeground(config.colors[4])
  82. g.set(statusX,height,' '..buttons[4]..' ')
  83. g.set(x-1,height,buttons[2]..' ')
  84. end
  85. end
  86. end
  87.  
  88. function link(bNum,bX,bY)
  89. comp.beep(1500)
  90. g.setForeground(config.colors[9])
  91. g.set(bX,bY,buttons[bNum])
  92. os.sleep(0.3)
  93. end
  94.  
  95. function clicker(_,_,curX,curY)
  96. if curX == x and curY == y then link(2,x,y) work = false
  97. 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)
  98. elseif curX >= 1 and curX <= 10 and curY == y then link(1,1,y) if #config.players < maxPlayers then addPlayer() else playersLimitter() end
  99. end
  100. end
  101.  
  102. function remover(index)
  103. fs.remove(workDir..config.players[index].nick..'.lua')
  104. table.remove(config.players,index)
  105. conf_S()
  106. end
  107.  
  108. function playersLimitter()
  109. comp.beep(1700)
  110. g.set(1,y-1,'> Вы достигли лимита в '..maxPlayers..' игроков!')
  111. os.sleep(2)
  112. end
  113.  
  114. function makeUserScript(name)
  115. local file = io.open(workDir..name..'.lua','w')
  116. file:flush()
  117. file:close()
  118. end
  119.  
  120. function addPlayer()
  121. ev.ignore('touch',clicker)
  122. g.fill(1,10,100,100,' ')
  123. for col = 1, #config.colors do
  124. g.setForeground(config.colors[col])
  125. if col <= 10 then
  126. g.set(col*5-3, 24, '>'..tostring(col))
  127. else
  128. g.set(col*5-3-x, 25, '>'..tostring(col))
  129. end
  130. end
  131. g.setForeground(config.colors[9])
  132. g.fill(1,10,100,1,'─')
  133. g.fill(1,23,100,1,'─')
  134. g.set(23,22,'Цвета:')
  135. term.setCursor(1,11)
  136. io.write('> Новый ник: ')
  137. n = io.read()
  138. io.write('> Префикс: ')
  139. p = io.read()
  140. io.write('> Цвет ника (по номеру ниже): ')
  141. local input = tonumber(io.read())
  142. if input == nil or input > 20 or input < 1 then nC = 1
  143. else nC = math.floor(input) end
  144. io.write('> Цвет префикса (по номеру ниже): ')
  145. local input = tonumber(io.read())
  146. if input == nil or input > 20 or input < 1 then pC = 1
  147. else pC = math.floor(input) end
  148. io.write('> Создать скрипт '..workDir..'*ник игрока*.lua,\nвыполняющийся при заходе игрока? Y/N: ')
  149. local input = io.read()
  150. if input == 'y' or input == 'Y' then makeUserScript(n) end
  151. table.insert(config.players,{ nick = n, prefix = p, prefixColor = config.colors[pC], nickColor = config.colors[nC], activeScript = true }) conf_S()
  152. ev.listen('touch',clicker)
  153. end
  154.  
  155. function conf_S()
  156. local file = io.open(workDir..'config.cfg','w')
  157. file:write(ser.serialize(config,false))
  158. file:flush()
  159. file:close()
  160. end
  161.  
  162. function conf_R()
  163. local file = io.open(workDir..'config.cfg','r')
  164. config = ser.unserialize(file:read(fs.size(workDir..'config.cfg')))
  165. file:close()
  166. end
  167.  
  168. function run()
  169. if not fs.exists(workDir) then fs.makeDirectory(workDir) conf_S() else conf_R() end
  170. ev.listen('touch',clicker)
  171. while work do
  172. check()
  173. os.sleep(1)
  174. end
  175. exit()
  176. end
  177.  
  178. function exit()
  179. conf_S()
  180. ev.ignore('touch',clicker)
  181. clear()
  182. g.setForeground(config.colors[1])
  183. g.setResolution(xOld,yOld)
  184. end
  185.  
  186. function start()
  187. if g.maxDepth() <= 4 then
  188. comp.beep(1500)
  189. print('CheckPlayer: Ошибка! Глубина цвета 4 и ниже не поддерживается! Наобходима видеокарта и монитор 3 уровня.')
  190. else
  191. run()
  192. end
  193. end
  194.  
  195. function ev.shouldInterrupt()
  196. return false
  197. end
  198.  
  199. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement