Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update qbox multicharacter #446

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 109 additions & 35 deletions client/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,84 @@ if config.characters.useExternalCharacters then return end
local previewCam = nil
local randomLocation = config.characters.locations[math.random(1, #config.characters.locations)]

local randomPedModels = {
`a_m_o_soucent_02`,
`mp_g_m_pros_01`,
`a_m_m_prolhost_01`,
`a_f_m_prolhost_01`,
`a_f_y_smartcaspat_01`,
`a_f_y_runner_01`,
`a_f_y_vinewood_04`,
`a_f_o_soucent_02`,
`a_m_y_cyclist_01`,
`a_m_m_hillbilly_02`,
local randomPeds = {
{
model = `mp_m_freemode_01`,
headOverlays = {
beard = {color = 0, style = 0, secondColor = 0, opacity = 1},
eyebrows = {color = 0, style = 0, secondColor = 0, opacity = 1},
chestHair = {color = 0, style = 0, secondColor = 0, opacity = 1},
},
components = {
{texture = 0, drawable = 0, component_id = 0},
{texture = 0, drawable = 0, component_id = 1},
{texture = 0, drawable = 0, component_id = 2},
{texture = 0, drawable = 0, component_id = 5},
{texture = 0, drawable = 0, component_id = 7},
{texture = 0, drawable = 0, component_id = 9},
{texture = 0, drawable = 0, component_id = 10},
{texture = 0, drawable = 15, component_id = 11},
{texture = 0, drawable = 15, component_id = 8},
{texture = 0, drawable = 15, component_id = 3},
{texture = 0, drawable = 34, component_id = 6},
{texture = 0, drawable = 61, component_id = 4},
},
props = {
{prop_id = 0, drawable = -1, texture = -1},
{prop_id = 1, drawable = -1, texture = -1},
{prop_id = 2, drawable = -1, texture = -1},
{prop_id = 6, drawable = -1, texture = -1},
{prop_id = 7, drawable = -1, texture = -1},
}
},
{
model = `mp_f_freemode_01`,
headBlend = {
shapeMix = 0.3,
shapeFirst = 31,
},
hair = {
style = 15,
},
headOverlays = {
beard = {color = 0, style = 0, secondColor = 0, opacity = 1},
eyebrows = {color = 0, style = 0, secondColor = 0, opacity = 1},
chestHair = {color = 0, style = 0, secondColor = 0, opacity = 1},
},
components = {
{drawable = 0, component_id = 0, texture = 0},
{drawable = 0, component_id = 1, texture = 0},
{drawable = 0, component_id = 2, texture = 0},
{drawable = 0, component_id = 5, texture = 0},
{drawable = 0, component_id = 7, texture = 0},
{drawable = 0, component_id = 9, texture = 0},
{drawable = 0, component_id = 10, texture = 0},
{drawable = 15, component_id = 3, texture = 0},
{drawable = 15, component_id = 11, texture = 3},
{drawable = 14, component_id = 8, texture = 0},
{drawable = 15, component_id = 4, texture = 3},
{drawable = 35, component_id = 6, texture = 0},
},
props = {
{prop_id = 0, drawable = -1, texture = -1},
{prop_id = 1, drawable = -1, texture = -1},
{prop_id = 2, drawable = -1, texture = -1},
{prop_id = 6, drawable = -1, texture = -1},
{prop_id = 7, drawable = -1, texture = -1},
}
}
}

local nationalities = {}

if config.characters.limitNationalities then
CreateThread(function()
for i = 1, #config.characters.nationalities do
nationalities[#nationalities + 1] = {value = config.characters.nationalities[i]}
end
end)
end

local function setupPreviewCam()
DoScreenFadeIn(1000)
SetTimecycleModifier('hud_def_blur')
Expand Down Expand Up @@ -49,24 +114,26 @@ local function destroyPreviewCam()
FreezeEntityPosition(cache.ped, false)
end

local function randomPed()
local ped = randomPeds[math.random(1, #randomPeds)]
lib.requestModel(ped.model, config.loadingModelsTimeout)
SetPlayerModel(cache.playerId, ped.model)
pcall(function() exports['illenium-appearance']:setPedAppearance(PlayerPedId(), ped) end)
SetModelAsNoLongerNeeded(ped.model)
end

---@param citizenId? string
local function previewPed(citizenId)
if not citizenId then
local model = randomPedModels[math.random(1, #randomPedModels)]
lib.requestModel(model, config.loadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
return
end
if not citizenId then randomPed() return end

local clothing, model = lib.callback.await('qbx_core:server:getPreviewPedData', false, citizenId)
if model and clothing then
lib.requestModel(model, config.loadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
pcall(function() exports['illenium-appearance']:setPedAppearance(PlayerPedId(), json.decode(clothing)) end)
SetModelAsNoLongerNeeded(model)
else
model = randomPedModels[math.random(1, #randomPedModels)]
lib.requestModel(model, config.loadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
randomPed()
end
end

Expand All @@ -80,6 +147,22 @@ end

---@return string[]?
local function characterDialog()
local nationalityOption = config.characters.limitNationalities and {
type = 'select',
required = true,
icon = 'user-shield',
label = locale('info.nationality'),
default = 'American',
searchable = true,
options = nationalities
} or {
type = 'input',
required = true,
icon = 'user-shield',
label = locale('info.nationality'),
placeholder = 'Duck'
}

return lib.inputDialog(locale('info.character_registration_title'), {
{
type = 'input',
Expand All @@ -95,13 +178,7 @@ local function characterDialog()
label = locale('info.last_name'),
placeholder = 'Jordan'
},
{
type = 'input',
required = true,
icon = 'user-shield',
label = locale('info.nationality'),
placeholder = 'Duck'
},
nationalityOption,
{
type = 'select',
required = true,
Expand All @@ -122,11 +199,11 @@ local function characterDialog()
required = true,
icon = 'calendar-days',
label = locale('info.birth_date'),
format = 'YYYY-MM-DD',
format = config.characters.dateFormat,
returnString = true,
min = '1900-01-01', -- Has to be in the same in the same format as the format argument
max = '2006-12-31', -- Has to be in the same in the same format as the format argument
default = '2006-12-31'
min = config.characters.dateMin,
max = config.characters.dateMax,
default = config.characters.dateMax
}
})
end
Expand Down Expand Up @@ -396,15 +473,12 @@ RegisterNetEvent('qbx_core:client:playerLoggedOut', function()
end)

CreateThread(function()
local model = randomPedModels[math.random(1, #randomPedModels)]
while true do
Wait(0)
if NetworkIsSessionStarted() then
pcall(function() exports.spawnmanager:setAutoSpawn(false) end)
Wait(250)
lib.requestModel(model, config.loadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
SetModelAsNoLongerNeeded(model)
randomPed()
chooseCharacter()
break
end
Expand Down
Loading