A friend asked how to add commas to the cash hud so it’s easier to read how much cash you have. So I wrote some code that does the trick.

In the QB-hud client.lua at the bottom add the following code from https://stackoverflow.com/a/10992898:

function format_int(number)

    local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
  
    -- reverse the int-string and append a comma to all blocks of 3 digits
    int = int:reverse():gsub("(%d%d%d)", "%1,")
  
    -- reverse the int-string back remove an optional comma and put the 
    -- optional minus and fractional part back
    return minus .. int:reverse():gsub("^,", "") .. fraction
end

Now find similar code and replace with:

RegisterNetEvent('hud:client:ShowAccounts', function(type, amount)
    if type == 'cash' then
        SendNUIMessage({
            action = 'show',
            type="cash",
            cash = format_int(amount)
        })
    else
        SendNUIMessage({
            action = 'show',
            type="bank",
            bank = format_int(amount)
        })
    end
end)
RegisterNetEvent('hud:client:OnMoneyChange', function(type, amount, isMinus)
    cashAmount = format_int(PlayerData.money['cash'])
    bankAmount = format_int(PlayerData.money['bank'])
    SendNUIMessage({
        action = 'updatemoney',
        cash = cashAmount,
        bank = bankAmount,
        amount = amount,
        minus = isMinus,
        type = type
    })
end)

I hope this helps someone like it helped out my friend. :v:



Looking for a FiveM Server host? Click here