Cronoss Posted February 3, 2022 Share Posted February 3, 2022 (edited) 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 February 3, 2022 by Cronoss Link to comment
Mr.Hugin Posted February 3, 2022 Share Posted February 3, 2022 (edited) 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 February 3, 2022 by Mr.Hugin Link to comment
βurak Posted February 3, 2022 Share Posted February 3, 2022 (edited) Do you want to send data from client side to server side? Or do you want to trigger the event on the server side and load the player's data? Edited February 3, 2022 by Burak5312 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