Jump to content

ID on Scoreboard


xXGhostXx

Recommended Posts

Hi guys !

i maked ID System !

i have problem id dont show on scoreboard !

but i make column !

in score board show Column (ID) but dont show player id !

call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "ID" ) ---Export of ScoreBoard
local ids,playerid = {},nil,nil,{}
if not ids[player] then
	playerid = getElementData( player, "id" )
	ids[player] = playerid
		else
			playerid = ids[player]
		end

what is problem ?

Edited by xXGhostXx
Link to comment
6 minutes ago, xXGhostXx said:

	_getPlayerID = getPlayerID
	function getPlayerID(player)
		return nil
	end

i write this code but dont work !

please give me fix code !

Did you fix the you sent code before this one ?
And there no problem on this code.
I think you should know that this code is useless because you will return 'nil'.

Edited by iMr.WiFi..!
Link to comment
Just now, iMr.WiFi..! said:

Did you fix the code before this one ?
And there no problem on this code.
I think you should know that this code is useless because you will return 'nil'.

call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "ID" ) ---Export of ScoreBoard
local ids,playerid = {},nil,nil,{}
if not ids[player] then
	playerid = getElementData( player, "id" )
	ids[player] = playerid
		else
			playerid = ids[player]
		end

My main code !

Please fix problem in this code !

ID System code :

local ID = { }

function newPlayerID( player )
	for i = 1, getMaxPlayers( ) do
		if not ( ID[ i ] ) then
			ID[ i ] = player
			setElementData( player, "id", i )
			break
		end
	end
end

function getPlayerByID( id )
	for i = 1, getMaxPlayers( ) do
		if ( ID[ i ] ) then
			print( getPlayerName( ID[ i ] ) )
			return ID[ i ]
		end
	end
end

addEventHandler( "onPlayerQuit", root,
	function( )
		for i = 1, getMaxPlayers do
			if ( ID[ i ] == source ) then
				ID[ i ] = nil
				break
			end
		end
	end
)

addEventHandler( "onPlayerJoin", root, function( ) newPlayerID( source ) end )
addEventHandler( "onResourceStart", resourceRoot, function( ) local players = getElementsByType( "player" ) for i = 1, #players do newPlayerID( players[ i ] ) end end )

 

Link to comment
local ID = { }

function newPlayerID( player )    	
	local players = getElementsByType( "player" ) 
	for i = 1, #players do 
		if not ( ID[ i ] ) then
			ID[ i ] = player
			setElementData( player, "id", i )
			break
		end
	end
end

function getPlayerByID( id )    	
  	local players = getElementsByType( "player" ) 
  	for i = 1, #players do 
		if ( ID[ i ] ) then
			print( getPlayerName( ID[ i ] ) )
		end
	end
end

addEventHandler( "onPlayerQuit", root,
	function( )
    		local players = getElementsByType( "player" ) 
    		if( #players > 1 )then
    			for i = 1, #players do 
				if ( ID[ i ] == source ) then
					ID[ i ] = nil
					break
				end
			end
		end
	end
)

addEventHandler( "onPlayerJoin", root, function( ) newPlayerID( source ) end )
addEventHandler( "onResourceStart", resourceRoot, function( ) 
    local players = getElementsByType( "player" ) 
    if( #players ~= 0 )then
    	for i, player in ipairs( players ) do 
		ID[ i ] = player
		setElementData( player, "id", i )
    	end
	end 
end )

 

Edited by iMr.WiFi..!
Additional checks
Link to comment

nvm i confused here you go

ID = {}

exports["scoreboard"]:scoreboardAddColumn("ID", root, 20, "ID", 1)

------------------------- [ Events ] --------------------------

addEventHandler("onPlayerJoin", root, 
function()
    for i = 1, getMaxPlayers() do
	    if not ID[i] then
		   ID[i] = source
		   setElementData(source, "ID", i)
		   break
		end
	end
end)

--

addEventHandler("onPlayerQuit", root, 
function()
    ID[getPlayerID(source)] = nil
end)

--

addEventHandler("onResourceStart", resourceRoot, 
function()
    for _, v in ipairs(getElementsByType("player")) do
	    for i = 1, getMaxPlayers() do
		    if not ID[i] then
			   ID[i] = v
			   setElementData(v, "ID", i)
			   break
			end
		end
	end
end)

------------------------- [ Functions ] -----------------------

function getPlayerID(player)
    if player and isElement(player) and getElementType(player) == "player" then
	   return getElementData(player, "ID")
	end
	return false
end

--

function getPlayerFromID(id)
    if id and tonumber(id)  then
	   return ID[tonumber(id)]
	end
	return false
end

 

Edited by Dimos7
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...