Advertisement
ReBraLaCC

Scoreboard revamped

Oct 25th, 2016
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.59 KB | None | 0 0
  1. -- Local functions (only usable in the program itself not in the api)
  2.  
  3. local object = {}
  4. object.__index = object
  5. --local scoreboard = commands.scoreboard
  6. local titleObj
  7. local orri
  8.  
  9. local colorTable = {
  10.     mcColor = {
  11.         "black",
  12.         "dark_blue",
  13.         "dark_green",
  14.         "dark_aqua",
  15.         "dark_red",
  16.         "dark_purple",
  17.         "gold",
  18.         "gray",
  19.         "dark_gray",
  20.         "blue",
  21.         "green",
  22.         "aqua",
  23.         "red",
  24.         "light_purple",
  25.         "yellow",
  26.         "white",
  27.     },
  28.  
  29.     ccColor = {
  30.         [colors.lightGray] = "gray",
  31.         [colors.green] = "dark_green",
  32.         [colors.lime] = "green",
  33.         [colors.blue] = "blue",
  34.         [colors.lightBlue] = "aqua",
  35.         [colors.gray] = "dark_gray",
  36.         [colors.pink] = "light_purple",
  37.         [colors.black] = "black",
  38.         [colors.purple] = "dark_purple",
  39.         [colors.red] = "red",
  40.         [colors.white] = "white",
  41.     }
  42.  
  43. }
  44.  
  45. local match = false
  46.  
  47. local function getTeam(team)
  48.     ret = scoreboard("teams join "..team.." test")
  49.     if ret then
  50.         scoreboard("teams leave "..team.." test")  
  51.     end
  52.     return ret
  53. end
  54.  
  55. -- klaar soort van
  56. function new(type)
  57.     if type == "line" then
  58.         return function (text,value,color)
  59.                 local raw = {}
  60.                 setmetatable(raw,object)
  61.                 raw.text = text  
  62.                 raw.value = value
  63.                 raw.color = color
  64.                 raw.type = "line"
  65.                 function raw:getValue()
  66.                     return self.value
  67.                 end
  68.                 function raw:getText()
  69.                     return self.text
  70.                 end
  71.                 function raw:getColor()
  72.                     return self.color
  73.                 end
  74.                 function raw:getType()
  75.                     return self.type
  76.                 end
  77.                 return raw
  78.             end
  79.     elseif type == "title" then
  80.         return function (text)
  81.                 local raw = {}
  82.                 setmetatable(raw,object)
  83.                 raw.text = text
  84.                 raw.type = "title"
  85.                 function raw:getText()
  86.                     return self.text
  87.                 end
  88.                 function raw:getType()
  89.                     return self.type
  90.                 end
  91.                 return raw
  92.             end
  93.     elseif type == "board" then    
  94.  
  95.         return function (obj)
  96.             local raw = {}
  97.             setmetatable(raw,object)
  98.             raw.text = text
  99.             raw.type = "board"
  100.             raw.objects = obj
  101.             raw.title = checkForTitle(obj):getText()
  102.            
  103.             function raw:generate()
  104.                 scoreboard("objectives add "..self.title.." dummy")
  105.                 for k,v in pairs(objects) do
  106.                     if v:getType() == "line" then
  107.                         scoreboard("players set "..v:getText().." "..self.title.." "..v:getValue())
  108.                         setColor(v)
  109.                     end
  110.                 end
  111.                 return true
  112.             end
  113.            
  114.             function raw:delete()
  115.                 scoreboard("objectives remove "..self.title)
  116.                 return true
  117.             end
  118.            
  119.             function raw:showTo(playerTable)
  120.                 playerTable = playerTable or {"@a"}
  121.                 for k,v in pairs(playerTable) do
  122.                     scoreboard("objectives setdisplay sidebar "..v)
  123.                 end
  124.                 return true
  125.             end
  126.            
  127.             return raw
  128.         end
  129.     end
  130. end
  131.  
  132. function checkForTitle(objects)
  133.     for k,v in pairs(objects) do
  134.         if objects[k]:getType() == "title" then
  135.             return objects[k]
  136.         end
  137.     end
  138.     return false
  139.    
  140.    
  141. end
  142.  
  143. function setColor(obj)
  144.     local name = obj:getText()
  145.     local color = obj:getColor()
  146.    
  147.     for k,v in pairs(colorTable.mcColor) do
  148.         if color == v then
  149.             match = true
  150.         else
  151.             match = false
  152.         end
  153.        
  154.         if match then break end
  155.     end
  156.    
  157.     if not match then
  158.         if colorTable.ccColor[color] then
  159.             color = colorTable.ccColor[color]
  160.             match = true
  161.         end
  162.     end
  163.    
  164.     if match then
  165.         scoreboard("teams join "..color.." "..name)
  166.         match = false
  167.     else
  168.         error("Color: "..color.." does not exist!",2)
  169.     end
  170.    
  171.    
  172. end
  173.  
  174. function init()
  175.     for k,v in pairs(colorTable.mcColor) do
  176.         if not getTeam(v) then
  177.             scoreboard("teams add "..v)
  178.             scoreboard("teams option "..v.." color "..v)
  179.         end
  180.     end
  181. end
  182.  
  183. function removeTeams()
  184.     for k,v in pairs(colorTable.mcColor) do
  185.         scoreboard("teams remove "..v)
  186.     end
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement