Protagonist95 Posted February 12, 2016 Share Posted February 12, 2016 Hello ppl.Currently working on saving element datas,after player loggs in and out. Heres script i made,but apparently it doesn't want to work. function setDataOnQuit() local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local health = getElementData(source,"health") setAccountData(playeraccount,"player.health",health) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), setDataOnQuit ) function setDataOnJoin() local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local health = getAccountData ( playeraccount, "player.health") if (health) then setElementData(playeraccount,"health",health) end end end addEventHandler ( "onPlayerLogin", getRootElement ( ), setDataOnJoin ) function statsOnSpawn() local player = source if player then setElementData(player,"health",100) setElementData(player,"stamina",100) setElementData(player,"food",100) setElementData(player,"thirst",100) end end addEventHandler ( "onPlayerSpawn", getRootElement(), statsOnSpawn ) Link to comment
Dimos7 Posted February 12, 2016 Share Posted February 12, 2016 so what you want save in accounts? Link to comment
Protagonist95 Posted February 12, 2016 Author Share Posted February 12, 2016 so what you want save in accounts? ElementData Link to comment
1LoL1 Posted February 12, 2016 Share Posted February 12, 2016 so what you want save in accounts? ElementData setElementData for health doesn't exist. Use setElementHealth & getElementHealth. Link to comment
Dimos7 Posted February 12, 2016 Share Posted February 12, 2016 function onLogin(thePreviousAccount, theCurrentAccount, autoLogin) if ~= (isGuestAccount(getPlayerAccount(source))) then local playerHealth = getAccountData(theCurrentAccount, "s.health") setElementHealth(source, playerHealth) end end addEventHandler("onPlayerLogin", root, onLogin) function onQuit(quitType, reason, resposibleElement) if ~= (isGuestAccount(getPlayerAccount(source))) then local account = getPlayerAccount(source) if (account) then setAccountData(account, "s.health", tostring(getElementHealth(source))) end end end addEventHandler("onPlayerQuit", root, onQuit) 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