pedr0fontoura / fivem-appearance

👀 A flexible player customization script for FiveM.
https://forum.cfx.re/t/release-fivem-appearance/2438537
MIT License
120 stars 73 forks source link

setPlayerAppearance export with kvs #17

Closed mascotte-scripts closed 3 years ago

mascotte-scripts commented 3 years ago

Hi there!

I'm trying to use the setPlayerAppearance export with FiveM's internal kvs. Saving to the database is fine but trying to set the player appearance after spawn isn't proving effective..

Event to save the skin:

RegisterNetEvent('updatecharacterclothes')
AddEventHandler('updatecharacterclothes', function(appearance)
    local identifier = GetIdentifier(source)
        SetResourceKvp(('users:%s:outfit_current'):format(identifier), json.encode(appearance))
        print('outfit saved to db')
end)

Function to retrieve the skin:

function GetCharSkin(source)
    local source = source
    local identifier = GetIdentifier(source)
    local appearance =  GetResourceKvpString(('users:%s:outfit_current'):format(identifier))
    local charappearance = json.decode(appearance)

    return charappearance
end

I'm using this handler:

AddEventHandler('playerSpawned', function()

To trigger the server event that gets the saved data and using this event to try load it from the client:

RegisterNetEvent('player:loadcharacterclothes')
AddEventHandler('player:loadcharacterclothes', function(source, charappearance)
  print('and here')
  local appearance = charappearance
  exports["fivem-appearance"]:setPlayerAppearance(appearance)
  print('Loaded clothes')
end)

However, 'Default Dan' is loaded each time. No errors in the console, and the prints show each event running as they should.

Everything is standalone from any framework

Any suggestion?

EDIT: I overlooked the fact the export takes two params, so to anyone reading thism the correct syntax for me was:

exports["fivem-appearance"]:setPlayerAppearance(source, appearance)