Clothing and clipboard update
QBClothing and ESKSkin working. Need others (WIP) Copy to clipboard now a utility function. Will json encode if ~= string
This commit is contained in:
1 parent
b9f5a3ed64
commit
d4908042be
16 files changed
+1306
-44
No files matched your search
@@ -13,6 +13,7 @@ shared_scripts {
|
||||
'lib/init.lua',
|
||||
'modules/math/*.lua',
|
||||
'modules/locales/*.lua',
|
||||
'modules/clothing/**/shared.lua',
|
||||
}
|
||||
|
||||
server_scripts {
|
||||
@@ -72,6 +73,7 @@ files {
|
||||
'lib/**/client/*.lua',
|
||||
'lib/**/shared/*.lua',
|
||||
'lib/**/server/*.lua',
|
||||
'modules/**',
|
||||
'settings/*.lua',
|
||||
'lib/init.lua',
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ Utility = Utility or {}
|
||||
local blipIDs = {}
|
||||
local spawnedPeds = {}
|
||||
|
||||
Locales = Locales or Require('modules/locales/shared.lua')
|
||||
|
||||
-- === Local Helpers ===
|
||||
|
||||
---Get the hash of a model (string or number)
|
||||
@@ -409,7 +411,7 @@ end
|
||||
---@param value T The value to match against the cases
|
||||
---@param cases table<T|false, fun(): any> Table with case functions and an optional default (false key)
|
||||
---@return any|false result The return value of the matched case function, or false if none matched
|
||||
function Utility.Switch(value, cases)
|
||||
function Utility.Switch(value, cases)
|
||||
local caseFunc = cases[value] or cases[false]
|
||||
|
||||
if caseFunc and type(caseFunc) == "function" then
|
||||
@@ -420,6 +422,20 @@ function Utility.Switch(value, cases)
|
||||
return false
|
||||
end
|
||||
|
||||
function Utility.CopyToClipboard(text)
|
||||
if not text then return false end
|
||||
if type(text) ~= "string" then
|
||||
text = json.encode(text, { indent = true })
|
||||
end
|
||||
SendNUIMessage({
|
||||
type = "copytoclipboard",
|
||||
text = text
|
||||
})
|
||||
local message = Locales and Locales.Locale("clipboard.copy")
|
||||
TriggerEvent('community_bridge:Client:Notify', message, 'success')
|
||||
return true
|
||||
end
|
||||
|
||||
--[[
|
||||
local vehicleType = "boat"
|
||||
|
||||
|
||||
@@ -41,5 +41,8 @@
|
||||
"cb_tritanopia_desc": "Blue-yellow color blindness that makes someone unable to tell the difference between blue and green, purple and red, and yellow and pink.\nIt also makes colors look less bright.",
|
||||
"cb_tritanomaly_title": "Tritanomaly",
|
||||
"cb_tritanomaly_desc": "Blue-yellow color blindness makes it hard to tell the difference between blue and green and between yellow and red."
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copied to clipboard"
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -23,6 +23,9 @@
|
||||
"cb_tritanopia_title": "Tritanopia",
|
||||
"cb_tritanopia_desc": "Daltonismo azul-amarelo que faz com que alguém não consiga distinguir a diferença entre azul e verde, roxo e vermelho, e amarelo e rosa.\nTambém faz com que as cores pareçam menos brilhantes.",
|
||||
"cb_tritanomaly_title": "Tritanomalia",
|
||||
"cb_tritanomaly_desc": "O daltonismo azul-amarelo dificulta a distinção entre azul e verde e entre amarelo e vermelho.",
|
||||
"cb_tritanomaly_desc": "O daltonismo azul-amarelo dificulta a distinção entre azul e verde e entre amarelo e vermelho."
|
||||
},
|
||||
"clipboard":{
|
||||
"copy": "Copied to clipboard"
|
||||
}
|
||||
}
|
||||
@@ -3,34 +3,71 @@
|
||||
Clothing = Clothing or {}
|
||||
|
||||
ClothingBackup = {}
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
Ultility = Utility or Require('lib/utility/client/utility.lua')
|
||||
|
||||
|
||||
---This will set the peds skin data to the specified table. It will also store previous skin in the event it needs returned to original.
|
||||
---@param data table
|
||||
---@return boolean
|
||||
Clothing.SetAppearance = function(data)
|
||||
ClothingBackup = Clothing.GetAppearance()
|
||||
Utility.SetEntitySkinData(cache.ped, data)
|
||||
return true
|
||||
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
|
||||
|
||||
---This will return a table of the players ped appearance
|
||||
---Get the skin data of a ped
|
||||
---@param entity number
|
||||
---@return table
|
||||
Clothing.GetAppearance = function()
|
||||
return Utility.GetEntitySkinData(cache.ped)
|
||||
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
|
||||
|
||||
---This will return the peds clothing to the previously stored clothing
|
||||
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
|
||||
|
||||
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
|
||||
---@return boolean
|
||||
Clothing.RestoreAppearance = function()
|
||||
Utility.SetEntitySkinData(cache.ped, ClothingBackup)
|
||||
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
|
||||
|
||||
---This will reload the peds skin data from the backup table. This is used when the skin data is changed and needs to be reloaded.
|
||||
---This will return the peds components to the previously stored components
|
||||
---@return boolean
|
||||
Clothing.ReloadSkin = function()
|
||||
Utility.SetEntitySkinData(cache.ped, ClothingBackup)
|
||||
Clothing.RestoreAppearance = function(entity)
|
||||
Clothing.SetAppearance(entity, ClothingBackup)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -38,24 +75,20 @@ Clothing.UpdateAppearanceBackup = function(data)
|
||||
ClothingBackup = data
|
||||
end
|
||||
|
||||
RegisterNetEvent('community_bridge:client:updateClothingBackup', function(skindata)
|
||||
ClothingBackup = skindata
|
||||
end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:SetAppearance', function(data)
|
||||
Clothing.SetAppearance(data)
|
||||
Clothing.SetAppearance(PlayerPedId(), data)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:GetAppearance', function()
|
||||
Clothing.GetAppearance()
|
||||
Clothing.GetAppearance(PlayerPedId())
|
||||
end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:RestoreAppearance', function()
|
||||
Clothing.RestoreAppearance()
|
||||
Clothing.RestoreAppearance(PlayerPedId())
|
||||
end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:ReloadSkin', function()
|
||||
Clothing.ReloadSkin()
|
||||
RegisterCommand("clothing:copy", function(source, args, rawCommand)
|
||||
Clothing.CopyAppearanceToClipboard()
|
||||
end)
|
||||
|
||||
return Clothing
|
||||
@@ -1,34 +1,58 @@
|
||||
--[[This module is incomplete]]--
|
||||
|
||||
Clothing = Clothing or {}
|
||||
Clothing.LastAppearance = Clothing.LastAppearance or {}
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
|
||||
function Clothing.IsMale(src)
|
||||
local ped = GetPlayerPed(src)
|
||||
if not ped or not DoesEntityExist(ped) then return end
|
||||
return GetEntityModel(ped) == `mp_m_freemode_01`
|
||||
end
|
||||
|
||||
|
||||
function Clothing.GetAppearance(src)
|
||||
return Callback.Trigger('community_bridge:cb:GetAppearance', src)
|
||||
end
|
||||
|
||||
Clothing.SetAppearance = function(src, data)
|
||||
local strSrc = tostring(src)
|
||||
Clothing.LastAppearance[strSrc] = Clothing.GetAppearance(src)
|
||||
TriggerClientEvent('community_bridge:client:SetAppearance', src, data)
|
||||
end
|
||||
|
||||
--- Sets a player's appearance based on gender-specific data
|
||||
--- @param src number The server ID of the player
|
||||
--- @param data table Table containing separate appearance data for male and female characters
|
||||
--- @return table|nil Appearance updated player appearance data or nil if failed
|
||||
function Clothing.SetAppearanceExt(src, data)
|
||||
local tbl = Clothing.IsMale(src) and data.male or data.female
|
||||
Clothing.SetAppearance(src, tbl)
|
||||
end
|
||||
|
||||
Clothing.RestoreAppearance = function(src)
|
||||
TriggerClientEvent('community_bridge:client:RestoreAppearance', src)
|
||||
end
|
||||
|
||||
Clothing.ReloadSkin = function(src)
|
||||
TriggerClientEvent('community_bridge:client:ReloadSkin', src)
|
||||
end
|
||||
|
||||
-- RegisterNetEvent('community_bridge:client:SetAppearance', function(data)
|
||||
-- local src = source
|
||||
-- Clothing.SetAppearance(src, data)
|
||||
-- end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:SetAppearance', function(data)
|
||||
Clothing.SetAppearance(data)
|
||||
end)
|
||||
-- RegisterNetEvent('community_bridge:client:GetAppearance', function()
|
||||
-- local src = source
|
||||
-- Clothing.GetAppearance(src)
|
||||
-- end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:GetAppearance', function()
|
||||
Clothing.GetAppearance()
|
||||
end)
|
||||
-- RegisterNetEvent('community_bridge:client:RestoreAppearance', function()
|
||||
-- local src = source
|
||||
-- Clothing.RestoreAppearance(src)
|
||||
-- end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:RestoreAppearance', function()
|
||||
Clothing.RestoreAppearance()
|
||||
end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:ReloadSkin', function()
|
||||
Clothing.ReloadSkin()
|
||||
end)
|
||||
-- RegisterNetEvent('community_bridge:client:ReloadSkin', function()
|
||||
-- local src = source
|
||||
-- Clothing.ReloadSkin(src)
|
||||
-- end)
|
||||
|
||||
return Clothing
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
if GetResourceState('esx_skin') == 'missing' then return end
|
||||
Clothing = Clothing or {}
|
||||
|
||||
function Clothing.OpenMenu()
|
||||
TriggerEvent('esx_skin:openMenu', function()end, function()end, true)
|
||||
end
|
||||
@@ -0,0 +1,210 @@
|
||||
if GetResourceState('esx_skin') == 'missing' then return end
|
||||
Clothing = Clothing or {}
|
||||
Clothing.Players = {}
|
||||
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
Table = Table or Require('lib/utility/shared/tables.lua')
|
||||
ESX = ESX or exports['es_extended']:getSharedObject()
|
||||
|
||||
--- Internal function to get the full appearance data including skin, model, and converted format
|
||||
--- @param src number The server ID of the player
|
||||
--- @return table|nil The player's full appearance data or nil if not found
|
||||
function Clothing.GetFullAppearanceData(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local Player = ESX.GetPlayerFromId(src)
|
||||
if not Player then return end
|
||||
local citId = Player.identifier
|
||||
if not citId then return end
|
||||
|
||||
if Clothing.Players[citId] then return Clothing.Players[citId] end
|
||||
|
||||
local result = MySQL.query.await('SELECT skin FROM users WHERE identifier = ?', { citId})
|
||||
if result[1] == nil then return end
|
||||
|
||||
local model = GetEntityModel(GetPlayerPed(src))
|
||||
local skinData = json.decode(result[1].skin)
|
||||
local converted = Clothing.ConvertToDefault(skinData)
|
||||
|
||||
-- Store complete data in the cache
|
||||
Clothing.Players[citId] = {
|
||||
model = model,
|
||||
skin = skinData,
|
||||
converted = converted
|
||||
}
|
||||
|
||||
return Clothing.Players[citId]
|
||||
end
|
||||
|
||||
--- Retrieves a player's converted appearance data for easy use across modules
|
||||
--- @param src number The server ID of the player
|
||||
--- @param fullData boolean Optional - If true, returns the full data object including skin and model
|
||||
--- @return table|nil The player's converted appearance data or full appearance data if fullData=true
|
||||
function Clothing.GetAppearance(src, fullData)
|
||||
if fullData then
|
||||
return Clothing.GetFullAppearanceData(src)
|
||||
end
|
||||
local completeData = Clothing.GetFullAppearanceData(src)
|
||||
if not completeData then return nil end
|
||||
return completeData.converted
|
||||
end
|
||||
|
||||
|
||||
function Clothing.Save(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local Player = ESX.GetPlayerFromId(src)
|
||||
if not Player then return end
|
||||
local citId = Player.identifier
|
||||
if not citId then return end
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
local currentSkin = currentClothing.skin
|
||||
local encodedSkin = json.encode(currentSkin)
|
||||
MySQL.update.await('UPDATE users SET skin = ? WHERE identifier = ?', {
|
||||
encodedSkin,
|
||||
citId
|
||||
})
|
||||
end
|
||||
--- Sets a player's appearance based on the provided data
|
||||
--- @param src number The server ID of the player
|
||||
--- @param data table The appearance data to apply
|
||||
--- @param updateBackup boolean Whether to update the backup appearance data
|
||||
--- @return table|nil The updated player appearance data or nil if failed
|
||||
function Clothing.SetAppearance(src, data, updateBackup, save)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local Player = ESX.GetPlayerFromId(src)
|
||||
if not Player then return end
|
||||
local citId = Player.identifier
|
||||
if not citId then return end
|
||||
local model = GetEntityModel(GetPlayerPed(src))
|
||||
if not model then return end
|
||||
local converted = Clothing.ConvertFromDefault(data)
|
||||
|
||||
-- Get full appearance data
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
|
||||
local currentSkin = currentClothing.skin
|
||||
for k, v in pairs(converted) do
|
||||
currentSkin[k] = v
|
||||
end
|
||||
|
||||
|
||||
if not Clothing.Players[citId].backup or updateBackup then
|
||||
Clothing.Players[citId].backup = currentClothing.converted
|
||||
end
|
||||
|
||||
Clothing.Players[citId] = Clothing.Players[citId] or {}
|
||||
Clothing.Players[citId].skin = currentSkin
|
||||
Clothing.Players[citId].model = model
|
||||
Clothing.Players[citId].converted = Clothing.ConvertToDefault(currentSkin)
|
||||
if save then
|
||||
local encodedSkin = json.encode(currentSkin)
|
||||
-- saving 1 sql call by adding the query here instead of calling save
|
||||
MySQL.update.await('UPDATE users SET skin = ? WHERE identifier = ?', {
|
||||
encodedSkin,
|
||||
citId
|
||||
})
|
||||
end
|
||||
TriggerClientEvent('community_bridge:client:SetAppearance', src, Clothing.Players[citId].converted)
|
||||
return Clothing.Players[citId]
|
||||
end
|
||||
|
||||
--- Sets a player's appearance based on gender-specific data
|
||||
--- @param src number The server ID of the player
|
||||
--- @param data table Table containing separate appearance data for male and female characters
|
||||
--- @return table|nil Appearance updated player appearance data or nil if failed
|
||||
function Clothing.SetAppearanceExt(src, data)
|
||||
local tbl = Clothing.IsMale(src) and data.male or data.female
|
||||
Clothing.SetAppearance(src, tbl)
|
||||
end
|
||||
|
||||
--- Reverts a player's appearance to their backup appearance
|
||||
--- @param src number The server ID of the player
|
||||
--- @return boolean|nil Returns true if successful or nil if failed
|
||||
function Clothing.Revert(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
local backup = currentClothing.backup
|
||||
if not backup then return end
|
||||
return Clothing.SetAppearance(src, backup)
|
||||
end
|
||||
|
||||
|
||||
function Clothing.OpenMenu(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
TriggerClientEvent('esx_skin:openMenu', src)
|
||||
end
|
||||
|
||||
--- Event handler for when a player loads into the server
|
||||
--- Caches the player's appearance data
|
||||
AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
-- Use GetFullAppearanceData to cache the complete appearance
|
||||
Clothing.GetFullAppearanceData(src)
|
||||
end)
|
||||
|
||||
--- Event handler for when a player disconnects from the server
|
||||
--- Removes the player's appearance data from the cache
|
||||
AddEventHandler('community_bridge:Server:OnPlayerUnload', function(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local strSrc = tostring(src)
|
||||
Clothing.Players[strSrc] = nil
|
||||
end)
|
||||
|
||||
|
||||
|
||||
--- Event handler for when the resource starts
|
||||
--- Caches appearance data for all currently connected players
|
||||
AddEventHandler('onResourceStart', function(resource)
|
||||
if resource ~= GetCurrentResourceName() then return end
|
||||
for _, playerId in ipairs(GetPlayers()) do
|
||||
local src = tonumber(playerId)
|
||||
local strSrc = tostring(src)
|
||||
if not Clothing.Players[strSrc] then
|
||||
Clothing.Players[strSrc] = Clothing.GetAppearance(src)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Callback handler for retrieving a player's appearance data
|
||||
Callback.Register('community_bridge:cb:GetAppearance', function(source)
|
||||
local src = source
|
||||
return Clothing.GetAppearance(src)
|
||||
end)
|
||||
|
||||
|
||||
RegisterCommand('clothing:debug', function(source, args, rawCommand)
|
||||
local src = source
|
||||
Clothing.SetAppearance(src, {
|
||||
components ={
|
||||
{component_id = 1, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 2, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 3, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 4, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 5, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 6, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 7, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 8, drawable = math.random(0, 50), texture = 0},
|
||||
},
|
||||
props = {
|
||||
{prop_id = 3, drawable = 0, texture = 0},
|
||||
{prop_id = 1, drawable = 0, texture = 0},
|
||||
{prop_id = 2, drawable = 0, texture = 0},
|
||||
}
|
||||
})
|
||||
end, false)
|
||||
|
||||
|
||||
RegisterCommand('clothing:revert', function(source, args, rawCommand)
|
||||
local src = source
|
||||
Clothing.Revert(src)
|
||||
end, false)
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
|
||||
if GetResourceState('esx_skin') == 'missing' then return end
|
||||
|
||||
Clothing = Clothing or {}
|
||||
|
||||
-- {"glasses_2":0,"shoes_1":70,"dad":0,"shoes_2":2,"pants_1":28,"eye_squint":0,"ears_1":-1,"hair_color_1":61,"eyebrows_6":0,"bodyb_3":-1,"beard_1":11,"complexion_2":0,"arms_2":0,"hair_1":76,"nose_1":0,"blush_2":0,"bracelets_2":0,"blush_1":0,"jaw_2":0,"helmet_1":-1,"eyebrows_3":0,"watches_1":-1,"eyebrows_4":0,"jaw_1":0,"lipstick_1":0,"eyebrows_1":0,"nose_4":0,"age_2":0,"torso_1":23,"hair_2":0,"chin_2":0,"arms":1,"chain_1":22,"nose_2":0,"cheeks_1":2,"tshirt_1":4,"glasses_1":0,"pants_2":3,"lipstick_4":0,"chin_13":0,"beard_4":0,"beard_3":0,"chain_2":2,"cheeks_3":6,"sex":0,"lipstick_3":0,"makeup_1":0,"hair_color_2":29,"mask_2":0,"chin_1":0,"eyebrows_5":0,"bodyb_2":0,"sun_2":0,"watches_2":0,"sun_1":0,"chin_4":0,"nose_3":0,"helmet_2":0,"bags_2":0,"moles_2":0,"mask_1":0,"blemishes_2":0,"chest_1":0,"cheeks_2":-10,"age_1":0,"chest_2":0,"beard_2":10,"torso_2":2,"blush_3":0,"bproof_1":0,"moles_1":0,"chin_3":0,"lip_thickness":-2,"lipstick_2":0,"chest_3":0,"complexion_1":0,"bodyb_4":0,"neck_thickness":0,"bproof_2":0,"makeup_3":0,"tshirt_2":2,"makeup_2":0,"makeup_4":0,"bracelets_1":-1,"decals_2":0,"nose_6":0,"bodyb_1":-1,"bags_1":0,"blemishes_1":0,"decals_1":0,"mom":21,"eyebrows_2":0,"eye_color":0,"skin_md_weight":50,"face_md_weight":50,"nose_5":10,"ears_2":0}
|
||||
|
||||
Components = {}
|
||||
Components.Map = {
|
||||
[1] = 'mask', -- componentId
|
||||
[2] = 'ears',
|
||||
[3] = 'arms',
|
||||
[4] = 'pants',
|
||||
[5] = 'bags',
|
||||
[6] = 'shoes',
|
||||
[7] = 'chain',
|
||||
[8] = 'tshirt',
|
||||
[9] = 'bproof',
|
||||
[10] = 'decals',
|
||||
[11] = 'torso'
|
||||
}
|
||||
|
||||
Components.InverseMap = {
|
||||
mask = 1, -- componentId
|
||||
arms = 3,
|
||||
pants = 4,
|
||||
bags = 5,
|
||||
shoes = 6,
|
||||
chain = 7,
|
||||
tshirt = 8,
|
||||
bproof = 9,
|
||||
decals = 10,
|
||||
torso = 11,
|
||||
}
|
||||
|
||||
Props = {}
|
||||
Props.Map = {
|
||||
[0] = 'helmet', -- propId
|
||||
[1] = 'glasses',
|
||||
[2] = 'ears',
|
||||
[6] = 'watches',
|
||||
[7] = 'bracelets'
|
||||
}
|
||||
|
||||
Props.InverseMap = {
|
||||
helmet_1 = 0,
|
||||
helmet_2 = 0,
|
||||
glasses_1 = 1,
|
||||
glasses_2 = 1,
|
||||
ears_1 = 2,
|
||||
ears_2 = 2,
|
||||
watches_1 = 6,
|
||||
watches_2 = 6,
|
||||
bracelets_1 = 7,
|
||||
bracelets_2 = 7,
|
||||
}
|
||||
|
||||
-- Converts from illinium format to esx format
|
||||
function Components.ConvertFromDefault(defaultComponents)
|
||||
local returnComponents = {}
|
||||
for index, componentData in pairs(defaultComponents or {}) do
|
||||
local componentId = Components.Map[componentData.component_id]
|
||||
if componentId then
|
||||
returnComponents[componentId .. '_1'] = componentData.drawable
|
||||
returnComponents[componentId .. '_2'] = componentData.texture
|
||||
end
|
||||
end
|
||||
return returnComponents
|
||||
end
|
||||
|
||||
function Components.ConvertToDefault(esxComponents)
|
||||
local returnComponents = {}
|
||||
for componentIndex, componentData in pairs(esxComponents or {}) do
|
||||
local isTexture = componentIndex:find('_2')
|
||||
componentIndex = componentIndex:gsub('_1', ''):gsub('_2', '')
|
||||
local componentId = Components.InverseMap[componentIndex]
|
||||
if componentId then
|
||||
if isTexture then
|
||||
returnComponents[componentId] = returnComponents[componentId] or {}
|
||||
returnComponents[componentId].texture = componentData
|
||||
else
|
||||
returnComponents[componentId] = returnComponents[componentId] or {}
|
||||
returnComponents[componentId].component_id = componentId
|
||||
returnComponents[componentId].drawable = componentData
|
||||
returnComponents[componentId].texture = returnComponents[componentId].texture or 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return returnComponents
|
||||
end
|
||||
|
||||
function Props.ConvertFromDefault(defaultProps)
|
||||
local returnProps = {}
|
||||
for index, propData in pairs(defaultProps or {}) do
|
||||
local propId = Props.Map[propData.prop_id]
|
||||
if propId then
|
||||
returnProps[propId .. '_1'] = propData.drawable
|
||||
returnProps[propId .. '_2'] = propData.texture
|
||||
end
|
||||
end
|
||||
return returnProps
|
||||
end
|
||||
|
||||
function Props.ConvertToDefault(esxProps)
|
||||
local returnProps = {}
|
||||
for propIndex, propData in pairs(esxProps or {}) do
|
||||
local isTexture = propIndex:find('_2')
|
||||
propIndex = propIndex:gsub('_1', ''):gsub('_2', '')
|
||||
local propId = Props.InverseMap[propIndex]
|
||||
if propId then
|
||||
if isTexture then
|
||||
returnProps[propId] = returnProps[propId] or {}
|
||||
returnProps[propId].texture = propData
|
||||
else
|
||||
returnProps[propId] = returnProps[propId] or {}
|
||||
returnProps[propId].prop_id = propId
|
||||
returnProps[propId].drawable = propData
|
||||
returnProps[propId].texture = returnProps[propId].texture or 0
|
||||
end
|
||||
end
|
||||
table.sort(returnProps, function(a, b)
|
||||
return a.prop_id < b.prop_id
|
||||
end)
|
||||
end
|
||||
return returnProps
|
||||
end
|
||||
|
||||
function Clothing.ConvertFromDefault(defaultClothing)
|
||||
local components = Components.ConvertFromDefault(defaultClothing.components)
|
||||
local props = Props.ConvertFromDefault(defaultClothing.props)
|
||||
|
||||
for propsIndex, propData in pairs(props) do
|
||||
components[propsIndex] = propData
|
||||
end
|
||||
|
||||
return components --skin
|
||||
end
|
||||
|
||||
function Clothing.ConvertToDefault(esxClothing)
|
||||
local components = Components.ConvertToDefault(esxClothing)
|
||||
local props = Props.ConvertToDefault(esxClothing)
|
||||
return { components = components, props = props }
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Clothing = {}
|
||||
|
||||
-- StoredOldClothing = {}
|
||||
|
||||
-- Clothing.SetAppearance = function(clothingData)
|
||||
-- if GetEntityModel(cache.ped) == `mp_m_freemode_01` then
|
||||
-- clothingData = clothingData.male
|
||||
-- else
|
||||
-- clothingData = clothingData.female
|
||||
-- end
|
||||
-- local repackedTable = {}
|
||||
-- local componentMap = {
|
||||
-- [1] = "mask",
|
||||
-- [3] = "arms",
|
||||
-- [4] = "pants",
|
||||
-- [5] = "bag",
|
||||
-- [6] = "shoes",
|
||||
-- [7] = "accessory",
|
||||
-- [8] = "t-shirt",
|
||||
-- [9] = "vest",
|
||||
-- [10] = "decals",
|
||||
-- [11] = "torso2"
|
||||
-- }
|
||||
|
||||
-- local propMap = {
|
||||
-- [0] = "hat",
|
||||
-- [1] = "glass",
|
||||
-- [2] = "ear",
|
||||
-- [6] = "watch",
|
||||
-- [7] = "bracelet"
|
||||
-- }
|
||||
|
||||
-- local specialMap = {
|
||||
-- eye_color_id = "eye_color",
|
||||
-- moles_id = "moles",
|
||||
-- ageing_id = "ageing",
|
||||
-- hair_id = "hair",
|
||||
-- face_id = "face"
|
||||
-- }
|
||||
|
||||
-- for _, data in pairs(clothingData) do
|
||||
-- if componentMap[data.component_id] then
|
||||
-- repackedTable[componentMap[data.component_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif propMap[data.prop_id] then
|
||||
-- repackedTable[propMap[data.prop_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.eye_color_id] then
|
||||
-- repackedTable[specialMap[data.eye_color_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.moles_id] then
|
||||
-- repackedTable[specialMap[data.moles_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.ageing_id] then
|
||||
-- repackedTable[specialMap[data.ageing_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.hair_id] then
|
||||
-- repackedTable[specialMap[data.hair_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.face_id] then
|
||||
-- repackedTable[specialMap[data.face_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- end
|
||||
-- end
|
||||
-- TriggerEvent('esx-clothing:client:loadOutfit', repackedTable)
|
||||
-- end
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
|
||||
-- {
|
||||
-- male = {
|
||||
-- name = "Short Sleeve",
|
||||
-- outfitData = {
|
||||
-- ["pants"] = {item = 133, texture = 0}, -- Pants
|
||||
-- ["arms"] = {item = 31, texture = 0}, -- Arms
|
||||
-- ["t-shirt"] = {item = 35, texture = 0}, -- T Shirt
|
||||
-- ["vest"] = {item = 34, texture = 0}, -- Body Vest
|
||||
-- ["torso2"] = {item = 48, texture = 0}, -- Jacket
|
||||
-- ["shoes"] = {item = 52, texture = 0}, -- Shoes
|
||||
-- ["accessory"] = {item = 0, texture = 0}, -- Neck Accessory
|
||||
-- ["bag"] = {item = 0, texture = 0}, -- Bag
|
||||
-- ["hat"] = {item = 0, texture = 0}, -- Hat
|
||||
-- ["glass"] = {item = 0, texture = 0}, -- Glasses
|
||||
-- ["mask"] = {item = 0, texture = 0} -- Mask
|
||||
-- },
|
||||
-- grades = {0, 1, 2, 3, 4},
|
||||
-- },
|
||||
-- female = {
|
||||
-- name = "Short Sleeve",
|
||||
-- outfitData = {
|
||||
-- ["pants"] = {item = 133, texture = 0}, -- Pants
|
||||
-- ["arms"] = {item = 31, texture = 0}, -- Arms
|
||||
-- ["t-shirt"] = {item = 35, texture = 0}, -- T Shirt
|
||||
-- ["vest"] = {item = 34, texture = 0}, -- Body Vest
|
||||
-- ["torso2"] = {item = 48, texture = 0}, -- Jacket
|
||||
-- ["shoes"] = {item = 52, texture = 0}, -- Shoes
|
||||
-- ["accessory"] = {item = 0, texture = 0}, -- Neck Accessory
|
||||
-- ["bag"] = {item = 0, texture = 0}, -- Bag
|
||||
-- ["hat"] = {item = 0, texture = 0}, -- Hat
|
||||
-- ["glass"] = {item = 0, texture = 0}, -- Glasses
|
||||
-- ["mask"] = {item = 0, texture = 0} -- Mask
|
||||
-- },
|
||||
-- }
|
||||
-- }
|
||||
|
||||
-- function Clothing.ConvertData(data)
|
||||
-- return data
|
||||
-- end
|
||||
@@ -0,0 +1,221 @@
|
||||
-- Get appearence data
|
||||
|
||||
-- {
|
||||
-- "tattoos": {
|
||||
-- "ZONE_HAIR": [
|
||||
-- {
|
||||
-- "label": "hair-0-188",
|
||||
-- "collection": "multiplayer_overlays",
|
||||
-- "name": "hair-0-188",
|
||||
-- "hashFemale": "FM_F_Hair_003_c",
|
||||
-- "hashMale": "FM_M_Hair_003_c",
|
||||
-- "zone": "ZONE_HAIR"
|
||||
-- }
|
||||
-- ]
|
||||
-- },
|
||||
-- "components": [
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 0
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 1
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 2
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 3
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 4
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 5
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 6
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 7
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 8
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 9
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 10
|
||||
-- },
|
||||
-- {
|
||||
-- "texture": -1,
|
||||
-- "drawable": -1,
|
||||
-- "component_id": 11
|
||||
-- }
|
||||
-- ],
|
||||
-- "headBlend": {
|
||||
-- "skinSecond": 0,
|
||||
-- "skinMix": 0.0,
|
||||
-- "shapeFirst": 0,
|
||||
-- "shapeThird": 0,
|
||||
-- "skinFirst": 0,
|
||||
-- "shapeMix": 0.0,
|
||||
-- "shapeSecond": 0,
|
||||
-- "skinThird": 0,
|
||||
-- "thirdMix": 0.0
|
||||
-- },
|
||||
-- "hair": {
|
||||
-- "texture": -1,
|
||||
-- "style": -1,
|
||||
-- "color": -1,
|
||||
-- "highlight": -1
|
||||
-- },
|
||||
-- "eyeColor": -1,
|
||||
-- "headOverlays": {
|
||||
-- "lipstick": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "moleAndFreckles": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "ageing": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "makeUp": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "beard": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "blush": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "complexion": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "bodyBlemishes": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "eyebrows": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "chestHair": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "sunDamage": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- },
|
||||
-- "blemishes": {
|
||||
-- "color": 0,
|
||||
-- "style": 0,
|
||||
-- "opacity": 0.0,
|
||||
-- "secondColor": 0
|
||||
-- }
|
||||
-- },
|
||||
-- "faceFeatures": {
|
||||
-- "jawBoneBackSize": 0.0,
|
||||
-- "noseWidth": 0.0,
|
||||
-- "eyeBrownHigh": 0.0,
|
||||
-- "chinBoneSize": 0.0,
|
||||
-- "chinHole": 0.0,
|
||||
-- "neckThickness": 0.0,
|
||||
-- "noseBoneTwist": 0.0,
|
||||
-- "noseBoneHigh": 0.0,
|
||||
-- "nosePeakHigh": 0.0,
|
||||
-- "nosePeakSize": 0.0,
|
||||
-- "eyesOpening": 0.0,
|
||||
-- "cheeksBoneHigh": 0.0,
|
||||
-- "cheeksBoneWidth": 0.0,
|
||||
-- "cheeksWidth": 0.0,
|
||||
-- "lipsThickness": 0.0,
|
||||
-- "nosePeakLowering": 0.0,
|
||||
-- "jawBoneWidth": 0.0,
|
||||
-- "eyeBrownForward": 0.0,
|
||||
-- "chinBoneLenght": 0.0,
|
||||
-- "chinBoneLowering": 0.0
|
||||
-- },
|
||||
-- "model": "mp_m_freemode_01",
|
||||
-- "props": [
|
||||
-- {
|
||||
-- "drawable": -1,
|
||||
-- "prop_id": 0,
|
||||
-- "texture": -1
|
||||
-- },
|
||||
-- {
|
||||
-- "drawable": -1,
|
||||
-- "prop_id": 1,
|
||||
-- "texture": -1
|
||||
-- },
|
||||
-- {
|
||||
-- "drawable": -1,
|
||||
-- "prop_id": 2,
|
||||
-- "texture": -1
|
||||
-- },
|
||||
-- {
|
||||
-- "drawable": -1,
|
||||
-- "prop_id": 6,
|
||||
-- "texture": -1
|
||||
-- },
|
||||
-- {
|
||||
-- "drawable": -1,
|
||||
-- "prop_id": 7,
|
||||
-- "texture": -1
|
||||
-- }
|
||||
-- ]
|
||||
-- }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
if GetResourceState('qb-clothing') == 'missing' then return end
|
||||
Clothing = Clothing or {}
|
||||
|
||||
function Clothing.OpenMenu()
|
||||
TriggerEvent('qb-clothing:client:openMenu')
|
||||
end
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
if GetResourceState('qb-clothing') == 'missing' then return end
|
||||
Clothing = Clothing or {}
|
||||
Clothing.Players = {}
|
||||
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
Table = Table or Require('lib/utility/shared/tables.lua')
|
||||
QBCore = QBCore or exports['qb-core']:GetCoreObject()
|
||||
|
||||
--- Internal function to get the full appearance data including skin, model, and converted format
|
||||
--- @param src number The server ID of the player
|
||||
--- @return table|nil The player's full appearance data or nil if not found
|
||||
function Clothing.GetFullAppearanceData(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then return end
|
||||
local citId = Player.PlayerData.citizenid
|
||||
if not citId then return end
|
||||
|
||||
if Clothing.Players[citId] then return Clothing.Players[citId] end
|
||||
|
||||
local result = MySQL.query.await('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', { citId, 1 })
|
||||
if result[1] == nil then return end
|
||||
|
||||
local model = Player.PlayerData.model
|
||||
local skinData = json.decode(result[1].skin)
|
||||
local converted = Clothing.ConvertToDefault(skinData)
|
||||
|
||||
-- Store complete data in the cache
|
||||
Clothing.Players[citId] = {
|
||||
model = model,
|
||||
skin = skinData,
|
||||
converted = converted
|
||||
}
|
||||
|
||||
return Clothing.Players[citId]
|
||||
end
|
||||
|
||||
--- Retrieves a player's converted appearance data for easy use across modules
|
||||
--- @param src number The server ID of the player
|
||||
--- @param fullData boolean Optional - If true, returns the full data object including skin and model
|
||||
--- @return table|nil The player's converted appearance data or full appearance data if fullData=true
|
||||
function Clothing.GetAppearance(src, fullData)
|
||||
if fullData then
|
||||
return Clothing.GetFullAppearanceData(src)
|
||||
end
|
||||
local completeData = Clothing.GetFullAppearanceData(src)
|
||||
if not completeData then return nil end
|
||||
return completeData.converted
|
||||
end
|
||||
|
||||
--- Sets a player's appearance based on the provided data
|
||||
--- @param src number The server ID of the player
|
||||
--- @param data table The appearance data to apply
|
||||
--- @param updateBackup boolean Whether to update the backup appearance data
|
||||
--- @return table|nil The updated player appearance data or nil if failed
|
||||
function Clothing.SetAppearance(src, data, updateBackup, save)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then return end
|
||||
local citId = Player.PlayerData.citizenid
|
||||
if not citId then return end
|
||||
local model = GetEntityModel(GetPlayerPed(src))
|
||||
if not model then return end
|
||||
local converted = Clothing.ConvertFromDefault(data)
|
||||
|
||||
-- Get full appearance data
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
|
||||
local currentSkin = currentClothing.skin
|
||||
for k, v in pairs(converted) do
|
||||
currentSkin[k] = v
|
||||
end
|
||||
|
||||
if not Clothing.Players[citId].backup or updateBackup then
|
||||
Clothing.Players[citId].backup = currentClothing.converted
|
||||
end
|
||||
|
||||
Clothing.Players[citId] = Clothing.Players[citId] or {}
|
||||
Clothing.Players[citId].skin = currentSkin
|
||||
Clothing.Players[citId].model = model
|
||||
Clothing.Players[citId].converted = Clothing.ConvertToDefault(currentSkin)
|
||||
if save then
|
||||
MySQL.update.await('UPDATE playerskins SET skin = ? WHERE citizenid = ? AND active = ?', {
|
||||
json.encode(currentSkin),
|
||||
citId,
|
||||
1
|
||||
})
|
||||
end
|
||||
TriggerClientEvent('community_bridge:client:SetAppearance', src, Clothing.Players[citId].converted)
|
||||
return Clothing.Players[citId]
|
||||
end
|
||||
|
||||
--- Sets a player's appearance based on gender-specific data
|
||||
--- @param src number The server ID of the player
|
||||
--- @param data table Table containing separate appearance data for male and female characters
|
||||
--- @return table|nil Appearance updated player appearance data or nil if failed
|
||||
function Clothing.SetAppearanceExt(src, data)
|
||||
local tbl = Clothing.IsMale(src) and data.male or data.female
|
||||
Clothing.SetAppearance(src, tbl)
|
||||
end
|
||||
|
||||
--- Reverts a player's appearance to their backup appearance
|
||||
--- @param src number The server ID of the player
|
||||
--- @return boolean|nil Returns true if successful or nil if failed
|
||||
function Clothing.Revert(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local currentClothing = Clothing.GetFullAppearanceData(src)
|
||||
if not currentClothing then return end
|
||||
local backup = currentClothing.backup
|
||||
print(src, backup)
|
||||
if not backup then return end
|
||||
return Clothing.SetAppearance(src, backup)
|
||||
end
|
||||
|
||||
function Clothing.OpenMenu(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
TriggerClientEvent('qb-clothing:client:openMenu', src)
|
||||
end
|
||||
|
||||
--- Event handler for when a player loads into the server
|
||||
--- Caches the player's appearance data
|
||||
AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then return end
|
||||
local citId = Player.PlayerData.citizenid
|
||||
if not citId then return end
|
||||
|
||||
-- Use GetFullAppearanceData to cache the complete appearance
|
||||
Clothing.GetFullAppearanceData(src)
|
||||
end)
|
||||
|
||||
--- Event handler for when a player disconnects from the server
|
||||
--- Removes the player's appearance data from the cache
|
||||
AddEventHandler('community_bridge:Server:OnPlayerUnload', function(src)
|
||||
src = src and tonumber(src)
|
||||
assert(src, "src is nil")
|
||||
local strSrc = tostring(src)
|
||||
Clothing.Players[strSrc] = nil
|
||||
end)
|
||||
|
||||
|
||||
|
||||
--- Event handler for when the resource starts
|
||||
--- Caches appearance data for all currently connected players
|
||||
AddEventHandler('onResourceStart', function(resource)
|
||||
if resource ~= GetCurrentResourceName() then return end
|
||||
for _, playerId in ipairs(GetPlayers()) do
|
||||
local src = tonumber(playerId)
|
||||
local strSrc = tostring(src)
|
||||
if not Clothing.Players[strSrc] then
|
||||
Clothing.Players[strSrc] = Clothing.GetAppearance(src)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Callback handler for retrieving a player's appearance data
|
||||
Callback.Register('community_bridge:cb:GetAppearance', function(source)
|
||||
local src = source
|
||||
return Clothing.GetAppearance(src)
|
||||
end)
|
||||
|
||||
|
||||
RegisterCommand('clothing:debug', function(source, args, rawCommand)
|
||||
local src = source
|
||||
Clothing.SetAppearance(src, {
|
||||
components ={
|
||||
{component_id = 1, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 2, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 3, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 4, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 5, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 6, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 7, drawable = math.random(0, 50), texture = 0},
|
||||
{component_id = 8, drawable = math.random(0, 50), texture = 0},
|
||||
},
|
||||
props = {
|
||||
{prop_id = 3, drawable = 0, texture = 0},
|
||||
{prop_id = 1, drawable = 0, texture = 0},
|
||||
{prop_id = 2, drawable = 0, texture = 0},
|
||||
}
|
||||
}, false, true)
|
||||
end, false)
|
||||
|
||||
|
||||
RegisterCommand('clothing:revert', function(source, args, rawCommand)
|
||||
local src = source
|
||||
Clothing.Revert(src)
|
||||
end, false)
|
||||
|
||||
|
||||
RegisterCommand('clothing:current', function(source, args, rawCommand)
|
||||
local src = source
|
||||
local currentClothing = Clothing.GetAppearance(src)
|
||||
if not currentClothing then return end
|
||||
print(json.encode(currentClothing, { indent = true }))
|
||||
end, false)
|
||||
|
||||
RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
|
||||
local src = source
|
||||
Clothing.OpenMenu(src)
|
||||
end, false)
|
||||
|
||||
|
||||
RegisterCommand('clothing:crowley', function(source, args, rawCommand)
|
||||
local src = source
|
||||
end, false)
|
||||
@@ -0,0 +1,201 @@
|
||||
|
||||
if GetResourceState('qb-clothing') == 'missing' then return end
|
||||
|
||||
Clothing = Clothing or {}
|
||||
|
||||
Components = {}
|
||||
Components.Map = {
|
||||
[1] = "mask",
|
||||
[2] = "hair",
|
||||
[3] = "arms",
|
||||
[4] = "pants",
|
||||
[5] = "bag",
|
||||
[6] = "shoes",
|
||||
[7] = "accessory",
|
||||
[8] = "t-shirt",
|
||||
[9] = "vest",
|
||||
[10] = "decals",
|
||||
[11] = "torso2"
|
||||
}
|
||||
Components.InverseMap = {
|
||||
mask = 1,
|
||||
hair = 2,
|
||||
arms = 3,
|
||||
pants = 4,
|
||||
bag = 5,
|
||||
shoes = 6,
|
||||
accessory = 7,
|
||||
['t-shirt'] = 8, --<--I HATE THAT
|
||||
vest = 9,
|
||||
decals = 10,
|
||||
torso2 = 11
|
||||
}
|
||||
|
||||
Props = {}
|
||||
Props.Map = {
|
||||
[0] = "hat",
|
||||
[1] = "glass",
|
||||
[2] = "ear",
|
||||
[6] = "watch",
|
||||
[7] = "bracelet"
|
||||
}
|
||||
Props.InverseMap = {
|
||||
hat = 0,
|
||||
glass = 1,
|
||||
ear = 2,
|
||||
watch = 6,
|
||||
bracelet = 7
|
||||
}
|
||||
|
||||
function Components.ConvertFromDefault(defaultComponents)
|
||||
local returnComponents = {}
|
||||
for index, componentData in pairs(defaultComponents or {}) do
|
||||
local componentId = Components.Map[componentData.component_id]
|
||||
if componentId then
|
||||
returnComponents[componentId] = {
|
||||
item = componentData.drawable,
|
||||
texture = componentData.texture
|
||||
}
|
||||
end
|
||||
end
|
||||
return returnComponents
|
||||
end
|
||||
|
||||
function Components.ConvertToDefault(qbComponents)
|
||||
local returnComponents = {}
|
||||
for componentIndex, componentData in pairs(qbComponents or {}) do
|
||||
local componentId = Components.InverseMap[componentIndex]
|
||||
if componentId then
|
||||
returnComponents[componentId] = {
|
||||
component_id = componentId,
|
||||
drawable = componentData.item,
|
||||
texture = componentData.texture
|
||||
}
|
||||
end
|
||||
end
|
||||
return returnComponents
|
||||
end
|
||||
|
||||
function Props.ConvertFromDefault(defaultProps)
|
||||
local returnProps = {}
|
||||
for index, propData in pairs(defaultProps or {}) do
|
||||
local propId = Props.Map[propData.prop_id]
|
||||
if propId then
|
||||
returnProps[propId] = {
|
||||
item = propData.drawable,
|
||||
texture = propData.texture
|
||||
}
|
||||
end
|
||||
end
|
||||
return returnProps
|
||||
end
|
||||
|
||||
function Props.ConvertToDefault(qbProps)
|
||||
local returnProps = {}
|
||||
for propIndex, propData in pairs(qbProps or {}) do
|
||||
local propId = Props.InverseMap[propIndex]
|
||||
if propId then
|
||||
table.insert(returnProps, {
|
||||
prop_id = propId,
|
||||
drawable = propData.item,
|
||||
texture = propData.texture
|
||||
})
|
||||
end
|
||||
end
|
||||
table.sort(returnProps, function(a, b)
|
||||
return a.prop_id < b.prop_id
|
||||
end)
|
||||
return returnProps
|
||||
end
|
||||
|
||||
function Clothing.ConvertFromDefault(defaultClothing)
|
||||
local components = Components.ConvertFromDefault(defaultClothing.components)
|
||||
local props = Props.ConvertFromDefault(defaultClothing.props)
|
||||
|
||||
for propsIndex, propData in pairs(props) do
|
||||
components[propsIndex] = propData
|
||||
end
|
||||
|
||||
return components --skin
|
||||
end
|
||||
|
||||
function Clothing.ConvertToDefault(qbClothing)
|
||||
local components = Components.ConvertToDefault(qbClothing)
|
||||
local props = Props.ConvertToDefault(qbClothing)
|
||||
return { components = components, props = props }
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Clothing = {}
|
||||
|
||||
-- StoredOldClothing = {}
|
||||
|
||||
-- Clothing.SetAppearance = function(clothingData)
|
||||
-- if GetEntityModel(cache.ped) == `mp_m_freemode_01` then
|
||||
-- clothingData = clothingData.male
|
||||
-- else
|
||||
-- clothingData = clothingData.female
|
||||
-- end
|
||||
-- local repackedTable = {}
|
||||
-- local componentMap = {
|
||||
-- [1] = "mask",
|
||||
-- [3] = "arms",
|
||||
-- [4] = "pants",
|
||||
-- [5] = "bag",
|
||||
-- [6] = "shoes",
|
||||
-- [7] = "accessory",
|
||||
-- [8] = "t-shirt",
|
||||
-- [9] = "vest",
|
||||
-- [10] = "decals",
|
||||
-- [11] = "torso2"
|
||||
-- }
|
||||
|
||||
-- local propMap = {
|
||||
-- [0] = "hat",
|
||||
-- [1] = "glass",
|
||||
-- [2] = "ear",
|
||||
-- [6] = "watch",
|
||||
-- [7] = "bracelet"
|
||||
-- }
|
||||
|
||||
-- local specialMap = {
|
||||
-- eye_color_id = "eye_color",
|
||||
-- moles_id = "moles",
|
||||
-- ageing_id = "ageing",
|
||||
-- hair_id = "hair",
|
||||
-- face_id = "face"
|
||||
-- }
|
||||
|
||||
-- for _, data in pairs(clothingData) do
|
||||
-- if componentMap[data.component_id] then
|
||||
-- repackedTable[componentMap[data.component_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif propMap[data.prop_id] then
|
||||
-- repackedTable[propMap[data.prop_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.eye_color_id] then
|
||||
-- repackedTable[specialMap[data.eye_color_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.moles_id] then
|
||||
-- repackedTable[specialMap[data.moles_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.ageing_id] then
|
||||
-- repackedTable[specialMap[data.ageing_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.hair_id] then
|
||||
-- repackedTable[specialMap[data.hair_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- elseif specialMap[data.face_id] then
|
||||
-- repackedTable[specialMap[data.face_id]] = {drawable = data.drawable, texture = data.texture}
|
||||
-- end
|
||||
-- end
|
||||
-- TriggerEvent('qb-clothing:client:loadOutfit', repackedTable)
|
||||
-- end
|
||||
Vendored
+45
@@ -10,4 +10,49 @@
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
<script>
|
||||
// dont judge me
|
||||
|
||||
function isTableJSON(jsonString) {
|
||||
try {
|
||||
const parsed = JSON.parse(jsonString);
|
||||
if (!Array.isArray(parsed)) {
|
||||
return false;
|
||||
}
|
||||
if (parsed.length > 0) {
|
||||
const firstKeys = Object.keys(parsed[0]);
|
||||
for (let i = 0; i < parsed.length; i++) {
|
||||
if (typeof parsed[i] !== 'object' || parsed[i] === null || Array.isArray(parsed[i])) {
|
||||
return false;
|
||||
}
|
||||
if (Object.keys(parsed[i]).length !== firstKeys.length || !Object.keys(parsed[i]).every(key => firstKeys.includes(key))) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const copyToClipboard = (str) => {
|
||||
const el = document.createElement("textarea");
|
||||
el.value = str;
|
||||
document.body.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(el);
|
||||
};
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event?.data?.type === "copytoclipboard") {
|
||||
var str = event.data.text;
|
||||
// if (isTableJSON(str)) {
|
||||
// str = JSON.stringify(JSON.parse(str), null, 2);
|
||||
// }
|
||||
copyToClipboard(str);
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
@@ -9,4 +9,23 @@
|
||||
<div id="root"></div>
|
||||
<script type="module" src="./src/main.jsx"></script>
|
||||
</body>
|
||||
<script>
|
||||
// dont judge me
|
||||
const copyToClipboard = (str) => {
|
||||
const el = document.createElement("textarea");
|
||||
el.value = str;
|
||||
document.body.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(el);
|
||||
};
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event?.data?.type === "copytoclipboard") {
|
||||
var str = event.data.text;
|
||||
copyToClipboard(str);
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
Reference in new issue
Block a user