Instead of setting every value invidually, I suggest using JSON to save the trouble and make it a little bit cleaner. Try the following, I tested it and seems to work just fine.
function saveAccount( account )
local account = eventName == "onPlayerLogout" and account or getPlayerAccount( source )
if ( account ) and ( not isGuestAccount( account ) ) then
local x, y, z = getElementPosition( source )
local _, _, rotation = getElementRotation( source )
local position = { skin = getElementModel( source ), x = x, y = y, z = z, interior = getElementInterior( source ), dimension = getElementDimension( source ), rotation = rotation }
local stats = { money = getPlayerMoney( source ), health = getElementHealth( source ), armor = getPedArmor( source ) }
local weapons = { }
for i = 0, 12 do
weapons[ i ] = { weapon = getPedWeapon( source ), ammo = getPedTotalAmmo( source, i ) }
end
setAccountData( account, "account.position", toJSON( position ) )
setAccountData( account, "account.stats", toJSON( stats ) )
setAccountData( account, "account.weapons", toJSON( weapons ) )
end
end
addEventHandler( "onPlayerQuit", root, saveAccount )
addEventHandler( "onPlayerWasted", root, saveAccount )
addEventHandler( "onPlayerLogout", root, saveAccount )
addEventHandler( "onPlayerLogin", root,
function( _, account )
local position = getAccountData( account, "account.position" )
if ( position ) then
position = fromJSON( position )
spawnPlayer( source, position.x, position.y, position.z, position.rotation, position.skin, position.interior, position.dimension )
else
spawnPlayer( source, 2485, -1665, 13.5, 0, 0, 0, 0 )
end
setCameraTarget( source, source )
fadeCamera( source, true, 2.0 )
local stats = getAccountData( account, "account.stats" )
if ( stats ) then
stats = fromJSON( stats )
setElementHealth( source, stats.health )
setPedArmor( source, stats.armor )
setPlayerMoney( source, stats.money )
end
local weapons = getAccountData( account, "account.weapons" )
if ( weapons ) then
weapons = fromJSON( weapons )
for i, data in pairs( weapons ) do
giveWeapon( source, data.weapon, data.ammo, false )
end
end
end
)