Skip to content

Commit

Permalink
feat(client): Allow disabling components / props entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
TheiLLeniumStudios committed Jul 2, 2022
1 parent ed6c2a5 commit 7efac2a
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 94 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Discord: https://discord.gg/ZVJEkjUTkx
- Blacklist / Limit Peds to certain Jobs / Gangs / ACEs
- Persist Job / Gang Clothes on reconnects / logout
- Themes Support (Default & QBCore provided out of the box)
- Disable Components / Props Entirely (Clothing as items support)

## New Preview (with Tattoos)

Expand Down Expand Up @@ -261,6 +262,12 @@ You can customize every theme using the parameters defined in `theme.json`. Foll

*Note:* After creating the custom theme, make sure to change `currentTheme` to the `id` of the new theme. You can ofcourse modify the existing themes as well if you want, but it is recommended to create your own so that you can switch between the defaults and the custom one whenever needed.

## Disabling Components / Props entirely

You can now disable any Component / Prop using `shared/config.lua` if you have some clothing as items.
- For example if you want to disable Masks then you can change `Masks` value to `true` under `Config.DisableComponents`.
- For example if you want to disable Watches then you can change `Watches` to `true` under `Component.DisableProps`.

## Credits
- Original Script: https://github.com/pedr0fontoura/fivem-appearance
- Tattoo's Support: https://github.com/franfdezmorales/fivem-appearance
Expand Down
155 changes: 84 additions & 71 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ local function InitAppearance()
if not appearance then
return
end
exports['fivem-appearance']:setPlayerAppearance(appearance)
exports['is-clothing']:setPlayerAppearance(appearance)
if Config.PersistUniforms then
LoadPlayerUniform()
end
Expand Down Expand Up @@ -142,16 +142,55 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
InitAppearance()
end)

local function getConfigForPermission(hasPedPerms)
local config = {
ped = true,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
tattoos = true
local function getComponentConfig()
return {
masks = not Config.DisableComponents.Masks,
upperBody = not Config.DisableComponents.UpperBody,
lowerBody = not Config.DisableComponents.LowerBody,
bags = not Config.DisableComponents.Bags,
shoes = not Config.DisableComponents.Shoes,
scarfAndChains = not Config.DisableComponents.ScarfAndChains,
bodyArmor = not Config.DisableComponents.BodyArmor,
shirts = not Config.DisableComponents.Shirts,
decals = not Config.DisableComponents.Decals,
jackets = not Config.DisableComponents.Jackets
}
end

local function getPropConfig()
return {
hats = not Config.DisableProps.Hats,
glasses = not Config.DisableProps.Glasses,
ear = not Config.DisableProps.Ear,
watches = not Config.DisableProps.Watches,
bracelets = not Config.DisableProps.Bracelets
}
end

local function getDefaultConfig()
return {
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = false,
components = false,
componentConfig = getComponentConfig(),
props = false,
propConfig = getPropConfig(),
tattoos = false,
enableExit = true,
}
end

local function getConfigForPermission(hasPedPerms)
local config = getDefaultConfig()
config.ped = true
config.headBlend = true
config.faceFeatures = true
config.headOverlays = true
config.components = true
config.props = true
config.tattoos = true

if Config.EnablePedMenu then
config.ped = hasPedPerms
Expand All @@ -166,15 +205,15 @@ RegisterNetEvent('qb-clothes:client:CreateFirstCharacter', function()
if pd.charinfo.gender == 1 then
skin = "mp_f_freemode_01"
end
exports['fivem-appearance']:setPlayerModel(skin)
exports['is-clothing']:setPlayerModel(skin)
-- Fix for tattoo's appearing when creating a new character
local ped = PlayerPedId()
exports['fivem-appearance']:setPedTattoos(ped, {})
exports['is-clothing']:setPedTattoos(ped, {})
ClearPedDecorations(ped)
QBCore.Functions.TriggerCallback("QBCore:HasPermission", function(permission)
local config = getConfigForPermission(permission)
config.disableCancel = true
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
config.enableExit = false
exports['is-clothing']:startPlayerCustomization(function(appearance)
if (appearance) then
TriggerServerEvent('fivem-appearance:server:saveAppearance', appearance)
ResetRechargeMultipliers()
Expand All @@ -191,7 +230,7 @@ function OpenShop(config, isPedMenu, shopType)
return
end

exports['fivem-appearance']:startPlayerCustomization(function(appearance)
exports['is-clothing']:startPlayerCustomization(function(appearance)
if appearance then
if not isPedMenu then
TriggerServerEvent("fivem-appearance:server:chargeCustomer", shopType)
Expand All @@ -205,63 +244,37 @@ function OpenShop(config, isPedMenu, shopType)
end

local function OpenClothingShop(isPedMenu)
local config = {
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = false,
components = true,
props = true,
tattoos = false
}
local config = getDefaultConfig()
config.components = true
config.props = true

if isPedMenu then
config = {
ped = true,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
tattoos = true
}
config.ped = true
config.headBlend = true
config.faceFeatures = true
config.headOverlays = true
config.tattoos = true
end
OpenShop(config, isPedMenu, 'clothing')
end

local function OpenBarberShop()
OpenShop({
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = true,
components = false,
props = false,
tattoos = false
}, false, 'barber')
local config = getDefaultConfig()
config.headOverlays = true
OpenShop(config, false, 'barber')
end

local function OpenTattooShop()
OpenShop({
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = false,
components = false,
props = false,
tattoos = true
}, false, 'tattoo')
local config = getDefaultConfig()
config.tattoos = true
OpenShop(config, false, 'tattoo')
end

local function OpenSurgeonShop()
OpenShop({
ped = false,
headBlend = true,
faceFeatures = true,
headOverlays = false,
components = false,
props = false,
tattoos = false
}, false, 'surgeon')
local config = getDefaultConfig()
config.headBlend = true
config.faceFeatures = true
OpenShop(config, false, 'surgeon')
end

RegisterNetEvent('fivem-appearance:client:openClothingShop', OpenClothingShop)
Expand Down Expand Up @@ -295,9 +308,9 @@ RegisterNetEvent('fivem-appearance:client:saveOutfit', function()
end

local playerPed = PlayerPedId()
local pedModel = exports['fivem-appearance']:getPedModel(playerPed)
local pedComponents = exports['fivem-appearance']:getPedComponents(playerPed)
local pedProps = exports['fivem-appearance']:getPedProps(playerPed)
local pedModel = exports['is-clothing']:getPedModel(playerPed)
local pedComponents = exports['is-clothing']:getPedComponents(playerPed)
local pedProps = exports['is-clothing']:getPedProps(playerPed)

TriggerServerEvent('fivem-appearance:server:saveOutfit', keyboard.input, pedModel, pedComponents, pedProps)
end)
Expand Down Expand Up @@ -445,13 +458,13 @@ end)

RegisterNetEvent("fivem-appearance:client:changeOutfit", function(data)
local playerPed = PlayerPedId()
local pedModel = exports['fivem-appearance']:getPedModel(playerPed)
local pedModel = exports['is-clothing']:getPedModel(playerPed)
local failed = false
local appearanceDB = nil
if pedModel ~= data.model then
QBCore.Functions.TriggerCallback("fivem-appearance:server:getAppearance", function(appearance)
if appearance then
exports['fivem-appearance']:setPlayerAppearance(appearance)
exports['is-clothing']:setPlayerAppearance(appearance)
appearanceDB = appearance
ResetRechargeMultipliers()
else
Expand All @@ -462,18 +475,18 @@ RegisterNetEvent("fivem-appearance:client:changeOutfit", function(data)
end
end, data.model)
else
appearanceDB = exports['fivem-appearance']:getPedAppearance(playerPed)
appearanceDB = exports['is-clothing']:getPedAppearance(playerPed)
end
if not failed then
while not appearanceDB do
Wait(100)
end
playerPed = PlayerPedId()
exports['fivem-appearance']:setPedComponents(playerPed, data.components)
exports['fivem-appearance']:setPedProps(playerPed, data.props)
exports['fivem-appearance']:setPedHair(playerPed, appearanceDB.hair)
exports['is-clothing']:setPedComponents(playerPed, data.components)
exports['is-clothing']:setPedProps(playerPed, data.props)
exports['is-clothing']:setPedHair(playerPed, appearanceDB.hair)

local appearance = exports['fivem-appearance']:getPedAppearance(playerPed)
local appearance = exports['is-clothing']:getPedAppearance(playerPed)
TriggerServerEvent('fivem-appearance:server:saveAppearance', appearance)
end
end)
Expand Down Expand Up @@ -520,7 +533,7 @@ RegisterNetEvent('fivem-appearance:client:reloadSkin', function()
if not appearance then
return
end
exports['fivem-appearance']:setPlayerAppearance(appearance)
exports['is-clothing']:setPlayerAppearance(appearance)
if Config.PersistUniforms then
TriggerServerEvent("fivem-appearance:server:syncUniform", nil)
end
Expand Down
Loading

0 comments on commit 7efac2a

Please sign in to comment.