Yung_Lungs

Job Points ranking in 3D GUI

Recommended Posts

Hello I have, going to do a ranking of players where considered to be, and their quantity. The entry points I made to the MySQL database, there is written the number of points, the player and continuously updated. 3D GUI also I have done, I give the code below. I would like to make in this GUI was displayed ranking 10 or 5 players with the most points. I have no idea how I make such a ranking. This is beyond my skills.

Here is the code for 3D GUI:

local renderTarget = dxCreateRenderTarget(1000, 1000, true)
local X, Y, Z = -345.5341796875, -1031.6298828125, 59.296432495117
local title_font = dxCreateFont(":server_fonts/main_font.ttf", 63)
local ranking_font = dxCreateFont(":server_fonts/main_font.ttf", 50)

addEventHandler("onClientRender", root, function()
		dxSetRenderTarget(renderTarget, true)
			dxDrawRectangle( 0, 0, 1000, 700, tocolor(72, 71, 81, 190)) -- Background
			dxDrawText("Job Ranking", 0, 0, 1000, 100, tocolor(255, 255, 255, 255), 1, title_font, "center", "center") -- Text
				dxDrawText("1. ", -830, 300, 1000, 50, tocolor(255, 255, 255, 255), 1, ranking_font, "center", "center") -- Text
		dxSetRenderTarget()
		dxDrawMaterialLine3D( X, Y, Z + 5, X, Y, Z, renderTarget, 5, tocolor(255, 255, 255, 255), -2000, 0, 0)
end)

 

Share this post


Link to post

You could easily do query below to get top 10 points

SELECT * FROM your_table SORT BY `points` DESC LIMIT 10

Or, you can fetch all data from SQL then store it to LUA table

SELECT * FROM `your_table`

Every time resource started, and store it to LUA table.

addEventHandler("onResourceStart", resourceRoot,
  function ()
    local Q = dbQuery = (connection, "SELECT * FROM `your_table_here`")
    local result = dbPoll(Q, -1)
    points = result
  end
)

Then send it to client using triggerClientEvent

And sort it on client side like below. And do iteration to output correct ranking position

points = {} -- this table from mysql query

table.sort(points, function (a, b) return a.points > b.points end) -- sort table based on their points descending
for i, v in pairs(points)  do
	-- Your dx output and coordinate calculation here
end

And do not forget to update the table for every point change and send it to client, so player get the realtime data.

Edited by idarrr
Code mistake
  • Like 1

Share this post


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.