Chronic Posted December 27, 2013 Share Posted December 27, 2013 (edited) Hello For some reason getElementData is always returning false. server addEventHandler ( "onPlayerQuit", root, function ( ) setElementData ( source, "team", getPlayerTeam ( source ) ) setElementData ( source, "skin", getElementModel ( source ) ) end ) addEventHandler ( "onPlayerJoin", root, function ( ) setElementModel ( source, getElementData ( source, "skin" ) ) setPlayerTeam ( source, getElementData ( source, "team" ) ) end ) Does anyone know how to fix this? Edited December 27, 2013 by Guest Link to comment
johny46 Posted December 27, 2013 Share Posted December 27, 2013 Element data is lost whenever the element is destroyed. In your case, the element is a player who is just about to leave your server. So his data is lost. You will have to find another way of storing your data. You can for example use setAccountData, or create an xml file where you'd store their serials next to their settings. Link to comment
Chronic Posted December 27, 2013 Author Share Posted December 27, 2013 Alright I tried it, the skin gets set on login, however the team doesn't. addEventHandler ( "onPlayerQuit", root, function ( ) acc = getPlayerAccount ( source ) setAccountData ( acc, "team", getPlayerTeam ( source ) ) setAccountData ( acc, "skin", getElementModel ( source ) ) end ) addEventHandler ( "onPlayerLogin", root, function ( ) setElementModel ( source, getAccountData ( acc, "skin" ) ) setPlayerTeam ( source, getAccountData ( acc, "team" ) ) end ) Link to comment
Jusonex Posted December 27, 2013 Share Posted December 27, 2013 (edited) You can't save elements via setAccountData. If you want to save the team, you'll have to find another solution such as saving the team name + using getTeamFromName later. EDIT: addEventHandler("onPlayerQuit", root, function() local acc = getPlayerAccount(source) setAccountData(acc, "team", getTeamName(getPlayerTeam(source))) setAccountData(acc, "skin", getElementModel(source)) end ) addEventHandler("onPlayerLogin", root, function(oldAccount, newAccount) setElementModel(source, getAccountData(newAccount, "skin")) local teamName = getAccountData(newAccount, "team") local team = getTeamFromName(teamName) or createTeam(teamName) -- get existing team if exists or create a new one setPlayerTeam(source, team) end ) (Untested) Edited December 27, 2013 by Guest Link to comment
Chaos Posted December 27, 2013 Share Posted December 27, 2013 (edited) Try getTeamName instead of getPlayerTeam Edited December 27, 2013 by Guest Link to comment
TAPL Posted December 27, 2013 Share Posted December 27, 2013 addEventHandler("onPlayerQuit", root, function() local acc = getPlayerAccount(source) if acc and not isGuestAccount(acc) then local team = getPlayerTeam(source) setAccountData(acc, "skin", getElementModel(source)) if team then setAccountData(acc, "team", getTeamName(team)) else setAccountData(acc, "team", false) end end end) addEventHandler("onPlayerLogin", root, function(_, acc) local skin = getAccountData(acc, "skin") local teamName = getAccountData(acc, "team") local team = teamName and getTeamFromName(teamName) or false setElementModel(source, skin) if team then setPlayerTeam(source, team) end end) You may want to spawn the player before anyway. Link to comment
Chronic Posted December 27, 2013 Author Share Posted December 27, 2013 Thank you TAPL, your solution works 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