Client Open Files
Open Source Files
RegisterNetEvent('nf-skin:client:loadSkin', function(model, payload)
model = model or "mp_m_freemode_01"
Citizen.CreateThread(function()
if Framework.QBCore() then
if not model then
model = "mp_m_freemode_01"
if Framework.PlayerData.charinfo.gender == 1 then
model = "mp_f_freemode_01"
end
end
elseif Framework.ESX() then
if not model then
model = "mp_m_freemode_01"
if Framework.PlayerData.sex == "f" then
model = "mp_f_freemode_01"
end
end
end
SkinChanger.model = model
SkinChanger.skinData.model = model
SkinChanger:SetPedModel(model, function(playerPed)
SkinChanger:SetPedAppearance(playerPed, payload or SkinChanger.skinData)
SetEntityMaxHealth(playerPed, 200)
SetEntityHealth(playerPed, SkinChanger.health)
SetPedArmour(playerPed, SkinChanger.armour)
SetPlayerHealthRechargeMultiplier(cache.playerId, 0.0)
SetPlayerHealthRechargeLimit(cache.playerId, 0.0)
end)
end)
end)
RegisterNetEvent('nf-skin:client:openMenu', function()
SkinChanger:OpenMenu({
navSelected = 'head_blend',
navList = {
'head_blend', 'face_feature', 'head_overlay', 'hair_styles', 'clothes', 'tattoos'
},
})
end)
RegisterNetEvent('nf-skin:client:openOutfitMenu', function(payload)
local outfits = lib.callback.await('nf-skin:server:getOutfits', false, payload)
SkinChanger:OpenMenu({
navSelected = 'outfits',
navList = {
'outfits'
},
outfits = outfits,
})
end)
RegisterNetEvent('nf-skin:client:loadPlayerClothing', function(entity, payload)
SkinChanger:SetPedAppearance(entity, payload or SkinChanger.skinData)
end)
RegisterNetEvent('nf-skin:textUI', function(text)
if text == false then
lib.hideTextUI()
else
lib.showTextUI(text)
end
end)
RegisterNetEvent('nf-skin:client:saveSkin', function()
TriggerServerEvent('nf-skin:server:saveSkin', nil, SkinChanger.model, SkinChanger.skinData)
end)
SkinChanger = {
model = nil,
skinData = lib.table.deepclone(Config.SkinData),
temp_model = nil,
temp_skinData = {},
isLoaded = false,
isOpen = false,
health = 200,
armour = 0,
}
RegisterNuiCallback('isLoaded', function(payload, cb)
if SkinChanger.isLoaded then
return cb({
isSuccess = false,
})
end
SkinChanger.isLoaded = true
cb({
isSuccess = true,
config = Config.UI,
translations = Config.LocaleUI
})
end)
function SkinChanger:OpenMenu(payload)
self.health = GetEntityHealth(cache.ped)
self.armour = GetPedArmour(cache.ped)
payload.model = self.model or self.skinData.model
self.temp_model = self.model or self.skinData.model
self.temp_skinData = lib.table.deepclone(self.skinData)
SendNUIMessage({
eventName = 'openMenu',
payload = payload
})
SetNuiFocus(true, true)
SetNuiFocusKeepInput(true)
exports['nf-core']:DragPedCameraStart({
initFov = 50.0,
minFov = 20.0,
maxFov = 60.0,
})
self.isOpen = true
end
function SkinChanger:OpenCreator(cb)
self:OpenMenu({
navSelected = 'head_blend',
navList = {
'head_blend', 'face_feature', 'head_overlay', 'hair_styles', 'clothes', 'tattoos'
},
closeButton = false,
})
local isClosed = lib.waitFor(function()
if not self.isOpen then
return true
end
end, "Error", false)
if isClosed then
cb()
end
end
RegisterNuiCallback('closeMenu', function(payload, cb)
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
exports['nf-core']:DragPedCameraStop()
SendNUIMessage({
eventName = 'closeMenu'
})
if payload == "old_skin" then
SkinChanger.model = SkinChanger.temp_model
SkinChanger.skinData = SkinChanger.temp_skinData
end
SkinChanger:SetPedModel(SkinChanger.model)
SkinChanger:SetPedAppearance(cache.ped, SkinChanger.skinData)
SkinChanger.isOpen = false
cb(0)
end)
RegisterNuiCallback('toggleKeepInput', function(payload, cb)
SetNuiFocusKeepInput(payload)
cb(0)
end)
RegisterNuiCallback('setAnimation', function(payload, cb)
exports['nf-core']:SetAnimation(payload.animDict, payload.animName)
cb(0)
end)
RegisterNuiCallback('stopAnimation', function(_, cb)
exports['nf-core']:StopAnimation()
cb(0)
end)
RegisterNuiCallback('setLightIntensity', function(payload, cb)
exports['nf-core']:SetLightIntensity(payload)
cb(0)
end)
RegisterNuiCallback('changeCamera', function(payload, cb)
exports['nf-core']:SetFocusOn(payload.boneIndex, payload.fov)
cb(0)
end)
RegisterNuiCallback('hideClothes', function(_, cb)
if SkinChanger:IsFreemodeModel() then
local hiddenClothes = Config.HiddenClothesMale
if SkinChanger:CheckFreemodeModel("mp_f_freemode_01") then
hiddenClothes = Config.HiddenClothesFemale
end
SkinChanger:SetPedComponents(cache.ped, hiddenClothes.components, false)
SkinChanger:SetPedProps(cache.ped, hiddenClothes.props, false)
end
cb(0)
end)
RegisterNuiCallback('showClothes', function(_, cb)
if SkinChanger:IsFreemodeModel() then
SkinChanger:SetPedComponents(cache.ped, SkinChanger.skinData.components)
SkinChanger:SetPedProps(cache.ped, SkinChanger.skinData.props)
end
cb(0)
end)
if not Framework.QBCore() then
return
end
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('nf-skin:client:refresh_skin', function()
if not LocalPlayer.state.isLoggedIn then
return
end
SkinChanger:SetPedAppearance(cache.ped, SkinChanger.skinData)
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
Framework.PlayerData = QBCore.Functions.GetPlayerData()
Framework.Job = Framework.PlayerData.job.name
Framework.JobGrade = Framework.PlayerData.job.grade.level
Framework.Gang = Framework.PlayerData.gang.name
Framework.GangGrade = Framework.PlayerData.gang.grade.level
Framework.Jobs = QBCore.Shared.Jobs
Framework.Gangs = QBCore.Shared.Gangs
SkinChanger.skinData = lib.table.deepclone(Config.SkinData)
SkinChanger.temp_skinData = {}
SkinChanger.model = "mp_m_freemode_01"
SkinChanger.health = GetEntityHealth(cache.ped)
SkinChanger.armour = Framework.PlayerData.metadata['armor']
TriggerServerEvent('nf-skin:server:loadPlayerSkin')
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
SkinChanger.skinData = lib.table.deepclone(Config.SkinData)
SkinChanger.temp_skinData = {}
SkinChanger.model = "mp_m_freemode_01"
SkinChanger.health = 200
SkinChanger.armour = 0
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
Framework.Job = job.name
Framework.JobGrade = job.grade.level
end)
RegisterNetEvent('QBCore:Client:OnGangUpdate', function(gang)
Framework.Gang = gang.name
Framework.GangGrade = gang.grade.level
end)
RegisterNetEvent('QBCore:Player:SetPlayerData', function(newPlayerData)
Framework.PlayerData = newPlayerData
end)
RegisterNetEvent('qb-clothes:client:CreateFirstCharacter', function()
local model = "mp_m_freemode_01"
if Framework.PlayerData.charinfo.gender == 1 then
model = "mp_f_freemode_01"
end
SkinChanger:SetPedModel(model, function(entityPed)
SkinChanger:SetPedAppearance(entityPed, SkinChanger.skinData)
Citizen.Wait(2000)
SkinChanger:OpenMenu({
navSelected = 'head_blend',
navList = {
'head_blend', 'face_feature', 'head_overlay', 'hair_styles', 'clothes', 'tattoos'
},
closeButton = false,
})
end)
end)
RegisterNetEvent('qb-clothing:client:loadOutfit', function(payload)
local props = {
'hat',
'glass',
'ear',
'watch',
'bracelet',
}
for k, v in pairs(payload.outfitData) do
if props[k] then
SkinChanger:SetPedProp(cache.ped, props[k], { v.item, v.texture })
else
SkinChanger:SetPedComponent(cache.ped, k, { v.item, v.texture })
end
end
end)
RegisterNetEvent('qb-clothing:client:loadPlayerClothing', function(payload, entity)
SkinChanger:SetPedAppearance(entity, payload or SkinChanger.skinData)
end)
RegisterNetEvent('qb-clothing:client:openMenu', function()
TriggerEvent('nf-skin:client:openMenu')
end)
RegisterNetEvent('qb-clothing:client:openOutfitMenu', function()
TriggerEvent('nf-skin:client:openOutfitMenu')
end)
AddEventHandler('onResourceStart', function(resourceName)
if resourceName ~= GetCurrentResourceName() then
return
end
exports['nf-core']:DragPedCameraStop()
if not LocalPlayer.state.isLoggedIn then
return
end
SkinChanger.skinData = lib.table.deepclone(Config.SkinData)
SkinChanger.temp_skinData = {}
Framework.PlayerData = QBCore.Functions.GetPlayerData()
Framework.Job = Framework.PlayerData.job.name
Framework.JobGrade = Framework.PlayerData.job.grade.level
Framework.Gang = Framework.PlayerData.gang.name
Framework.GangGrade = Framework.PlayerData.gang.grade.level
Framework.Jobs = QBCore.Shared.Jobs
Framework.Gangs = QBCore.Shared.Gangs
SkinChanger.health = 200
SkinChanger.armour = Framework.PlayerData.metadata['armor']
TriggerServerEvent('nf-skin:server:loadPlayerSkin')
end)
print("^2QBCore Framework is successfully initialized^7")
if not Framework.ESX() then
return
end
local ESX = exports["es_extended"]:getSharedObject()
RegisterNetEvent('nf-skin:client:refresh_skin', function()
if not ESX.IsPlayerLoaded() then
return
end
SkinChanger:SetPedAppearance(cache.ped, SkinChanger.skinData)
end)
RegisterNetEvent("esx:playerLoaded", function(xPlayer)
Framework.PlayerData = xPlayer
Framework.Job = xPlayer.job.name
Framework.JobGrade = xPlayer.job.grade
Framework.Gang = xPlayer.job.name
Framework.GangGrade = xPlayer.job.grade
Framework.Jobs = lib.callback.await("nf-skin:server:getJobs", false)
Framework.Gangs = Framework.Jobs
SkinChanger.health = Framework.PlayerData.metadata['health'] or 200
SkinChanger.armour = Framework.PlayerData.metadata['armor'] or 0
end)
RegisterNetEvent('esx:setJob', function(job)
Framework.Job = job.name
Framework.JobGrade = job.grade
Framework.Gang = job.grade
Framework.GangGrade = job.grade
end)
function SkinChanger:OpenCreationMenu(entityPed, cb)
self:SetPedAppearance(entityPed, Config.SkinData)
self:OpenMenu({
navSelected = 'head_blend',
navList = {
'head_blend', 'face_feature', 'head_overlay', 'hair_styles', 'clothes', 'tattoos'
},
closeButton = false,
})
local isClosed = lib.waitFor(function()
if not self.isOpen then
return true
end
end, "Error", false)
if isClosed then
cb()
end
end
exports('OpenCreationMenu', function(entityPed, cb)
SkinChanger:OpenCreationMenu(entityPed, cb)
end)
AddEventHandler('onResourceStart', function(resourceName)
if resourceName ~= GetCurrentResourceName() then
return
end
exports['nf-core']:DragPedCameraStop()
if not ESX.IsPlayerLoaded() then
return
end
SkinChanger.skinData = lib.table.deepclone(Config.SkinData)
SkinChanger.temp_skinData = {}
Framework.PlayerData = ESX.GetPlayerData()
Framework.Job = Framework.PlayerData.job.name
Framework.JobGrade = Framework.PlayerData.job.grade
Framework.Gang = Framework.PlayerData.job.name
Framework.GangGrade = Framework.PlayerData.job.grade
Framework.Jobs = lib.callback.await("nf-skin:server:getJobs", false)
Framework.Gangs = Framework.Jobs
SkinChanger.health = Framework.PlayerData.metadata['health'] or 200
SkinChanger.armour = Framework.PlayerData.metadata['armor'] or 0
TriggerServerEvent('nf-skin:server:loadPlayerSkin')
end)
print("^2ESX Framework is successfully initialized^7")
if not Config.EnableClothing then
return
end
SkinChanger.clothingMenu = {
components = {},
props = {}
}
function SkinChanger:ToggleClothing(type, name)
local hiddenClothes = Config.HiddenClothesMale
if SkinChanger:CheckFreemodeModel("mp_f_freemode_01") then
hiddenClothes = Config.HiddenClothesFemale
end
if type == 'props' then
local prop = self:GetPedProp(cache.ped, name)
if prop[1] ~= hiddenClothes.props[name][1] then
self.clothingMenu.props[name] = prop
self:SetPedProp(cache.ped, name, hiddenClothes.props[name])
else
self:SetPedProp(cache.ped, name, self.clothingMenu.props[name] or hiddenClothes.props[name])
self.clothingMenu.props[name] = nil
end
elseif type == 'components' then
local component = self:GetPedComponent(cache.ped, name)
if component[1] ~= hiddenClothes.components[name][1] then
self.clothingMenu.components[name] = component
self:SetPedComponent(cache.ped, name, hiddenClothes.components[name])
else
self:SetPedComponent(cache.ped, name, self.clothingMenu.components[name] or hiddenClothes.components[name])
self.clothingMenu.components[name] = nil
end
end
end
lib.registerRadial({
id = 'clothing_menu',
items = {
{
label = _L('hat'),
icon = 'fa-hat-cowboy',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('props', 'hat')
end
},
{
label = _L('glasses'),
icon = 'fa-glasses',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('props', 'glass')
end
},
{
label = _L('ear'),
icon = 'fa-shirt',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('props', 'ear')
end
},
{
label = _L('watch'),
icon = 'fa-clock',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('props', 'watch')
end
},
{
label = _L('bracelet'),
icon = 'fa-shirt',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('props', 'bracelet')
end
},
{
label = _L('mask'),
icon = 'fa-mask',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'mask')
end
},
{
label = _L('pants'),
icon = 'fa-shirt',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'pants')
end
},
{
label = _L('bag'),
icon = 'fa-bag-shopping',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'bag')
end
},
{
label = _L('shoes'),
icon = 'fa-shoe-prints',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'shoes')
end
},
{
label = _L('accessory'),
icon = 'fa-shirt',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'accessory')
end
},
{
label = _L('vest'),
icon = 'fa-vest',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'vest')
end
},
{
label = _L('decals'),
icon = 'fa-shirt',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'decals')
end
},
{
label = _L('torso'),
icon = 'fa-shirt',
keepOpen = true,
onSelect = function()
SkinChanger:ToggleClothing('components', 'torso2')
SkinChanger:ToggleClothing('components', 't-shirt')
SkinChanger:ToggleClothing('components', 'arms')
end
},
}
})
lib.addRadialItem({
{
id = 'clothing',
label = _L('clothing'),
icon = 'tshirt',
menu = 'clothing_menu'
},
})
function SkinChanger:IsFreemodeModel()
return self.model == "mp_m_freemode_01" or self.model == "mp_f_freemode_01"
end
function SkinChanger:CheckFreemodeModel(model)
return self.model == model
end
function SkinChanger:IsPedMale(playerPed)
local currentModel = GetEntityModel(playerPed)
local findModel = lib.array.find(self:FilterPedModelsForPlayer(Config.ManPlayerModels, true), function(model)
return joaat(model) == currentModel
end)
return findModel and true or false
end
function SkinChanger:FilterPedModelsForPlayer(pedConfigs, ignore)
local playerPeds = {}
if ignore == nil then
local allowedAces = lib.callback.await("nf-skin:server:getPlayerAces", false)
for i = 1, #pedConfigs do
local config = pedConfigs[i]
if (not config.jobs and not config.gangs and not config.citizenids and not config.aces) or AllowedForPlayer(config, allowedAces) then
for j = 1, #config.peds do
playerPeds[#playerPeds + 1] = config.peds[j]
end
end
end
else
for i = 1, #pedConfigs do
local config = pedConfigs[i]
for j = 1, #config.peds do
playerPeds[#playerPeds + 1] = config.peds[j]
end
end
end
return playerPeds
end
function SkinChanger:GetPedHashName(entityPed)
local pedModel = GetEntityModel(entityPed)
local pedName = lib.array.find(self:FilterPedModelsForPlayer(Config.ManPlayerModels, true), function(model)
return joaat(model) == pedModel
end)
if not pedName then
pedName = lib.array.find(self:FilterPedModelsForPlayer(Config.WomanPlayerModels, true), function(model)
return joaat(model) == pedModel
end)
end
return pedName
end
Last updated