Jump to content

save-system with events?


Cronoss

Recommended Posts

I thought that it would be better to save the player data without loading it immediately when he logs in, is it possible to load it when he executes an event? This is the code:

--------------------Saves the data----------------------
function recordarPersonaje()
	local cuentaJugador = getPlayerAccount(source)
	if (cuentaJugador) and not isGuestAccount(cuentaJugador) then
		local personajeDatos = getPlayerName(source)
		local skinPJ = getElementModel(source)
		local x,y,z = getElementPosition(source)
		setAccountData(cuentaJugador,"PosX",x) 
        setAccountData(cuentaJugador,"PosY",y) 
        setAccountData(cuentaJugador,"PosZ",z)
		setAccountData(cuentaJugador, "nombre", personajeDatos)
		setAccountData(cuentaJugador, "skin", skinPJ)
	end
end
addEventHandler("onPlayerQuit", root, recordarPersonaje)

--------------------This is the code, obviusly doesn't work but it's an example of what I "want"----------------------

function darDatos(_, cuentaJugador)
	if (cuentaJugador) then
		local skinJugadorDar = getAccountData(cuentaJugador, "skin")
		local nombreJugadorDar = getAccountData(cuentaJugador, "nombre")
		local x,y,z = getAccountData(cuentaJugador,"PosX"),getAccountData(cuentaJugador,"PosY"),getAccountData(cuentaJugador,"PosZ") 
		if (nombreJugadorDar) then
			spawnPlayer(source, x, y, z)
			setPlayerName(source, nombreJugadorDar)
			setElementModel(source, skinJugadorDar)
		end
	end
end

addEvent("cargarDatos")
addEventHandler("cargarDatos", root, darDatos)

(server side)

This is the client-side part:

  function elegirPJlg()
        ventanaPrimeraSeleccion = guiCreateWindow(842, 463, 272, 81, "Seleccionar personaje", false)
        guiWindowSetSizable(ventanaPrimeraSeleccion, false)
        showCursor(true)

        btnSeleccionar = guiCreateButton(72, 31, 127, 40, "Seleccionar", false, ventanaPrimeraSeleccion)
        btnIZQ = guiCreateButton(10, 31, 52, 40, "<", false, ventanaPrimeraSeleccion)
        btnDER = guiCreateButton(209, 32, 52, 39, ">", false, ventanaPrimeraSeleccion)

        addEventHandler("onClientGUIClick", btnSeleccionar, function()
        guiSetVisible(ventanaPrimeraSeleccion, false)
        triggerServerEvent("cargarDatos", getLocalPlayer(), localPlayer)
        end)
    end
---------------------Just in case my idea is not clear, this is what I want, the player clicks on a button and then the save-data loads all his/her info (example of what I want to make)----------

I don't need the full code or a long explanation, I just need to know if is it possible and how could I do it, I want to learn

 

EDIT: I want this: the player log in > triggers another command that show the player their info > there, they can choose load the data or delete it

Edited by Cronoss
Link to comment
4 minutes ago, Cronoss said:

I thought that it would be better to save the player data without loading it immediately when he logs in, is it possible to load it when he executes an event? This is the code:

--------------------Saves the data----------------------
function recordarPersonaje()
	local cuentaJugador = getPlayerAccount(source)
	if (cuentaJugador) and not isGuestAccount(cuentaJugador) then
		local personajeDatos = getPlayerName(source)
		local skinPJ = getElementModel(source)
		local x,y,z = getElementPosition(source)
		setAccountData(cuentaJugador,"PosX",x) 
        setAccountData(cuentaJugador,"PosY",y) 
        setAccountData(cuentaJugador,"PosZ",z)
		setAccountData(cuentaJugador, "nombre", personajeDatos)
		setAccountData(cuentaJugador, "skin", skinPJ)
	end
end
addEventHandler("onPlayerQuit", root, recordarPersonaje)

--------------------This is the code, obviusly doesn't work but it's an example of what I "want"----------------------

function darDatos(_, cuentaJugador)
	if (cuentaJugador) then
		local skinJugadorDar = getAccountData(cuentaJugador, "skin")
		local nombreJugadorDar = getAccountData(cuentaJugador, "nombre")
		local x,y,z = getAccountData(cuentaJugador,"PosX"),getAccountData(cuentaJugador,"PosY"),getAccountData(cuentaJugador,"PosZ") 
		if (nombreJugadorDar) then
			spawnPlayer(source, x, y, z)
			setPlayerName(source, nombreJugadorDar)
			setElementModel(source, skinJugadorDar)
		end
	end
end

addEvent("cargarDatos")
addEventHandler("cargarDatos", root, darDatos)

(server side)

This is the client-side part:

  function elegirPJlg()
        ventanaPrimeraSeleccion = guiCreateWindow(842, 463, 272, 81, "Seleccionar personaje", false)
        guiWindowSetSizable(ventanaPrimeraSeleccion, false)
        showCursor(true)

        btnSeleccionar = guiCreateButton(72, 31, 127, 40, "Seleccionar", false, ventanaPrimeraSeleccion)
        btnIZQ = guiCreateButton(10, 31, 52, 40, "<", false, ventanaPrimeraSeleccion)
        btnDER = guiCreateButton(209, 32, 52, 39, ">", false, ventanaPrimeraSeleccion)

        addEventHandler("onClientGUIClick", btnSeleccionar, function()
        guiSetVisible(ventanaPrimeraSeleccion, false)
        triggerServerEvent("cargarDatos", getLocalPlayer(), localPlayer)
        end)
    end
---------------------Just in case my idea is not clear, this is what I want, the player clicks on a button and then the save-data loads all his/her info (example of what I want to make)----------

I don't need the full code or a long explanation, I just need to know if is it possible and how could I do it, I want to learn

The best you can use is the database

servers Database

Edited by Mr.Hugin
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...