Files

94 lines
2.9 KiB
Lua
Raw Permalink Normal View History

2025-07-11 15:23:24 -04:00
---@diagnostic disable: duplicate-set-field
Clothing = Clothing or {}
local ClothingBackup = {}
2025-09-10 12:27:12 -04:00
---This will get the name of the in use resource.
---@return string
function Clothing.GetResourceName()
2025-09-10 12:27:12 -04:00
return 'default'
end
---This will open the clothing menu for a player, in the event there is not a supported menu it will print that.
function Clothing.OpenMenu()
print("^6 No supported clothing menu in use in community_bridge. ^0 ")
end
---This will check if the player model if male/female
---@return boolean
function Clothing.IsMale()
local ped = PlayerPedId()
if not ped or not DoesEntityExist(ped) then return false end
if GetEntityModel(ped) == `mp_m_freemode_01` then return true end
return false
end
2025-05-24 18:03:31 -05:00
---Get the skin data of a ped
---@param entity number
2025-04-08 19:10:02 -04:00
---@return table
2025-05-24 18:03:31 -05:00
function Clothing.GetAppearance(entity)
if not entity and not DoesEntityExist(entity) then return {} end
2025-05-24 18:03:31 -05:00
local model = GetEntityModel(entity)
local skinData = { model = model, components = {}, props = {} }
for i = 0, 11 do
2025-07-11 15:23:24 -04:00
table.insert(skinData.components,
{ component_id = i, drawable = GetPedDrawableVariation(entity, i), texture = GetPedTextureVariation(entity, i) })
2025-05-24 18:03:31 -05:00
end
for i = 0, 13 do
2025-07-11 15:23:24 -04:00
table.insert(skinData.props,
{ prop_id = i, drawable = GetPedPropIndex(entity, i), texture = GetPedPropTextureIndex(entity, i) })
2025-05-24 18:03:31 -05:00
end
ClothingBackup = skinData
2025-05-24 18:03:31 -05:00
return skinData
end
2026-08-17 03:49:37 -07:00
lib.callback.register('community_bridge:cb:GetAppearance', function()
2025-05-24 18:03:31 -05:00
local ped = PlayerPedId()
if not ped or not DoesEntityExist(ped) then return end
local skinData = Clothing.GetAppearance(ped)
return skinData
end)
---Apply skin data to a ped
---@param ped number
2025-05-24 18:03:31 -05:00
---@param skinData table
2025-04-08 19:10:02 -04:00
---@return boolean
function Clothing.SetAppearance(ped, skinData)
2025-05-24 18:03:31 -05:00
for k, v in pairs(skinData.components or {}) do
if v.component_id then
SetPedComponentVariation(ped, v.component_id, v.drawable, v.texture, 0)
2025-05-24 18:03:31 -05:00
end
end
for k, v in pairs(skinData.props or {}) do
if v.prop_id then
SetPedPropIndex(ped, v.prop_id, v.drawable, v.texture, false)
2025-05-24 18:03:31 -05:00
end
end
ClothingBackup = nil
return true
end
2025-05-24 18:03:31 -05:00
---This will return the peds components to the previously stored components
---@param ped number
2025-04-08 19:10:02 -04:00
---@return boolean
Clothing.RestoreAppearance = function(ped)
Clothing.SetAppearance(ped, ClothingBackup)
2025-02-06 23:33:31 -05:00
return true
end
RegisterNetEvent('community_bridge:client:SetAppearance', function(data)
if source ~= 65535 then return end
2025-05-24 18:03:31 -05:00
Clothing.SetAppearance(PlayerPedId(), data)
2025-02-06 23:33:31 -05:00
end)
RegisterNetEvent('community_bridge:client:GetAppearance', function()
if source ~= 65535 then return end
2025-05-24 18:03:31 -05:00
Clothing.GetAppearance(PlayerPedId())
2025-02-06 23:33:31 -05:00
end)
RegisterNetEvent('community_bridge:client:RestoreAppearance', function()
if source ~= 65535 then return end
2025-05-24 18:03:31 -05:00
Clothing.RestoreAppearance(PlayerPedId())
2025-02-06 23:33:31 -05:00
end)
return Clothing