Jump to content

Help with scoreboard


golanu21

Recommended Posts

    exports.scoreboard:scoreboardAddColumn( "WantedLv" ) 
function getwan() 
local players = getElementsByType ( "player" ) 
for theKey,source in ipairs(players) do 
local wanted = getPlayerWantedLevel(source) 
local zero = "" 
local one = "*" 
local two = "**" 
local three = "***" 
local four = "****" 
local five = "*****" 
local six = "******" 
    if wanted == 0 then 
        setElementData ( source, "Wanted", zero ) 
    else if wanted == 1 then 
        setElementData ( source, "Wanted", one ) 
    else if wanted == 2 then 
        setElementData ( source, "Wanted", two ) 
    else if wanted == 3 then 
        setElementData ( source, "Wanted", three ) 
    else if wanted == 4 then 
        setElementData ( source, "Wanted", four ) 
    else if wanted == 5 then 
        setElementData ( source, "Wanted", five ) 
    else if wanted == 6 then 
        setElementData ( source, "Wanted", six ) 
        end 
    end 
end 
end 
end 
end 
end 
end 
end 
setTimer(getwan,100,0) 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), getwan ) 

the column appear in the scoreboard, but when i have wanted level > 0 the stars (**) not appear :(

Link to comment

Easier way:

exports[ "scoreboard" ]:scoreboardAddColumn ( "WantedLv" ); 
local lastTick = getTickCount(); 
  
function SetWantedLevel() 
    if ( eventName == "onClientRender" ) then 
        if ( ( getTickCount() - lastTick ) < 500 ) then 
            return 
        end 
        lastTick = getTickCount(); 
    end 
     
    for index, value in ipairs ( getElementsByType "player" ) do 
        local wantedLevel = ( "*" ):rep ( getPlayerWantedLevel ( value ) ); 
        setElementData ( value, "WantedLv", wantedLevel ); 
    end 
end 
addEventHandler ( "onResourceStart", resourceRoot, SetWantedLevel ); 
addEventHandler ( "onClientRender", root, SetWantedLevel ); 

There might be a problem with time counting, I'm not awesome with maths. If someone finds any error in my code, please let me know.

Edited by Guest
Link to comment

Yeah, I also know it so. But lastTick is a tick count in the past, and getTickCount() will return the current tick count wich will be bigger than lastTick I think. If I'm right then "if ( lastTick - getTickCount() < 500 ) then" doesn't have much sense.

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