Jump to content

Help - Skin id to createPed, Client-side & Server-side


Furious

Recommended Posts

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 by MatheusCalixto
Link to comment
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 by MatheusCalixto
Link to comment

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.

  • Thanks 1
Link to comment
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
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.

 

  • Sad 1
Link to comment
1 hour ago, Dimos7 said:

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 by MatheusCalixto
Link to comment
-- 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 by MaligNos
  • Thanks 1
Link to comment
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 by Dimos7
  • Thanks 1
Link to comment
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 by MatheusCalixto
Link to comment
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 by Dimos7
  • Confused 1
Link to comment
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 by MatheusCalixto
Link to comment
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 by MaligNos
Link to comment

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 by MatheusCalixto
Link to comment
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

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...