Jump to content

Question


TheGuyNL

Recommended Posts

Is there an event for when a new map loads? I need my cash in the scoreboard to update after a new map loads, how do I do this?

Here is my script:

exports["scoreboard"]:scoreboardAddColumn("Cash") 
exports["scoreboard"]:scoreboardAddColumn("Points") 
  
function setStats(player) 
    local account = getPlayerAccount(player) 
    if (account) then 
    local cash = getAccountData(account, "cash") 
    local points = getAccountData(account, "points") 
    setElementData ( player, "Cash", "$" ..cash.. "" ) 
    setElementData ( player, "Points", points ) 
    else 
    setElementData ( player, "Cash", "guest" ) 
    setElementData ( player, "Points", "guest" ) 
    end 
end 
  
function timer() 
    setTimer( setStats, 1000, 1, source ) 
end 
addEventHandler("onPlayerLogin", getRootElement(), timer) 
addEventHandler("onPlayerJoin", getRootElement(), timer) 
  

Link to comment
exports.scoreboard:addScoreboardColumn('Cash') 
function fCashShow ( ) 
    setElementData( source,"Cash",getPlayerMoney( source ) ) 
end 
addEventHandler( 'onPlayerJoin', root, fCashShow ) 

This is my for cash if it helps you.

Link to comment
exports[ "scoreboard" ]:scoreboardAddColumn ( "Cash" ) 
exports[ "scoreboard" ]:scoreboardAddColumn ( "Points" ) 
  
function setStats ( player ) 
    if ( not player or not isElement ( player ) ) then 
        return 
    end 
    local account = getPlayerAccount ( player ) 
    if ( account and not isGuestAccount ( account ) ) then 
        local cash = getAccountData ( account, "cash" ) 
        local points = getAccountData ( account, "points" ) 
        setElementData ( player, "Cash", "$" .. cash or 0 ) 
        setElementData ( player, "Points", points or 0 ) 
    else 
        setElementData ( player, "Cash", "guest" ) 
        setElementData ( player, "Points", "guest" ) 
    end 
end 
  
function timer() 
    setTimer( setStats, 1000, 1, source ) 
end 
addEventHandler("onPlayerLogin", getRootElement(), timer) 
addEventHandler("onPlayerJoin", getRootElement(), timer) 
  
addEvent ( "onMapStarting", true ) 
addEventHandler ( "onMapStarting", root, 
    function ( ) 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            setStats ( player ) 
        end 
    end 
) 

Link to comment
exports[ "scoreboard" ]:scoreboardAddColumn ( "Cash" ) 
exports[ "scoreboard" ]:scoreboardAddColumn ( "Points" ) 
  
function setStats ( player ) 
    if ( not player or not isElement ( player ) ) then 
        return 
    end 
    local account = getPlayerAccount ( player ) 
    if ( account and not isGuestAccount ( account ) ) then 
        local cash = getAccountData ( account, "cash" ) 
        local points = getAccountData ( account, "points" ) 
        setElementData ( player, "Cash", "$" .. cash or 0 ) 
        setElementData ( player, "Points", points or 0 ) 
    else 
        setElementData ( player, "Cash", "guest" ) 
        setElementData ( player, "Points", "guest" ) 
    end 
end 
  
function timer() 
    setTimer( setStats, 1000, 1, source ) 
end 
addEventHandler("onPlayerLogin", getRootElement(), timer) 
addEventHandler("onPlayerJoin", getRootElement(), timer) 
  
addEvent ( "onMapStarting", true ) 
addEventHandler ( "onMapStarting", root, 
    function ( ) 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            setStats ( player ) 
        end 
    end 
) 

Thanks! This works great.

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