TheGuyNL Posted March 22, 2012 Share Posted March 22, 2012 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
Wei Posted March 22, 2012 Share Posted March 22, 2012 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
Castillo Posted March 22, 2012 Share Posted March 22, 2012 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
TheGuyNL Posted March 22, 2012 Author Share Posted March 22, 2012 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
TheGuyNL Posted March 22, 2012 Author Share Posted March 22, 2012 Something else, what is the function to restart a map? to make a command like /redo Link to comment
Castillo Posted March 22, 2012 Share Posted March 22, 2012 You can get the current map with: exports.mapmanager:getRunningGamemodeMap() and change it with this: exports.mapmanager:changeGamemodeMap() Link to comment
TheGuyNL Posted March 22, 2012 Author Share Posted March 22, 2012 You can get the current map with: exports.mapmanager:getRunningGamemodeMap() and change it with this: exports.mapmanager:changeGamemodeMap Again, thanks alot. 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