Jump to content

How should i make a scoreboard?


Recommended Posts

Well the question is, which part you don't know? The scrolling part? Drawing part? Maybe sorting? There's a function I wrote in one of the websites I developed that had pagination, I think the basic idea can be applied to the scoreboard as well. This code might help you with the scrolling:

local players = {} -- dummy player table
local itemOnPage = 10 -- maximum 10 players / page
local currPage = 3 -- get the players on page 3
for i = 1, 35 do -- create 35 dummy players
  table.insert(players, 'plr ID: ' .. i)
end

function getMaxPage()
  print( "Maximum pages (starts from 0): " .. math.ceil(#players / itemOnPage))
end

function currPageItems() -- reads in currPage var. and returns the players that belong to that particular page
  local returnedPlayers = {}
  	-- loop from the start of the page, ie if currPage * itemOnPage = 3 * 10 = 30 is our starting point
  	-- loop until currPage + 1 * itemOnPage = (3 + 1) * 10 = 40
    for i = currPage * itemOnPage, (currPage + 1) * itemOnPage do 
      if players[i] then -- the last page might not have full list
        table.insert(returnedPlayers, i) -- this table will be returned, which you can use in your onClientRender
      else
        break
      end
    end
  return returnedPlayers
end

getMaxPage()

for k, v in ipairs(currPageItems()) do
  print(players[v]) -- get a list of players depending on the variable: currPage and print their 'names'
end

All you have to do is manually (using binds, ie. mouse scroll) change the variable currPage + 1 or currPage - 1.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...