Jump to content

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


Furious

Recommended Posts

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(getPlayerName(thePlayer)) 
  local playerSkin = tonumber(getAccountData(playerAcc, "skin")) 
              createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 
function onPlayerCheckSkin()
  triggerServerEvent("makePed", localPlayer) 
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin) 

Try this 

Link to comment
7 minutes 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(getPlayerName(thePlayer)) 
  local playerSkin = tonumber(getAccountData(playerAcc, "skin")) 
              createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 

function onPlayerCheckSkin()
  triggerServerEvent("makePed", localPlayer) 
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin) 

Try this 

[2019-02-24 18:43:34] WARNING: [Gamemode]\login\server.lua:61: Bad argument @ 'getPlayerName' [Expected element at argument 1, got nil]
[2019-02-24 18:43:34] WARNING: [Gamemode]\login\server.lua:61: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got boolean]
[2019-02-24 18:43:34] WARNING: [Gamemode]\login\server.lua:62: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean]
[2019-02-24 18:43:34] WARNING: [Gamemode]\login\server.lua:63: Bad argument @ 'createPed' [Expected bool at argument 6, got number '0']

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(getPlayerName(thePlayer)) 
  local playerSkin = getAccountData(playerAcc, "skin")
  setElementData(thePlayer, "skin", playerSkin) 
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 
function onPlayerCheckSkin()
  triggerServerEvent("makePed", resourceRoot) 
  local playerSkin = tonumber(getElementData(localPlayer, "skin"))  
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin) 

If that not work i give up

Link to comment
16 minutes 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(getPlayerName(thePlayer)) 
  local playerSkin = getAccountData(playerAcc, "skin")
  setElementData(thePlayer, "skin", playerSkin) 
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 

function onPlayerCheckSkin()
  triggerServerEvent("makePed", resourceRoot) 
  local playerSkin = tonumber(getElementData(localPlayer, "skin"))  
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin) 

If that not work i give up

Black screen, This time I give up, better make another input panel.

Edited by MatheusCalixto
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(getPlayerName(thePlayer)) 
  local playerSkin = getAccountData(playerAcc, "skin")
  setElementData(thePlayer, "skin", playerSkin) 
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 
function onPlayerCheckSkin()
  triggerServerEvent("makePed", resourceRoot, localPlayer ) 
  local playerSkin = tonumber(getElementData(localPlayer, "skin"))  
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin)

 

Edited by Dimos7
Link to comment

Server

Spoiler

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 )

addEvent( "onRequestLastSkin", true )
addEventHandler( "onRequestLastSkin", root, function( )
    local serial = getPlayerSerial( source )
    triggerClientEvent( source, "onGetLastSkin", source, lastSkinTable[serial] )
end )

 

Client

Spoiler

addEventHandler( "onClientResourceStart", resourceRoot, function( )
    triggerServerEvent( "onRequestLastSkin", localPlayer )
end )

addEvent( "onGetLastSkin", true )
addEventHandler( "onGetLastSkin", root, function( skinID )
    local ped = createPed((skinID or 0),-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end )

 

 

Link to comment
19 minutes 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(getPlayerName(thePlayer)) 
  local playerSkin = getAccountData(playerAcc, "skin")
  setElementData(thePlayer, "skin", playerSkin) 
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 

function onPlayerCheckSkin()
  triggerServerEvent("makePed", resourceRoot, localPlayer ) 
  local playerSkin = tonumber(getElementData(localPlayer, "skin"))  
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin)

 

Please see your inbox.

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 = getAccountData(playerAcc, "skin")
  setElementData(thePlayer, "skin", playerSkin) 
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 
function onPlayerCheckSkin()
  triggerServerEvent("makePed", resourceRoot, localPlayer) 
  local playerSkin = tonumber(getElementData(localPlayer, "skin"))  
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end 
addEventHandler("onClientResourceStart", resourceRoot, onPlayerCheckSkin)

 

Edited by Dimos7
Link to comment
Spoiler
3 hours ago, Dimos7 said:


 
    
    
     
       
  

 

 
    
    
    
 
  
 



   
      
    
 

 

 

5 hours ago, Mr.Loki said:

Servidor

  Revelar conteúdos ocultos



 
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 )

addEvent( "onRequestLastSkin", true )
addEventHandler( "onRequestLastSkin", root, function( )
    local serial = getPlayerSerial( source )
    triggerClientEvent( source, "onGetLastSkin", source, lastSkinTable[serial] )
end )

 

Cliente

  Revelar conteúdos ocultos



 
addEventHandler( "onClientResourceStart", resourceRoot, function( )
    triggerServerEvent( "onRequestLastSkin", localPlayer )
end )

addEvent( "onGetLastSkin", true )
addEventHandler( "onGetLastSkin", root, function( skinID )
    local ped = createPed((skinID or 0),-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end )

 

 

 

5 hours ago, KillerX said:


 

localPlayer = source

 

 

Guys, after a long time I figured out what it was, the temporary files, were conflicting with the server files. Thank you all!

I used the example of: Mr.Loki

But I'm sure the example of: Dimos7, is running too!

Code that worked, I did not want to store the skins and even then the code worked.

-- Server-side
addEventHandler( "onPlayerQuit", root, function( )
    local serial = getPlayerSerial( source )
    lastSkinTable[serial] = getElementModel( source )
    outputDebugString(lastSkinTable[serial])
end )

addEvent( "onRequestLastSkin", true )
addEventHandler( "onRequestLastSkin", root, function( )
    local serial = getPlayerSerial( source )
    triggerClientEvent( source, "onGetLastSkin", source, lastSkinTable[serial] )
end )

 

--Client-side

addEvent( "onGetLastSkin", true )
addEventHandler( "onGetLastSkin", root, function( skinID )
    local ped = createPed((skinID or 0),-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end )

 

Edited by MatheusCalixto
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, "makePed", root, playerSkin) 
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 
function onPlayerCheckSkin(playerSkin)
  triggerServerEvent("makePed", root , localPlayer)   
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,241.908905,0,0)
end
addEvent("makePed", true) 
addEventHandler("makePed", root , onPlayerCheckSkin)

 

Edited by Dimos7
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"))
  createPed(playerSkin or 0 ,-1600.9000244141,-1620.6999511719,36.599998474121,0)
end 
addEvent("makePed", true) 
addEventHandler("makePed", root, onPlayerLoadSkin) 
function onPlayerCheckSkin()
  triggerServerEvent("makePed", root , localPlayer)   
end
addEventHandler("onClientResourceStart", resourceRoot , onPlayerCheckSkin)

 

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