Jump to content

Can't save account data,please help


Protagonist95

Recommended Posts

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

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