Jump to content

little problem


Wei

Recommended Posts

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

Link to comment

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) 

Link to comment

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]

Link to comment

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 
) 

Link to comment

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.

Link to comment
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?

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