Jump to content

Level Rank on scoreboard


SoManyTears

Recommended Posts

Hi Forum,ı want to say that ı am new in scripting and now ı am starting to try element datas.ı want to add rank in scoreboard acording to the number of levels.ı know ı cant do the codes below.can someone give me an example how can ı do this ? ı just want to show it on the scoreboard.Thank you from now.

exports.scoreboard:addScoreboardColumn('Rank')
 
addEventHandler("onPlayerSpawn",root,
function()
if getElementData(source,"level") >= 1 then
setElementData(source, "Rank", "test") 
elseif getElementData(source,"level") >= 5 then
setElementData(source, "Rank", "test1") 
elseif getElementData(source,"level") >= 10 then
setElementData(source, "Rank", "test2") 
elseif getElementData(source,"level") >= 15 then
setElementData(source, "Rank", "test3") 
elseif getElementData(source,"level") >= 20 then
setElementData(source, "Rank", "test4") 
elseif getElementData(source,"level") >= 25 then
setElementData(source, "Rank", "test5") 
end
end
)

addEventHandler("onPlayerSpawn",root,
function ()
    local rank = getElementData(source,"level")
    if rank then
        setElementData(source,"Rank", rank)
end
end
)

 

Link to comment

I don't quite get why your ranking system does not work, maybe you forgot to set anything to the element data "level" and its giving you an error because you are trying to compare a boolean with a number?

Anyway, i made this mess, have fun trying to understand it, I hope you can

exports.scoreboard:addScoreboardColumn('Rank')

local ranking_table = {
	-- You would need at least level 1 to unlock this rank
	-- This table stores itself like this: {minimum level to obtain the rank, the name of the rank}
	{1, "Noobie"},
	{5, "idk"},
	{10, "just put your ranks in here"},
}

function onSpawn()
	-- When you spawn, your current lvl would be stored in this variable, so we can check it later
	local lvl = getElementData(source, "level") or 1
	
	-- Then we will "travel" arround the table until from the last index to the first (in this case from 3 to 1)
	-- until we find that a rank requieres the same or lower level to adquire, so we set that to the player and we
	-- stop checking the table using break (some programmers/scripters would say that using break is a bad practice
	-- but w/e)
	for i=#ranking_table,1,-1 do
		if raking_table[i][1] <= lvl then
			setElementData(source, "Rank", ranking_table[i][2])
			break;
		end
	end
	
	-- This should work just fine, but i didn't test it so, idk
end
addEventHandler("onPlayerSpawn", root, onSpawn)

 

Edited by Platin - xNikoXD
Link to comment

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...