xXGhostXx Posted September 26, 2018 Share Posted September 26, 2018 (edited) 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 September 26, 2018 by xXGhostXx Link to comment
iMr.WiFi..! Posted September 26, 2018 Share Posted September 26, 2018 (edited) Line 2, You make values more than you made in defines. Player isn't defined Check from scoreboard resource name. Edited September 26, 2018 by iMr.WiFi..! Link to comment
xXGhostXx Posted September 26, 2018 Author Share Posted September 26, 2018 3 minutes ago, iMr.WiFi..! said: Line 2, you make values more than you made in defines. player isn't definedcheck from scoreboard resource name. _getPlayerID = getPlayerID function getPlayerID(player) return nil end i write this code but dont work ! please give me fix code ! Link to comment
iMr.WiFi..! Posted September 26, 2018 Share Posted September 26, 2018 (edited) 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 September 26, 2018 by iMr.WiFi..! Link to comment
xXGhostXx Posted September 26, 2018 Author Share Posted September 26, 2018 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
xXGhostXx Posted September 26, 2018 Author Share Posted September 26, 2018 1 minute ago, Dimos7 said: No going to work This is your help ? Link to comment
iMr.WiFi..! Posted September 26, 2018 Share Posted September 26, 2018 (edited) 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 September 26, 2018 by iMr.WiFi..! Additional checks Link to comment
xXGhostXx Posted September 26, 2018 Author Share Posted September 26, 2018 18 minutes ago, xXGhostXx said: _getPlayerID = getPlayerID function getPlayerID(player) return nil end i write this code but dont work ! please give me fix code ! And i use this code ? Link to comment
Dimos7 Posted September 26, 2018 Share Posted September 26, 2018 i had give you a ccode working perfectly Link to comment
xXGhostXx Posted September 26, 2018 Author Share Posted September 26, 2018 1 minute ago, Dimos7 said: i had give you a ccode working perfectly Me ? Link to comment
Dimos7 Posted September 26, 2018 Share Posted September 26, 2018 (edited) 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 September 26, 2018 by Dimos7 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now