4epB9Ik

SkyPad.lua

Mar 9th, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. --============================
  2. -- OpenRep.
  3. -- Автор SkyDrive_
  4. -- Идея Astro
  5. -- Проект McSkill, cервер ТМ
  6. -- 09.07.2017
  7. -- Version 1.01
  8. --============================
  9. local component = require(component)
  10. local term = require(term)
  11. local event = require(event)
  12. local unicode=require(unicode)
  13. local computer = require(computer)
  14. local fs = require(filesystem)
  15. local shell = require(shell)
  16. local serial = require(serialization)
  17. if not fs.exists(lib/sky.lua) then
  18. shell.execute(wget httpswww.dropbox.comsct5zsbm81zir7w2Sky%28lib%29.luadl=1 libSky.lua)
  19. end
  20. local Sky = require(lib/sky)
  21. local g = component.gpu
  22. local c = component.chat_box
  23. local u = computer.addUser
  24. local tab
  25. event.shouldInterrupt = function () return false end
  26. --------------------Настройки--------------------
  27. local WIGHT, HEIGHT = 80, 25 --Разрешение моника 146112 x 42
  28. local COLOR1 = 0x00ffff --Рамка
  29. local COLOR2 = 0x0000ff --Цвет кнопок
  30. local COLOR_W1 = §a --Лс текст
  31. local COLOR_W2 = §b --Лс выделение
  32. local LINES = 1 --Длина таблицы, которая отображает рейтинг топ игроков. Меняется, в зависимости от разрешения
  33. local HISTORY = 1 --Кол-во строк в истории
  34. -------------------------------------------------
  35. local mid = WIGHT 2 --
  36. print(nИнициализация...)
  37. os.sleep(2)
  38. print(Запуск программы...)
  39. os.sleep(2)
  40.  
  41. file = io.open(shell.getWorkingDirectory() .. RepBD.lua, r)
  42. local reads = fileread(9999999)
  43. if reads ~= nil then
  44. tab = serial.unserialize({ .. reads .. })
  45. else
  46. tab = {}
  47. end
  48. fileclose()
  49.  
  50. users={computer.users()}
  51. for i=1, #users do
  52. computer.removeUser(users[i])
  53. end
  54.  
  55. if not (fs.isDirectory(shell.getWorkingDirectory() .. Rep)) then
  56. fs.makeDirectory(shell.getWorkingDirectory() .. Rep)
  57. end
  58.  
  59. function RepCheck(name)
  60. file = io.open(shell.getWorkingDirectory() .. Rep .. name, r)
  61. local reads = fileread(9999999)
  62. local mass = serial.unserialize({ .. reads .. })
  63. local plus, minus = 0, 0
  64. for i = 1, #mass do
  65. if mass[i][2] == + then
  66. plus = plus + 1
  67. else
  68. minus = minus + 1
  69. end
  70. end
  71. fileclose()
  72. return plus, minus
  73. end
  74.  
  75. function RepChange(nick, name, value)
  76. file = io.open(shell.getWorkingDirectory() .. Rep .. name, r)
  77. local reads = fileread(9999999)
  78. if reads ~= nil then
  79. local mass = serial.unserialize({ .. reads .. })
  80. for i = 1, #mass do
  81. if mass[i][1] == nick then
  82. return(Вы уже оценили этого игрока)
  83. end
  84. end
  85. end
  86. fileclose()
  87.  
  88. file = io.open(shell.getWorkingDirectory() .. Rep .. name, a)
  89. filewrite({' .. nick .. ', ' .. value .. '},n)
  90. fileclose()
  91. return(Ваш голос учтён)
  92. end
  93.  
  94. function TabSave()
  95. file = io.open(shell.getWorkingDirectory() .. RepBD.lua, w)
  96. local text =
  97. for i = 1, #tab do
  98. text = text .. {' .. tab[i][1] .. ', .. tab[i][2] .. , .. tab[i][3] .. , .. tab[i][4] .. },n
  99. end
  100. filewrite(text)
  101. fileclose()
  102. end
  103.  
  104. function history(name)
  105. file = io.open(shell.getWorkingDirectory() .. Rep .. name, r)
  106. local reads = fileread(9999999)
  107. local mass = serial.unserialize({ .. reads .. })
  108. local hist
  109. if #mass HISTORY then
  110. hist = #mass - HISTORY + 1
  111. else
  112. hist = 1
  113. end
  114. local text =
  115. for i = hist, #mass do
  116. if mass[i][2] == + then
  117. COLOR_W3 = §2
  118. else
  119. COLOR_W3 = §4
  120. end
  121. text = text .. COLOR_W2 .. mass[i][1] .. COLOR_W1 .. поставил .. COLOR_W3 .. mass[i][2] .. string.char(10)
  122. end
  123. fileclose()
  124. return text
  125. end
  126.  
  127. function tableCheck(name)
  128. for i = 1, #tab do
  129. if tab[i][1] == name then
  130. table.remove(tab, i)
  131. return
  132. end
  133. end
  134. end
  135.  
  136. function tableAdd(name, reputation, plus, minus)
  137. for i = 1, #tab do
  138. if tab[i][2] = reputation then
  139. table.insert(tab, i, {name, reputation, plus, minus})
  140. if #tab LINES then
  141. table.remove(tab, #tab)
  142. end
  143. return
  144. end
  145. end
  146. table.insert(tab, {name, reputation, plus, minus})
  147. if #tab LINES then
  148. table.remove(tab, #tab)
  149. end
  150. end
  151.  
  152. function Message(msg, nick)
  153. if msg == -rep then
  154. Sky.Com(w .. nick .. .. string.char(10) ..
  155. §8------------------------------------------------ .. string.char(10) ..
  156. COLOR_W2 .. -rep nick §8➢ .. COLOR_W1 .. Узнать репутацию игрока. .. string.char(10) ..
  157. COLOR_W2 .. -rep nick + §8➢ .. COLOR_W1 .. Повысить репутацию игрока. .. string.char(10) ..
  158. COLOR_W2 .. -rep nick - §8➢ .. COLOR_W1 .. Понизить репутацию игрока. .. string.char(10) ..
  159. COLOR_W2 .. -history nick §8➢ .. COLOR_W1 .. Показать последние изменения .. string.char(10) ..
  160. §8------------------------------------------------)
  161. elseif string.find(msg, -rep) ~= nil then
  162. if string.sub(msg, unicode.len(msg), unicode.len(msg)) ~= + and string.sub(msg, unicode.len(msg), unicode.len(msg)) ~= - then
  163. local name = string.sub(msg, 6, unicode.len(msg))
  164. if (fs.exists(shell.getWorkingDirectory() .. Rep .. name)) then
  165. local plus, minus = RepCheck(name)
  166. local reputation = plus - minus
  167. local COLOR_W3
  168. if reputation = 0 then
  169. COLOR_W3 = §2
  170. else
  171. COLOR_W3 = §4
  172. end
  173. Sky.Com(w .. nick .. .. string.char(10) ..
  174. §8------------------------------------------------ .. string.char(10) ..
  175. COLOR_W1 .. Репутация игрока .. COLOR_W2 .. name .. .. string.char(10) ..
  176. COLOR_W1 .. Рейтинг = .. COLOR_W3 .. reputation .. ❤ .. string.char(10) ..
  177. COLOR_W1 .. Положительных (+) = §2 .. plus .. string.char(10) ..
  178. COLOR_W1 .. Отрицательных (-) = §4 .. minus .. string.char(10) ..
  179. §8------------------------------------------------)
  180. else
  181. Sky.Com(w .. nick .. .. COLOR_W1 .. Игрок не имеет репутации)
  182. end
  183. else
  184. local name = string.sub(msg, 6, unicode.len(msg)-2)
  185. local value
  186. if string.sub(msg, unicode.len(msg), unicode.len(msg)) == + then
  187. value = +
  188. else
  189. value = -
  190. end
  191. if u(name) ~= nil then
  192. computer.removeUser(name)
  193. local text = RepChange(nick, name, value)
  194. local plus, minus = RepCheck(name)
  195. local reputation = plus - minus
  196. if #tab ~= 0 then
  197. tableCheck(name)
  198. tableAdd(name, reputation, plus, minus)
  199. else
  200. table.insert(tab, {name, reputation, plus, minus})
  201. end
  202. draw()
  203. TabSave()
  204. Sky.Com(w .. nick .. .. COLOR_W1 .. text)
  205. else
  206. Sky.Com(w .. nick .. .. COLOR_W1 .. Игрок не найден, либо оффлайн)
  207. end
  208. end
  209. elseif string.find(msg, -history) ~= nil then
  210. if msg == -history then
  211. Sky.Com(w .. nick .. .. COLOR_W1 .. Введите ник (-history nick))
  212. else
  213. local name = string.sub(msg, 10, unicode.len(msg))
  214. if (fs.exists(shell.getWorkingDirectory() .. Rep .. name)) then
  215. local hist = history(name)
  216. Sky.Com(w .. nick .. .. string.char(10) ..
  217. §8------------------------------------------------ .. string.char(10) ..
  218. COLOR_W1 .. История .. COLOR_W2 .. name .. COLOR_W1 .. .. string.char(10)
  219. .. hist ..
  220. §8------------------------------------------------)
  221. else
  222. Sky.Com(w .. nick .. .. COLOR_W1 .. Игрок не имеет репутации)
  223. end
  224. end
  225. end
  226. end
  227.  
  228. function draw()
  229. WIGHT, HEIGHT = Sky.Resolution(WIGHT,HEIGHT)
  230. Sky.Ram(OpenRep, COLOR1,COLOR2,WIGHT, HEIGHT, false)
  231.  
  232. g.setForeground(COLOR1)
  233. Sky.Mid(WIGHT, 3, Лучшие игроки сервера)
  234. Sky.Mid(WIGHT, HEIGHT-2, Чтобы пользоваться сис-мой рейтинга пропишите -rep)
  235.  
  236. for i = 1, #tab do
  237. Sky.Mid(WIGHT, i+4, &b .. tab[i][1] .. - &2Рейтинг .. tab[i][2] .. &b - (&2+ .. tab[i][3] .. &b&4- .. tab[i][4] .. &b))
  238. end
  239. end
  240.  
  241. draw()
  242.  
  243. while true do
  244. local _, _, nick, msg = event.pull(chat_message)
  245. if msg ~= nil and nick ~= nil then
  246. Message(msg, nick)
  247. end
  248. end
Add Comment
Please, Sign In to add comment