[Request] Set the player model


#1

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


#2

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.


#3

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)

#4

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


#5

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


#7

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.


#8

Then search for script doing it and disable it…


#9

but the script doing it is that u writed.