proracer Posted February 12, 2011 Share Posted February 12, 2011 Hello guys, me and my friend have been now working on stats system. It doesn't give any errors. It should give points, cash and set new player's rank if he has specified amount of points. function onPlayerSetData ( ) local playeracc = getPlayerAccount ( source ) if ( playeracc ) then getAccountData ( playeracc, "data.cash" ) getAccountData ( playeracc, "data.points" ) getAccountData ( playeracc, "data.wins" ) getAccountData ( playeracc, "data.rank" ) else local playercash = 0 local playerwins = 0 local playerpoints = 0 local playerrank = "Beginner" setAccountData ( playeracc, "data.cash", playercash ) setAccountData ( playeracc, "data.wins", playerwins ) setAccountData ( playeracc, "data.points", playerpoints) setAccountData ( playeracc, "data.rank", playerrank ) outputChatBox ( "Loading stats for" .. playeracc, root, 0, 252, 255, false ) end end addEventHandler ( "onPlayerLogin", root, onPlayerSetData ) function onPlayerQuitSetData ( ) local playeracc = getPlayerAccount ( source ) if ( playeracc ) then setAccountData ( playeracc, "data.cash", getAccountData ( playeracc, "data.cash" ) ) setAccountData ( playeracc, "data.points", getAccountData ( playeracc, "data.points" ) ) setAccountData ( playeracc, "data.wins", getAccountData ( playeracc, "data.wins" ) ) setAccountData ( playeracc, "data.rank", getAccountData ( playeracc, "data.rank" ) ) end end addEventHandler ( "onPlayerQuit", root, onPlayerQuitSetData ) addEventHandler ( "onPlayerLogout", root, onPlayerQuitSetData ) -- Cash, Points and Rank function onGiveCashAndPtsAndRankToPlayer ( mapInfo ) info = mapInfo.modename if ( info ) == "Destruction derby" then local alivePlayers = getAlivePlayers ( ) if #alivePlayers == 1 then local playeracc = getPlayerAccount ( alivePlayers[1] ) if ( playeracc ) then local Cash1 = getAccountData ( playeracc, "data.cash" ) local Cash2 = 250 * getPlayerCount ( ) local Cash3 = Cash1 + Cash2 local Points1 = getAccountData ( playeracc, "data.points" ) local Points2 = 2 * getPlayerCount ( ) local Points3 = Points1 + Points2 -- Rank 1 if Points1 >= 10 then setAccountData ( playeracc, "data.rank", "Newbie" ) outputChatBox ( playeracc .. " has advanced to a new rank: 'Newbie' ", root, 0, 252, 255, false ) end -- Rank 2 if Points1 >= 25 then setAccountData ( playeracc, "data.rank", "Rookie" ) outputChatBox ( playeracc.. " has advanced to a new rank: 'Rookie' ", root, 0, 252, 255, false ) end -- Rank 3 if Points >= 50 then setAccountData ( playeracc, "data.rank", "Amateur" ) outputChatBox ( playeracc.. " has advanced to a new rank: 'Amateur' ", root, 0, 252, 255, false ) end setAccountData ( playeracc, "data.cash", Cash3 ) setAccountData ( playeracc, "data.points", Points3 ) outputChatBox (alivePlayers[1] .. " got " .. Cash3 " $ for suriving ", root, 0, 252, 255, false ) end end end end addEventHandler ( "onPlayerWasted", root, onGiveCashAndPtsAndRankToPlayer ) -- Public stats function playerStats ( source ) local playeracc = getPlayerAccount ( source ) local playercash = getAccountData ( playeracc, "data.cash" ) or 0 local playerpoints = getAccountData ( playeracc, "data.points" ) or 0 local playerrank = getAccountData ( playeracc, "data.rank" ) or "Beginner" if ( playeracc ) then outputChatBox ( "*" .. getPlayerName ( source ) .. " 's Stats: ", root, 0, 252, 255, false ) outputChatBox ( "* Cash Earned: " .. tonumber ( playercash ) .. " $ ", root, 0, 252, 255, false ) outputChatBox ( "* Points Earned: " .. tonumber ( playerpoints ) .. " Points", root, 0, 252, 255, false ) outputChatBox ( "* Current Rank: " .. playerrank, root, 0, 252, 255, false) end end addCommandHandler ( "stats", playerStats ) Edit: I edited the script a bit but still gives no error... Link to comment
SDK Posted February 12, 2011 Share Posted February 12, 2011 This script doesn't make sense, did you even test while making it? You don't put together a bunch of code and hope it works afterwards ... -- player joined function getAccountData ( playeracc, "data.cash" ) getAccountData ( playeracc, "data.points" ) getAccountData ( playeracc, "data.wins" ) getAccountData ( playeracc, "data.rank" ) This doesnt do anything, you probably want to store them in some variables, or set it as element data on a player -- player leaves function setAccountData ( playeracc, "data.cash", getAccountData ( playeracc, "data.cash" ) ) setAccountData ( playeracc, "data.points", getAccountData ( playeracc, "data.points" ) ) setAccountData ( playeracc, "data.wins", getAccountData ( playeracc, "data.wins" ) ) setAccountData ( playeracc, "data.rank", getAccountData ( playeracc, "data.rank" ) ) And this doesnt do anything either, you're getting the account data and then set the SAME account data again ... Correct your script to use element data and then come back, cause now it's just random. 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