levshx

lx.lua

Jan 23rd, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.25 KB | None | 0 0
  1. -- lib by levshx
  2. -- include SkyDrive_ lib
  3.  
  4. local lx = {}
  5. local component = require("component")
  6. local computer=require("computer")
  7. local serial = require("serialization")
  8. local term = require("term")
  9. local event = require("event")
  10. local unicode = require("unicode")
  11. local fs = require("filesystem")
  12. local internet = require("internet")
  13. local gpu = component.gpu
  14. local version = 4
  15.  
  16. function lx.box()
  17.   local xScreen,yScreen = gpu.getResolution()
  18.   gpu.fill(1, 1, xScreen, 1, unicode.char(0x2836)) -- верхняя горизонтальная
  19.   gpu.fill(1, yScreen, xScreen, 1, unicode.char(0x2836))  -- нижняя горизонтальная
  20.   gpu.fill(1,1,1,yScreen,unicode.char(0x2588))  -- левая вертикальная
  21.   gpu.fill(xScreen,1,1,yScreen,unicode.char(0x2588)) -- правая вертикальная
  22.   gpu.set(1, 1, unicode.char(0x28f6)) -- левый верхний
  23.   gpu.set(xScreen, 1, unicode.char(0x28f6)) -- правый верхний
  24.   gpu.set(1, yScreen, unicode.char(0x283f)) -- левый нижний
  25.   gpu.set(xScreen, yScreen, unicode.char(0x283f)) -- правый нижний
  26. end
  27.  
  28. function lx.loading(procent,name)
  29.   local xScreen,yScreen = gpu.getResolution()  
  30.   gpu.fill(1, yScreen-1, math.modf((xScreen/100)*procent), 1, unicode.char(0x2588))
  31.   gpu.set(1,yScreen,name)
  32. end
  33.  
  34. function lx.logo(alignment, x, y) --вывод logo  
  35.   local xScreen,yScreen = gpu.getResolution()
  36.   local logo = {}
  37.   logo[1]="██╗░░░░░███████╗██╗░░░██╗░██████╗██╗░░██╗██╗░░██╗"
  38.   logo[2]="██║░░░░░██╔════╝██║░░░██║██╔════╝██║░░██║╚██╗██╔╝"
  39.   logo[3]="██║░░░░░█████╗░░╚██╗░██╔╝╚█████╗░███████║░╚███╔╝░"
  40.   logo[4]="██║░░░░░██╔══╝░░░╚████╔╝░░╚═══██╗██╔══██║░██╔██╗░"
  41.   logo[5]="███████╗███████╗░░╚██╔╝░░██████╔╝██║░░██║██╔╝╚██╗"
  42.   logo[6]="╚══════╝╚══════╝░░░╚═╝░░░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝"
  43.   logo[7]="                 levshx™ software                "
  44.   -- x-25
  45.   -- y-3
  46.   if alignment == "center" then
  47.     for i = 1, #logo do
  48.       gpu.set((math.modf(xScreen/2)-25),(math.modf(yScreen/2)-3)+i,logo[i])
  49.     end
  50.   else
  51.     if alignment == nil then
  52.       for i = 1, #logo do
  53.         gpu.set(x,y+i,logo[i])
  54.       end
  55.     end    
  56.   end
  57. end
  58.  
  59.  
  60. function lx.com(command) --Командный блок    
  61.   if (component.isAvailable("opencb")) then
  62.     local _,c = component.opencb.execute(command)
  63.     return c
  64.   else
  65.     return nil
  66.   end
  67. end
  68.  
  69. function lx.money(nick) --Баланс игрока
  70.   local c = lx.com("money " .. nick)
  71.   local _, b = string.find(c, "Баланс: §f")
  72.   local balance
  73.   if b == nil then
  74.     balance = "0.00"
  75.   elseif string.find(c, "Emeralds") ~= nil then
  76.     balance = unicode.sub(c, b - 16, unicode.len(c) - 10)
  77.   else
  78.     balance = unicode.sub(c, b - 16, unicode.len(c) - 9)
  79.   end  
  80.   return (balance)
  81. end
  82.  
  83.  
  84. function lx.checkMoney(nick,price) --Чекнуть, баланс, если хватает, то снять бабки
  85.   local balance = lx.money(nick)
  86.   balance = string.sub(balance, 1, string.len(balance) - 3)
  87.   if string.find(balance, "-") ~= nil then
  88.     return false
  89.   else
  90.     balance = string.gsub(balance,",","")
  91.     if tonumber(balance) < price then
  92.       return false
  93.     else
  94.       lx.com("money take " .. nick .. " " .. price)
  95.       return true
  96.     end
  97.   end
  98. end
  99.  
  100. function lx.takeItem(nick, item, numb) --Забрать итем
  101.   if string.find(lx.com("clear " .. nick .. " " .. item .. " " .. numb), "Убрано") ~= nil then
  102.     return true
  103.   else
  104.     return false
  105.   end
  106. end
  107.  
  108. function lx.giveItem(nick, item, numb) --Выдать предмет и чекнуть влезло ли в инвентарь, если нет, вернуть остаток
  109.   local text = lx.com("egive " .. nick .. " " .. item .. " " .. numb)
  110.  
  111.   if string.find(text, "Недостаточно свободного места") ~= nil then
  112.     local _, b = string.find(text, "Недостаточно свободного места, §c")
  113.    
  114.     local i = 0
  115.     local ostatok = ""
  116.     while (ostatok ~= " ") do
  117.       i = i + 1
  118.       ostatok = string.sub(text, b+i, b+i)
  119.     end
  120.     ostatok = string.sub(text, b+1, b+i-1)
  121.     ostatok = string.gsub(ostatok,",","")
  122.     return ostatok
  123.   else
  124.     return 0
  125.   end
  126. end
  127.  
  128.  
  129. function lx.setColor(index) --Список цветов
  130.   if (index ~= "r") then back = gpu.getForeground() end
  131.   if (index == "0") then gpu.setForeground(0x333333) end
  132.   if (index == "1") then gpu.setForeground(0x0000ff) end
  133.   if (index == "2") then gpu.setForeground(0x00ff00) end
  134.   if (index == "3") then gpu.setForeground(0x24b3a7) end
  135.   if (index == "4") then gpu.setForeground(0xff0000) end
  136.   if (index == "5") then gpu.setForeground(0x8b00ff) end
  137.   if (index == "6") then gpu.setForeground(0xffa500) end
  138.   if (index == "7") then gpu.setForeground(0xbbbbbb) end
  139.   if (index == "8") then gpu.setForeground(0x808080) end
  140.   if (index == "9") then gpu.setForeground(0x0000ff) end
  141.   if (index == "a") then gpu.setForeground(0x66ff66) end
  142.   if (index == "b") then gpu.setForeground(0x00ffff) end
  143.   if (index == "c") then gpu.setForeground(0xff6347) end
  144.   if (index == "d") then gpu.setForeground(0xff00ff) end
  145.   if (index == "e") then gpu.setForeground(0xffff00) end
  146.   if (index == "f") then gpu.setForeground(0xffffff) end
  147.   if (index == "g") then gpu.setForeground(0x00ff00) end
  148.   if (index == "r") then gpu.setForeground(back) end
  149. end
  150.  
  151. function lx.text(x,y,text) --Цветной текст
  152.   local n = 1
  153.   for i = 1, unicode.len(text) do
  154.     if unicode.sub(text, i,i) == "&" then
  155.       lx.setColor(unicode.sub(text, i + 1, i + 1))
  156.     elseif unicode.sub(text, i - 1, i - 1) ~= "&" then
  157.       gpu.set(x+n,y, unicode.sub(text, i,i))
  158.       n = n + 1
  159.     end
  160.   end
  161. end
  162.  
  163. return lx
Add Comment
Please, Sign In to add comment