qbcore-framework / qb-core

FiveM RP Framework Core :muscle:
GNU General Public License v3.0
589 stars 960 forks source link

[BUG] #727

Closed bandgeekndb closed 2 years ago

bandgeekndb commented 2 years ago

Describe the bug The paycheck function reads the player's job payment amount from the PlayerData object. But, if you adjust the payments in jobs.lua after setting a player's job, the player will not see that updated payment amount until their job is reassigned using /setjob.

To Reproduce Steps to reproduce the behavior:

  1. Set jobs and salaries in jobs.lua
  2. Assign a player to a job
  3. Change the job salary in jobs.lua

Expected behavior The player continues to see their old salary until someone resets their job.

Desired behavior Instead, the PaycheckInterval() function should get the payment from the jobs.lua based on the player's assigned job.

Questions (please complete the following information):

Additional context Add any other context about the problem here.

GhzGarage commented 2 years ago

Try this

function PaycheckInterval()
    if next(QBCore.Players) then
        for _, Player in pairs(QBCore.Players) do
            if Player then
                local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][Player.PlayerData.job.grade].payment
                if not payment then payment = Player.PlayerData.job.payment end
                if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
                    if QBCore.Config.Money.PayCheckSociety then
                        local account = exports['qb-management']:GetAccount(Player.PlayerData.job.name)
                        if account ~= 0 then -- Checks if player is employed by a society
                            if account < payment then -- Checks if company has enough money to pay society
                                TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
                            else
                                Player.Functions.AddMoney('bank', payment)
                                exports['qb-management']:RemoveMoney(Player.PlayerData.job.name, payment)
                                TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
                            end
                        else
                            Player.Functions.AddMoney('bank', payment)
                            TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
                        end
                    else
                        Player.Functions.AddMoney('bank', payment)
                        TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
                    end
                end
            end
        end
    end
    SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
end
bandgeekndb commented 2 years ago

Awesome, appreciate the code suggestion! I forgot to add that I was happy to PR a change, just wanted to verify that it wasn't intended behavior for some reason, but looks like you've got it covered. I'll try this out, verify there are no issues, and report back. Thank you!

GhzGarage commented 2 years ago

Btw this might throw an error

[Player.PlayerData.job.grade].payment

if it does then try

[tostring(Player.PlayerData.job.grade.level)].payment

bandgeekndb commented 2 years ago

The second snippet worked, thank you. Do you want a PR for this change?

GhzGarage commented 2 years ago

Yeah thanks