Files
community_bridge/modules/clothing/_default/client.lua
T

187 lines
6.5 KiB
Lua
Raw Normal View History

--[[This module is incomplete]]--
Clothing = Clothing or {}
2025-02-06 23:33:31 -05:00
ClothingBackup = {}
2025-05-24 18:03:31 -05:00
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
Ultility = Utility or Require('lib/utility/client/utility.lua')
2025-05-24 22:10:39 -05:00
Cache = Cache or Require('lib/cache/shared/cache.lua')
2025-05-24 18:03:31 -05:00
function Clothing.IsMale()
local ped = PlayerPedId()
if not ped then return 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
local model = GetEntityModel(entity)
local skinData = { model = model, components = {}, props = {} }
for i = 0, 11 do
table.insert(skinData.components, { component_id = i, drawable = GetPedDrawableVariation(entity, i), texture = GetPedTextureVariation(entity, i) })
end
for i = 0, 13 do
table.insert(skinData.props, { prop_id = i, drawable = GetPedPropIndex(entity, i), texture = GetPedPropTextureIndex(entity, i) })
end
return skinData
end
function Clothing.CopyAppearanceToClipboard()
local ped = PlayerPedId()
if not ped or not DoesEntityExist(ped) then return end
local skinData = Clothing.GetAppearance(ped)
if not skinData then return end
Ultility.CopyToClipboard(skinData)
end
2025-05-24 18:03:31 -05:00
Callback.Register('community_bridge:cb:GetAppearance', function()
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 entity number
---@param skinData table
2025-04-08 19:10:02 -04:00
---@return boolean
2025-05-24 18:03:31 -05:00
function Clothing.SetAppearance(entity, skinData)
for k, v in pairs(skinData.components or {}) do
if v.component_id then
SetPedComponentVariation(entity, v.component_id, v.drawable, v.texture, 0)
end
end
for k, v in pairs(skinData.props or {}) do
if v.prop_id then
SetPedPropIndex(entity, v.prop_id, v.drawable, v.texture, 0)
end
end
return true
end
2025-05-24 18:03:31 -05:00
---This will return the peds components to the previously stored components
2025-04-08 19:10:02 -04:00
---@return boolean
2025-05-24 18:03:31 -05:00
Clothing.RestoreAppearance = function(entity)
Clothing.SetAppearance(entity, ClothingBackup)
2025-02-06 23:33:31 -05:00
return true
end
Clothing.UpdateAppearanceBackup = function(data)
ClothingBackup = data
end
2025-05-24 22:10:39 -05:00
Clothing.RunningDebug = false
Clothing.Cache = nil -- maybe change this to the actual cache system???!? For future not lazy me
Cache.Create('Clothing', function()
local ped = Cache.Get('Ped')
local appearance = Clothing.GetAppearance(ped)
if Table.Compare(Clothing.Cache, appearance) then
return false
end
return appearance
end, 1000)
local onChange = nil
Clothing.ToggleDebugging = function()
if Clothing.RunningDebug then
Clothing.RunningDebug = false
print("Clothing Debugging Disabled")
return Cache.RemoveOnChange('Clothing', onChange)
end
Clothing.RunningDebug = true
print("Clothing Debugging Enabled")
if Clothing.OpenMenu then
Clothing.OpenMenu()
end
onChange = Cache.OnChange('Clothing', function(new, old)
print("Clothing Debugging", new)
for k, v in pairs(old.components) do
if v.component_id then
if new.components[k].drawable ~= v.drawable or new.components[k].texture ~= v.texture then
print("Component ID: " .. v.component_id .. " Drawable: " .. new.components[k].drawable .. " Texture: " .. new.components[k].texture)
end
end
end
for k, v in pairs(old.props) do
if v.prop_id then
if new.props[k].drawable ~= v.drawable or new.props[k].texture ~= v.texture then
print("Prop ID: " .. v.prop_id .. " Drawable: " .. new.props[k].drawable .. " Texture: " .. new.props[k].texture)
end
end
end
end)
-- CreateThread(function()
-- while Clothing.RunningDebug do
-- Wait(3)
-- local ped = PlayerPedId()
-- if ped then
-- if not Clothing.Cache then
-- Clothing.Cache = Clothing.GetAppearance(ped)
-- end
-- for k, v in pairs(Clothing.Cache.components) do
-- if v.component_id then
-- local drawable = GetPedDrawableVariation(ped, v.component_id)
-- local texture = GetPedTextureVariation(ped, v.component_id)
-- if drawable ~= v.drawable or texture ~= v.texture then
-- print("Component ID: " .. v.component_id .. " Drawable: " .. drawable .. " Texture: " .. texture)
-- Clothing.Cache.components[k].drawable = drawable
-- Clothing.Cache.components[k].texture = texture
-- end
-- end
-- end
-- for k, v in pairs(Clothing.Cache.props) do
-- if v.prop_id then
-- local drawable = GetPedPropIndex(ped, v.prop_id)
-- local texture = GetPedPropTextureIndex(ped, v.prop_id)
-- if drawable ~= v.drawable or texture ~= v.texture then
-- print("Prop ID: " .. v.prop_id .. " Drawable: " .. drawable .. " Texture: " .. texture)
-- Clothing.Cache.props[k].drawable = drawable
-- Clothing.Cache.props[k].texture = texture
-- end
-- end
-- end
-- end
-- -- esc key to exit
-- if IsControlJustPressed(0, 177) then
-- Clothing.RunningDebug = false
-- print("Clothing Debugging Disabled")
-- end
-- end
-- Clothing.Cache = nil
-- end)
end
RegisterCommand("clothing:enabledebug", function(source, args, rawCommand)
Clothing.ToggleDebugging()
end)
2025-02-06 23:33:31 -05:00
RegisterNetEvent('community_bridge:client:SetAppearance', function(data)
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()
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()
2025-05-24 18:03:31 -05:00
Clothing.RestoreAppearance(PlayerPedId())
2025-02-06 23:33:31 -05:00
end)
2025-05-24 18:03:31 -05:00
RegisterCommand("clothing:copy", function(source, args, rawCommand)
Clothing.CopyAppearanceToClipboard()
end)
2025-05-24 22:10:39 -05:00
return Clothing