#qbx_management not hiring

1 messages · Page 1 of 1 (latest)

lyric grove
#

Everything works in the management menu except hiring someone.
They get the notification they're hired, but their job doesn't change.
im using qbx_management v1.2.0
No errors thrown client or server side.

midnight yarrow
lyric grove
#

i did not edit the code.

#
-- Callback to hire online player as employee of a given group
---@param employee integer Server ID of target employee to be hired
---@param groupType GroupType
lib.callback.register('qbx_management:server:hireEmployee', function(source, employee, groupType)
    local player = exports.qbx_core:GetPlayer(source)
    local target = exports.qbx_core:GetPlayer(employee)

    if not player.PlayerData[groupType].isboss then return end

    if not target then
        exports.qbx_core:Notify(source, locale('error.not_around'), 'error')
        return
    end

    local groupName = player.PlayerData[groupType].name
    local logArea = groupType == 'gang' and 'Gang' or 'Boss'

    if groupType == 'job' then
        exports.qbx_core:AddPlayerToJob(target.PlayerData.citizenid, groupName, 0)
        exports.qbx_core:SetPlayerPrimaryJob(target.PlayerData.citizenid, groupName)
    else
        exports.qbx_core:AddPlayerToGang(target.PlayerData.citizenid, groupName, 0)
        exports.qbx_core:SetPlayerPrimaryGang(target.PlayerData.citizenid, groupName)
    end

    local playerFullName = player.PlayerData.charinfo.firstname..' '..player.PlayerData.charinfo.lastname
    local targetFullName = target.PlayerData.charinfo.firstname..' '..target.PlayerData.charinfo.lastname
    local organizationLabel = player.PlayerData[groupType].label
    exports.qbx_core:Notify(source, locale('success.hired_into', targetFullName, organizationLabel), 'success')
    exports.qbx_core:Notify(target.PlayerData.source, locale('success.hired_to')..organizationLabel, 'success')
    logger.log({source = 'qbx_management', event = 'hireEmployee', message = string.format('%s | %s hired %s into %s at grade %s', logArea, playerFullName, targetFullName, organizationLabel, 0), webhook = config.discordWebhook})
end)```
midnight yarrow
#

does the logger log that someone got hired?

lyric grove
#

i didnt set up the logger since we're in dev stage atm 😅

midnight yarrow
#

You should set it up.

lyric grove
midnight yarrow
#

does the groupName exists?

lyric grove
#

it does

#

thats in the config, right?

midnight yarrow
#

no thats the job/gang it would assign

lyric grove
#

thats just ambulance, so yes

valid crest
#

What core version are you on and what are your convar values set to for qbx?

lyric grove
#
set qbx:bucketlockdownmode "inactive" # Sets the lockdown mode as relaxed read here: https://docs.fivem.net/natives/?_0xA0F2201F
set qbx:discordlink "discord.tmrw-rp.be" # Sets the servers discord link
set qbx:max_jobs_per_player 1 # Sets the number of jobs per player
set qbx:max_gangs_per_player 1 # Sets the number of gangs per player
set qbx:setjob_replaces "true" # When true, the SetJob function deletes the previous primary job of the player before setting the new one
set qbx:setgang_replaces "true" # When true, the SetGang function deletes the previous primary gang of the player before setting the new one```
valid crest
#

The error is probably getting buried unfortunately. Need to update qbx_management not to do so

lyric grove
valid crest
lyric grove
#

Hero ❤️

valid crest
lyric grove
valid crest
lyric grove
#

i only added a function to create a citizenid based of the birthdate in the core.

midnight yarrow
#

what

#

why would you do that?

valid crest
#

Could you show the code in qbx_management server/main line 107 and the qbx_core AddPlayerToJob export code you have?

lyric grove
#
        local success, errorResult = exports.qbx_core:AddPlayerToJob(target.PlayerData.citizenid, groupName, 0) -- line 106
        assert(success, errorResult.message)```
lyric grove
lyric grove
# valid crest Could you show the code in qbx_management server/main line 107 and the qbx_core ...
---Adds a player to the job or overwrites their grade for a job already held
---@param citizenid string
---@param jobName string
---@param grade integer
---@return boolean success
---@return ErrorResult? errorResult
function AddPlayerToJob(citizenid, jobName, grade)
    -- unemployed job is the default, so players cannot be added to it
    if jobName == 'unemployed' then
        return false, {
            code = 'unemployed',
            message = 'players cannot be added to the unemployed job'
        }
    end

    local job = GetJob(jobName)
    if not job then
        return false, {
            code = 'job_not_found',
            message = jobName .. ' does not exist in core memory'
        }
    end

    if not job.grades[grade] then
        return false, {
            code = 'job_missing_grade',
            message = string.format('job %s does not have grade %s', jobName, grade),
        }
    end

    local player = GetPlayerByCitizenId(citizenid) or GetOfflinePlayer(citizenid)
    if not player then
        return false, {
            code = 'player_not_found',
            message = string.format('player not found with citizenid %s', citizenid)
        }
    end

    if player.PlayerData.jobs[jobName] == grade then
        return true
    end

    if qbx.table.size(player.PlayerData.jobs) >= maxJobsPerPlayer and not player.PlayerData.jobs[jobName] then
        return false, {
            code = 'max_jobs',
            message = 'player already has maximum amount of jobs allowed'
        }
    end

    storage.addPlayerToJob(citizenid, jobName, grade)

    if not player.Offline then
        player.PlayerData.jobs[jobName] = grade
        player.Functions.SetPlayerData('jobs', player.PlayerData.jobs)
        TriggerEvent('qbx_core:server:onGroupUpdate', player.PlayerData.source, jobName, grade)
        TriggerClientEvent('qbx_core:client:onGroupUpdate', player.PlayerData.source, jobName, grade)
    end

    if player.PlayerData.job.name == jobName then
        SetPlayerPrimaryJob(citizenid, jobName)
    end

    return true
end

exports('AddPlayerToJob', AddPlayerToJob)```
valid crest
#

Every return false also returns a table, so I don't understand how you can have a nil return error in qbx_management

#

Maybe try adding prints for what success and errorResult are? You could also add prints in core to see which return is getting invoked.