Advertisement
TwiXon4ik

Untitled

Oct 10th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 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 = { '[Добавить]', '', '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,'Владельцы warp q:')
  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. function clipboarder(_,_,chatNick,data)
  88. if login==1 and chatNick == nick then
  89. advertising = data:lower():gsub('\\',' ')
  90. printFormatText(3,17,84,advertising,colors.white)
  91. end
  92. end
  93. function link(bNum,bX,bY)
  94. comp.beep(1500)
  95. g.setForeground(config.colors[9])
  96. g.set(bX,bY,buttons[bNum])
  97. os.sleep(0.3)
  98. end
  99.  
  100. function clicker(_,_,curX,curY)
  101. if curX == x and curY == y then link(2,x,y) work = false
  102. 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)
  103. elseif curX >= 1 and curX <= 10 and curY == y then link(1,1,y) if #config.players < maxPlayers then addPlayer() else playersLimitter() end
  104. end
  105. end
  106.  
  107. function remover(index)
  108. fs.remove(workDir..config.players[index].nick..'.lua')
  109. table.remove(config.players,index)
  110. conf_S()
  111. end
  112.  
  113. function playersLimitter()
  114. comp.beep(1700)
  115. g.set(1,y-1,'> Вы достигли лимита в '..maxPlayers..' игроков!')
  116. os.sleep(2)
  117. end
  118.  
  119. function makeUserScript(name)
  120. local file = io.open(workDir..name..'.lua','w')
  121. file:flush()
  122. file:close()
  123. end
  124.  
  125. function addPlayer()
  126. ev.ignore('touch',clicker)
  127. g.fill(1,10,100,100,' ')
  128. for col = 1, #config.colors do
  129. g.setForeground(config.colors[col])
  130. if col <= 10 then
  131. g.set(col*5-3, 24, '>'..tostring(col))
  132. else
  133. g.set(col*5-3-x, 25, '>'..tostring(col))
  134. end
  135. end
  136. g.setForeground(config.colors[9])
  137. g.fill(1,10,100,1,'─')
  138. g.fill(1,23,100,1,'─')
  139. g.set(23,22,'Цвета:')
  140. term.setCursor(1,11)
  141. io.write('> Новый ник: ')
  142. n = io.read()
  143. io.write('> Префикс: ')
  144. p = io.read()
  145. io.write('> Цвет ника (по номеру ниже): ')
  146. local input = tonumber(io.read())
  147. if input == nil or input > 20 or input < 1 then nC = 1
  148. else nC = math.floor(input) end
  149. io.write('> Цвет префикса (по номеру ниже): ')
  150. local input = tonumber(io.read())
  151. if input == nil or input > 20 or input < 1 then pC = 1
  152. else pC = math.floor(input) end
  153. io.write('> Создать скрипт '..workDir..'*ник игрока*.lua,\nвыполняющийся при заходе игрока? Y/N: ')
  154. local input = io.read()
  155. if input == 'y' or input == 'Y' then makeUserScript(n) end
  156. table.insert(config.players,{ nick = n, prefix = p, prefixColor = config.colors[pC], nickColor = config.colors[nC], activeScript = true }) conf_S()
  157. ev.listen('touch',clicker)
  158. end
  159.  
  160. function conf_S()
  161. local file = io.open(workDir..'config.cfg','w')
  162. file:write(ser.serialize(config,false))
  163. file:flush()
  164. file:close()
  165. end
  166.  
  167. function conf_R()
  168. local file = io.open(workDir..'config.cfg','r')
  169. config = ser.unserialize(file:read(fs.size(workDir..'config.cfg')))
  170. file:close()
  171. end
  172.  
  173. function run()
  174. if not fs.exists(workDir) then fs.makeDirectory(workDir) conf_S() else conf_R() end
  175. ev.listen('touch',clicker)
  176. while work do
  177. check()
  178. os.sleep(1)
  179. end
  180. exit()
  181. end
  182.  
  183. function exit()
  184. conf_S()
  185. ev.ignore('touch',clicker)
  186. clear()
  187. g.setForeground(config.colors[1])
  188. g.setResolution(xOld,yOld)
  189. end
  190.  
  191. function start()
  192. if g.maxDepth() <= 4 then
  193. comp.beep(1500)
  194. print('CheckPlayer: Ошибка! Глубина цвета 4 и ниже не поддерживается! Наобходима видеокарта и монитор 3 уровня.')
  195. else
  196. run()
  197. end
  198. end
  199.  
  200. function ev.shouldInterrupt()
  201. return false
  202. end
  203.  
  204. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement