Wei Posted April 27, 2012 Posted April 27, 2012 local pGroup; call ( getResourceFromName ( 'scoreboard' ), 'addScoreboardColumn', 'Group' ); function addRoleToScoreboard() local data = getElementData(source, "role") if data == police then pGroup = "Police Officer"; end setElementData ( source, 'Group', pGroup ); end addEventHandler("onClientRender", root, addRoleToScoreboard) no errors in debug. Problem: it doesn't show the group
arezu Posted April 27, 2012 Posted April 27, 2012 if there are no errors, then you should debug it yourself like this: local pGroup; call ( getResourceFromName ( 'scoreboard' ), 'addScoreboardColumn', 'Group' ); function addRoleToScoreboard() local data = getElementData(source, "role") dxDrawText("data: "..tostring(data), 500, 300) dxDrawText("police: "..tostring(police), 500, 350) if data == police then dxDrawText("data == police", 500, 400) pGroup = "Police Officer"; end dxDrawText("pGroup: "..tostring(pGroup), 500, 450) setElementData ( source, 'Group', pGroup ); end addEventHandler("onClientRender", root, addRoleToScoreboard)
Wei Posted April 28, 2012 Author Posted April 28, 2012 now i've remaded the code: setTimer( function () call ( getResourceFromName ( 'scoreboard' ), 'addScoreboardColumn', 'Group' ); local role = getElementData(sourcePlayer,'role') if role == tostring(police) then setElementData ( sourcePlayer, 'Group','Police'); end end ,5000,0) naz helped me. Whats the problem here ? ERROR: [2012-04-28 21:42:21] WARNING: testing\server.lua:5: Bad argument @ 'getElementData' [Expected element at argument 1, got nil]
Castillo Posted April 29, 2012 Posted April 29, 2012 I guess "police" variable is defined, right? call ( getResourceFromName ( 'scoreboard' ), 'addScoreboardColumn', 'Group' ) setTimer ( function ( ) for index, player in ipairs ( getElementsByType ( "player" ) ) do local role = getElementData ( player, 'role' ) if ( role == tostring ( police ) ) then setElementData ( player, 'Group', 'Police' ) end end end ,5000, 0 )
Michael# Posted April 29, 2012 Posted April 29, 2012 I think you can simplify all to: exports [ 'scoreboard' ]:addScoreboardColumn ( 'Group' ) setTimer ( function ( ) for _, player in ipairs ( getElementsByType 'player' ) do local data = getElementData ( player, 'role' ) setElementData ( player, 'Group', tostring ( data ) == tostring ( police ) and 'Police' or nil ) end end, 5000, 0 ) If don't work, show us what is "police" variable.
Kenix Posted April 29, 2012 Posted April 29, 2012 exports [ 'scoreboard' ]:addScoreboardColumn 'Group' setTimer ( function ( sPolice ) for _, pPlayer in ipairs ( getElementsByType 'player' ) do setElementData ( pPlayer, 'Group', tostring ( getElementData ( pPlayer, 'role' ) ) == tostring ( sPolice ) and 'Police' ) end end, 5000, 0, police ) Blazy your variable 'police' is defined?
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