Jump to content

ask save data player


iiv03

Recommended Posts

hey, i won't to use SQL to save data. account player but

but is this the way to save data account player and if entry he gets data account?

my code:

function lobby.save(newName, newAge, newCountry, player)
	if not isElement(player) then
		return
	end
	local thisAccount = getPlayerAccount( player )
	if thisAccount then
	setAccountData(thisAccount,"AccountPlayer",newName)
	setAccountData(thisAccount,"AccountPlayer",newAge)
	setAccountData(thisAccount,"AccountPlayer",newCountry)
	print("done save in data")
	else
	print("failed to save in data")
	end
end


addEventHandler("onPlayerLogin", root,
function(_, theCurrentAccount)
local acc = getAccountName(getPlayerAccount( source ))
if acc then
getAccountData(theCurrentAccount,"AccountPlayer")
end
end)

EDIT: how check if is new account ?

Edited by xFabel
Link to comment
12 hours ago, nikitafloy said:

-- Its new account?	
getAccountData(thisAccount,"oldAccount")
-- No, then
setAccountData(thisAccount,"oldAccount",true)
-- Now its old account

 

thx. u mean like this

addEventHandler("onPlayerLogin", root,
function(_, theCurrentAccount)
local acc = getAccountData(theCurrentAccount,"AccountPlayer")
if acc then
setAccountData(theCurrentAccount,"AccountPlayer",true)
end
end)

:)

 

Link to comment
  • Moderators

Every player in the server does have an account. If the account is not created by script, then it is a guest account, which is automatic deleted when it is not required any more.

Quote

This function checks to see if an account is a guest account. A guest account is an account automatically created for a user when they join the server and deleted when they quit or login to another account. Data stored in a guest account is not stored after the player has left the server. As a consequence, this function will check if a player is logged in or not.

https://wiki.multitheftauto.com/wiki/IsGuestAccount

if not isGuestAccount ( acc ) then

 

 

 

Edited by IIYAMA
  • Thanks 1
Link to comment
5 hours ago, nikitafloy said:

@xFabel 


addEventHandler("onPlayerLogin", root,
	function(_, theCurrentAccount)
		local acc = getAccountData(theCurrentAccount,"AccountPlayer")
		if not acc then 	-- not acc, because its new account - new account havent any datas
			setAccountData(theCurrentAccount,"AccountPlayer",true)
		end
end)

 

 

4 hours ago, IIYAMA said:

Every player in the server does have an account. If the account is not created by script, then it is a guest account, which is automatic deleted when it is not required any more.


if not isGuestAccount ( acc ) then

 

 

 

thx guys i can save player name? on getaccountdata/setaccountdata?

functions:

setPlayerName

getPlayerName

i don't know if work.

	setAccountData(playerAccount, "playerName", newName) -- when player press button and get event (newName) from triggerclientevent to save it in setaccountdata


function lobby.load(_ theCurrentAccount)
  local newName = getAccountData(theCurrentAccount, "playerName") -- get account data if player login 
	if newName then setPlayerName(source, newName) end -- setplayername
	print(newName) -- this for test but doesn't work in debug write me false
    end
  

 

Edited by xFabel
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...