2025-09-03 00:28:17 -05:00
|
|
|
if IsDuplicityVersion() then return end
|
|
|
|
|
local Clothing = {
|
|
|
|
|
property = "clothing",
|
|
|
|
|
default = {
|
|
|
|
|
components = {},
|
|
|
|
|
props = {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Clothing.ChangeClothes(entityData)
|
|
|
|
|
if entityData.entityType ~= "ped" then return end
|
|
|
|
|
local entity = entityData.spawned
|
|
|
|
|
if not entity or not DoesEntityExist(entity) then return end
|
|
|
|
|
local clothing = entityData.clothing.target
|
|
|
|
|
if clothing then
|
|
|
|
|
if type(clothing) == "number" then
|
|
|
|
|
local player = GetPlayerFromServerId(clothing)
|
|
|
|
|
if player and player ~= -1 then
|
|
|
|
|
clothing = Bridge.Clothing.GetAppearance(GetPlayerPed(player))
|
|
|
|
|
end
|
|
|
|
|
elseif type(clothing) == "string" then
|
2025-09-03 04:06:31 -05:00
|
|
|
local targetEntityData = Bridge.Entity.Get(clothing)
|
2025-09-03 00:28:17 -05:00
|
|
|
if targetEntityData then
|
|
|
|
|
clothing = Bridge.Clothing.GetAppearance(targetEntityData.spawned)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
clothing = entityData.clothing
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Bridge.Clothing.SetAppearance(entity, clothing)
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "clothing", clothing)
|
2025-09-03 00:28:17 -05:00
|
|
|
entityData.oldClothing = clothing
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "oldClothing", clothing)
|
2025-09-03 00:28:17 -05:00
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Clothing.OnSpawn(entityData)
|
|
|
|
|
if not entityData.spawned or not entityData.clothing then return end
|
|
|
|
|
Clothing.ChangeClothes(entityData)
|
|
|
|
|
entityData.clothing.updating = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Clothing.OnRemove(entityData)
|
|
|
|
|
if not entityData.spawned or not entityData.clothing then return end
|
|
|
|
|
entityData.oldClothing = nil
|
|
|
|
|
entityData.clothing.updating = true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Clothing.OnUpdate(entityData)
|
|
|
|
|
if not entityData.spawned or not entityData.clothing then return end
|
|
|
|
|
if entityData.clothing.updating then return end
|
|
|
|
|
entityData.clothing.updating = true
|
|
|
|
|
if not entityData.oldClothing then
|
|
|
|
|
Clothing.ChangeClothes(entityData)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
for componentId, component in pairs(entityData.clothing.components or {}) do
|
|
|
|
|
local oldComponent = entityData.oldClothing.components and entityData.oldClothing.components[componentId]
|
|
|
|
|
if not oldComponent or oldComponent.drawable ~= component.drawable or oldComponent.texture ~= component.texture then
|
|
|
|
|
Clothing.ChangeClothes(entityData)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for propId, prop in pairs(entityData.clothing.props or {}) do
|
|
|
|
|
local oldProp = entityData.oldClothing.props and entityData.oldClothing.props[propId]
|
|
|
|
|
if not oldProp or oldProp.drawable ~= prop.drawable or oldProp.texture ~= prop.texture then
|
|
|
|
|
Clothing.ChangeClothes(entityData)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
SetTimeout(1000, function()
|
|
|
|
|
if entityData.clothing then
|
|
|
|
|
entityData.clothing.updating = false
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "clothing", entityData.clothing)
|
2025-09-03 00:28:17 -05:00
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.RegisterBehavior("clothing", Clothing)
|
2025-09-03 00:28:17 -05:00
|
|
|
return Clothing
|