[Request] Set the player model

I want to set the model to player with steamid.
For ex:

steam:12314214xsa21 a_f_y_hipster_02
steam:1412561234af csb_car3guy1
etc.

Please help :C

server script

  • table indexed with steam id’s where value is model
  • event triggered by client check’s the source identifier for steam, then check table index for steam, if index exists return value of model, else return null
  • trigger client event with returned model or null

client script

  • trigger server script on spawn to see if model is defined
  • event handler for server to send back model or null
  • if model is received set model, if null set default model

Try to create with that approach. If your server is using a database this is not the best approach but does still contain some of the logic required.

1 Like

Client.lua

RegisterNetEvent('applyskin')
AddEventHandler('applyskin', function(skin)
    Citizen.CreateThread(function()
        local model = GetHashKey(skin)
        RequestModel(model)
        while not HasModelLoaded(model) do
            RequestModel(model)
            Citizen.Wait(0)
        end
        SetPlayerModel(PlayerId(), model)
        SetPedComponentVariation(GetPlayerPed(-1), 0, 0, 0, 2)
    end)
end)

Server.lua

local skins = {
    ['default'] = 'mp_m_freemode_01',
    ['steam:12314214xsa21'] = 'a_f_y_hipster_02'
}

RegisterServerEvent('playerSpawn')
AddEventHandler('playerSpawn', function()
    local steamID = nil
    for k,v in ipairs(GetPlayerIdentifiers(source)) do
        if string.sub(v, 1, 5) == "steam" then
            steamID = string.lower(v)
            break
        end
    end
    local skin = nil
    if skins[steamID] ~= nil then
        skin = skins[steamID]
    else
        skin = skins['default']
    end
    TriggerClientEvent("applyskin", source, skin)
end)
6 Likes

@n0mad_b
It sets skins to player, but when player is not listed in script he is invisible.

Add this : SetPedComponentVariation(GetPlayerPed(-1), 0, 0, 0, 2)

Okay, now it sets the same ped to player, i mean i have esx scripts, and it set the same ped for all players, i want to set the model only for players that are writed in lua, and i want script to let the players have their own characters.

Then search for script doing it and disable it…

but the script doing it is that u writed.

when i restart server skin set to default as mp_m_freemode_01
how to fix it ?

Hey there , blaizz can you help that script works?

Hi guys,

A question, is it possible to reset the model
I want to create a command, when you hit it, you change the player into the model
And when you hit it a second time, you come back to your “normal” skin (esx_skin, skinchanger)

You should create your own topic