Furious Posted February 22, 2019 Share Posted February 22, 2019 (edited) Hello, I would like to know if there is a way to save a skin, after the player leaves and when it enters the login page, the skin it was going to "createPed". Example: -- Server side function onPlayerQuitSaveSkin() local playeraccount = getPlayerAccount(source) if playeraccount and not isGuestAccount(playeraccount) then local playerSkin = getElementModel(source) if playerSkin then setAccountData(playeraccount, "player.skin", playerSkin) end end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuitSaveSkin ) -- Client-side function onPlayerClientLoadSkin() local accountName = getPlayerName(getLocalPlayer()) local playeraccount = getPlayerAccount(accountName) if (playeraccount) then local playerSkin = tonumber(getAccountData(playeraccount, "player-skin")) if (playerSkin) then createPed(playerSkin,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) else createPed(0,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end end end Except that the player is still not going to log in, I just want to appear the skin he was in the game on the screen. Edited February 22, 2019 by MatheusCalixto Link to comment
Mr.Loki Posted February 22, 2019 Share Posted February 22, 2019 a simple way is using setAccountData to save it when the player leaves the server onPlayerQuit then when the player logs in use getAccountData to get the skin model and add it to your spawnPlayer function in your login panel. 1 Link to comment
Furious Posted February 22, 2019 Author Share Posted February 22, 2019 (edited) 3 minutes ago, Mr.Loki said: a simple way is using setAccountData to save it when the player leaves the server onPlayerQuit then when the player logs in use getAccountData to get the skin model and add it to your spawnPlayer function in your login panel. I do not want to add skin in the "spawnPlayer" I want to add the skin in the "createPed" Edit: I tried to use "getPlayerAccount" but it returns me null. Edited February 22, 2019 by MatheusCalixto Link to comment
Mr.Loki Posted February 22, 2019 Share Posted February 22, 2019 10 minutes ago, MatheusCalixto said: Except that the player is still not going to log in, I just want to appear the skin he was in the game on the screen. You can create a database dbConnect, fileCreate, xmlCreateFile to store their skin when they disconnect using their serial. The simplest of the 3 is using fileCreate with the toJSON and fromJSON functions to save the tables. 1 Link to comment
Furious Posted February 22, 2019 Author Share Posted February 22, 2019 2 minutes ago, Mr.Loki said: Você pode criar um banco de dados dbConnect , fileCreate , xmlCreateFile para armazenar sua capa quando eles se desconectarem usando sua serial. O mais simples do 3 está usando fileCreate com as toJSON e fromJSON funções para salvar as tabelas. Could you tell me which side is "toJSON" and "fromJSON"? Server-side or Client-side? Link to comment
Mr.Loki Posted February 22, 2019 Share Posted February 22, 2019 Server because the player would be able to edit the file if it were on the client. 1 Link to comment
Furious Posted February 22, 2019 Author Share Posted February 22, 2019 2 minutes ago, Mr.Loki said: Server because the player would be able to edit the file if it were on the client. So I use "fileCreate" on the server-side with "onPlayerQuit" and on the client-side I use "FileOpen"? Link to comment
Mr.Loki Posted February 22, 2019 Share Posted February 22, 2019 Something like this local lastSkinTable = {} addEventHandler( "onPlayerQuit", root, function( ) local serial = getPlayerSerial( source ) lastSkinTable[serial] = getElementModel( source ) end ) local filePath = "skinDB.json" addEventHandler( "onResourceStart", resourceRoot, function( ) local db = fileExists( filePath ) and fileOpen( filePath ) if not db then return end lastSkinTable = fromJSON( fileRead( db, fileGetSize( db ) ) ) fileClose( db ) end ) addEventHandler( "onResourceStop", resourceRoot, function( ) local db = fileExists( filePath ) and fileOpen( filePath ) or fileCreate( filePath ) fileWrite( db, toJSON( lastSkinTable ) ) fileClose( db ) end ) Then use triggers to pass the data to the client when you need it. 1 Link to comment
Furious Posted February 22, 2019 Author Share Posted February 22, 2019 4 minutes ago, Mr.Loki said: Something like this local lastSkinTable = {} addEventHandler( "onPlayerQuit", root, function( ) local serial = getPlayerSerial( source ) lastSkinTable[serial] = getElementModel( source ) end ) local filePath = "skinDB.json" addEventHandler( "onResourceStart", resourceRoot, function( ) local db = fileExists( filePath ) and fileOpen( filePath ) if not db then return end lastSkinTable = fromJSON( fileRead( db, fileGetSize( db ) ) ) fileClose( db ) end ) addEventHandler( "onResourceStop", resourceRoot, function( ) local db = fileExists( filePath ) and fileOpen( filePath ) or fileCreate( filePath ) fileWrite( db, toJSON( lastSkinTable ) ) fileClose( db ) end ) Then use triggers to pass the data to the client when you need it. My problem is checking on the client side, how can I check on the client side that skin belongs to the player before he logs in? Link to comment
Mr.Loki Posted February 22, 2019 Share Posted February 22, 2019 12 minutes ago, MatheusCalixto said: My problem is checking on the client side, how can I check on the client side that skin belongs to the player before he logs in? 12 minutes ago, MatheusCalixto said: Then use triggers to pass the data to the client when you need it. 1 Link to comment
Furious Posted February 22, 2019 Author Share Posted February 22, 2019 19 minutes ago, Mr.Loki said: I can not do it, something very complicated! Link to comment
Furious Posted February 22, 2019 Author Share Posted February 22, 2019 How do I get the data from the table and step into the client? Link to comment
Furious Posted February 23, 2019 Author Share Posted February 23, 2019 Can someone save me? Link to comment
Furious Posted February 24, 2019 Author Share Posted February 24, 2019 20 hours ago, Dimos7 said: Use triggers event Hello, I can not figure out how to get the data out of the file. Link to comment
Dimos7 Posted February 24, 2019 Share Posted February 24, 2019 Use getAccountData setAccountData triggerClientEvent addEvent addEventHandler 1 Link to comment
Furious Posted February 24, 2019 Author Share Posted February 24, 2019 (edited) 1 hour ago, Dimos7 said: Use getAccountData setAccountData triggerClientEvent addEvent addEventHandler I think you do not understand, I wanted to know how I open the file and I get the "serial" and the "skin" id from inside the file. Example: function onPlayerCheckSkin() local accountName = getPlayerName(getLocalPlayer()) local playeraccount = getPlayerAccount(accountName) if (playeraccount) then local playerSkin = lastSkinTable[serial] if (playerSkin) then return playerSkin end end end I do not know how I open the file "skinDB.json" and get its data. Edited February 24, 2019 by MatheusCalixto Link to comment
[M]ister Posted February 24, 2019 Share Posted February 24, 2019 (edited) -- server side function onPlayerQuitSaveSkin() local playeraccount = getPlayerAccount(source) if playeraccount and not isGuestAccount(playeraccount) then setAccountData(playeraccount, "player.skin", getElementModel(source)) end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuitSaveSkin ) addEventHandler("onPlayerLogin", root, function(_,playeraccount) local playerSkin = tonumber(getAccountData(playeraccount, "player-skin")) triggerClientEvent ( source, "makePed", source, playerSkin or 0 ) end ) -- client side addEvent( "makePed", true ) addEventHandler( "makePed", localPlayer, function(skin) createPed(skin,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end end Edit: I did not read it right, you want to create the ped before the player logs in ? Edited February 24, 2019 by MaligNos 1 Link to comment
Dimos7 Posted February 24, 2019 Share Posted February 24, 2019 (edited) function onPlayerSaveSkin() local playerAcc = getPlayerAccount(source) if not isGuestAccount(playerAcc) then local playerSkin = getElementModel(source) setAccountData(playerAcc, "skin", tostring(playerSkin)) end end addEventHandler("onPlayerQuit", root, onPlayerSaveSkin) function onPlayerLoadSkin(thePlayer) local playerAcc = getPlayerAccount(thePlayer) local playerSkin = tonumber(getAccountData(playerAcc, "skin")) triggerClientEvent(thePlayer, "createSkinLogin", root, playerSkin) end function onPlayerCheckSkin(playerSkin) createPed(playerSkin or 0,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end addEvent("createSkinLogin", true) addEventHandler("createSkinLogin", root, onPlayerCheckSkin) Edited February 24, 2019 by Dimos7 1 Link to comment
Furious Posted February 24, 2019 Author Share Posted February 24, 2019 (edited) 11 hours ago, Dimos7 said: function onPlayerSaveSkin() local playerAcc = getPlayerAccount(source) if not isGuestAccount(playerAcc) then local playerSkin = getElementModel(source) setAccountData(playerAcc, "skin", tostring(playerSkin)) end end addEventHandler("onPlayerQuit", root, onPlayerSaveSkin) function onPlayerLoadSkin(thePlayer) local playerAcc = getPlayerAccount(thePlayer) local playerSkin = tonumber(getAccountData(playerAcc, "skin")) triggerClientEvent(thePlayer, "createSkinLogin", root, playerSkin) end function onPlayerCheckSkin(playerSkin) createPed(playerSkin or 0,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end addEvent("createSkinLogin", true) addEventHandler("createSkinLogin", root, onPlayerCheckSkin) Without success yet, nothing appears. I will explain better, when the player leaves the server "onPlayerQuit" his skin will be saved and when entering the server "onClientResourceStart" a skin that was already with him, will be loaded in the "createPed", this before he log in. Edited February 24, 2019 by MatheusCalixto Link to comment
Dimos7 Posted February 24, 2019 Share Posted February 24, 2019 (edited) function onPlayerCheckSkin() triggerServerEvent("makePed", localPlayer, playerSkin) createPed(playerSkin or 0,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end addEventHandler("onClientResourceStart", resourceRoot , onPlayerCheckSkin) function onPlayerSaveSkin() local playerAcc = getPlayerAccount(source) if not isGuestAccount(playerAcc) then local playerSkin = getElementModel(source) setAccountData(playerAcc, "skin" , tostring(playerSkin)) end end addEventHandler("onPlayerQuit", root, onPlayerSaveSkin) function onPlayerLoadSkin(thePlayer) local playerAcc = getPlayerAccount(thePlayer) local playerSkin = tonumber(getAccountData(playerAcc, "skin")) end addEvent("makePed", true) addEventHandler("makePed", root, onPlayerLoadSkin) 2 hours ago, MatheusCalixto said: Without success yet, nothing appears. I will explain better, when the player leaves the server "onPlayerQuit" his skin will be saved and when entering the server "onClientResourceStart" a skin that was already with him, will be loaded in the "createPed", this before he log in. Oh i see i will help you Edited February 24, 2019 by Dimos7 1 Link to comment
Furious Posted February 24, 2019 Author Share Posted February 24, 2019 (edited) 37 minutes ago, Dimos7 said: function onPlayerCheckSkin() triggerServerEvent("makePed", localPlayer, playerSkin) createPed(playerSkin or 0,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end addEventHandler("onClientResourceStart", resourceRoot , onPlayerCheckSkin) function onPlayerSaveSkin() local playerAcc = getPlayerAccount(source) if not isGuestAccount(playerAcc) then local playerSkin = getElementModel(source) setAccountData(playerAcc, "skin" , tostring(playerSkin)) end end addEventHandler("onPlayerQuit", root, onPlayerSaveSkin) function onPlayerLoadSkin(thePlayer) local playerAcc = getPlayerAccount(thePlayer) local playerSkin = tonumber(getAccountData(playerAcc, "skin")) end addEvent("makePed", true) addEventHandler("makePed", root, onPlayerLoadSkin) Oh i see i will help you The skin of id "0" has appeared, but can not get the data of the player that was logged in before. Quote [2019-02-24 16:18:18] WARNING: [Gamemode]\login\server.lua:61: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] [2019-02-24 16:18:24] WARNING: [Gamemode]\login\server.lua:62: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean] Edit: I'm almost giving up, I think I'd better try to make another entry. Edited February 24, 2019 by MatheusCalixto Link to comment
[M]ister Posted February 24, 2019 Share Posted February 24, 2019 (edited) local filename = "skin.txt" addEventHandler("onClientPlayerQuit", root, function() if (source == localPlayer) then local file = fileExists(filename) and fileOpen(filename) or fileCreate(filename) fileWrite(file, getElementModel(localPlayer)) fileClose(file) end end ) addEventHandler("onClientResourceStart", resourceRoot, function() local file = fileExists(filename) and fileOpen(filename) if file then skin = fileRead(file, fileGetSize(file)) fileClose(file) createPed(tonumber(skin),-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) else createPed(0,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0) end end ) Edited February 24, 2019 by MaligNos Link to comment
Furious Posted February 24, 2019 Author Share Posted February 24, 2019 (edited) Personally the "Mr.Loki" example is what I get closer, but I can not get the data from the file to check on the client. File: skinDB.json [ { "2CE273F16F6AE8C5C248E511F0FAF9A1": 189 } ] I do not know how to open this in the client and get the "id" of the skin, how can I explain, I do not know how to get the serial and do a verification of the serial of the player, if you can do the verification of the two serial, in the "createPed". I'm trying to do it all the way, but it's impossible. Edited February 24, 2019 by MatheusCalixto Link to comment
Dimos7 Posted February 24, 2019 Share Posted February 24, 2019 2 minutes ago, MatheusCalixto said: Personally the "Mr.Loki" example is what I get closer, but I can not get the data from the file to check on the client. File: skinDB.json [ { "2CE273F16F6AE8C5C248E511F0FAF9A1": 189 } ] I do not know how to open this in the client and I get the "id" skin, how can I explain, I do not know how to get the serial and do a verification of the serial of the player, if you can do the verification of the two serial, to add the "id "skin" on it. I'm trying to do it all the way, but it's impossible. You want player has login or before login? 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