Change default phone number

Welcome to Change default phone number

If you want to change both the default number prefix and assign a number of digits to your phone number, you can make the change from qb-core/server/player.lua and look for the CreatePhoneNumber() function. Be careful and modify these values with safety and a little bit of knowledge in programming and lua.

As you will see, as in the example, line 5 of your phone number will be modified, explaining better, the first math.random(100,999) gives you the example of the prefix that your phone number will have, and the second math.random(1000000,9999999) is the amount of digits that your number will have, so it will have 7 digits of amount.

You can set these example values, we will put a modified code and the original code as an example for use.

function QBCore.Functions.CreatePhoneNumber()
    local UniqueFound = false
    local PhoneNumber = nil
    while not UniqueFound do
        PhoneNumber = math.random(555,560) .. math.random(100000,999999)
        --math.random(555,560) = Placing only a 3-digit prefix with 5 different possible digits
        --math.random(100000,999999) = Placed only a number of 6 possible digits
        local query = '%' .. PhoneNumber .. '%'
        local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
        if result == 0 then
            UniqueFound = true
        end
    end
    return PhoneNumber
end

Last updated