Character Creation

CLIENT SIDE ONLY

A light weight standalone selection of helper functions useful for creating anything where character creation can be used, multi-characters, clothing stores, tattoo shops etc.

Functions

get_clothing_and_prop_values

Gets clothing and prop values for UI inputs.

Function

local function get_clothing_and_prop_values(sex)
    if not sex == 'm' or not sex == 'f' then debug_log('err', "Function: get_clothing_and_prop_values failed | Reason: Invalid parameters for sex. - Use 'm' or 'f' only.") return end
    local data = utils.shared.style[sex]
    local values = {
        hair = GetNumberOfPedDrawableVariations(PlayerPedId(), 2) - 1,
        fade = GetNumberOfPedTextureVariations(PlayerPedId(), 2, tonumber(data.barber.hair)) - 1,
        eyebrow = GetPedHeadOverlayNum(2) - 1,
        mask = GetNumberOfPedDrawableVariations(PlayerPedId(), 1) - 1,
        mask_texture = GetNumberOfPedTextureVariations(PlayerPedId(), 1, tonumber(data.clothing.mask_style) - 1)
    }
    return values
end

exports('get_clothing_and_prop_values', get_clothing_and_prop_values)
utils.character_creation.get_clothing_and_prop_values = get_clothing_and_prop_values

Example

--- Utils object
local values = utils.character_creation.get_clothing_and_prop_values()
print('Clothing + Prop Values:', json.encode(values))

--- Direct export
local values = exports.boii_utils:get_clothing_and_prop_values()
print('Clothing + Prop Values:', json.encode(values))

set_ped_appearance

Sets ped appearance values for hair, makeup, genetics, clothing, tattoos, etc. This uses utils built in appearance data.

Function

local function set_ped_appearance(player, data)
    if not player or not data then debug_log('err', 'Function: set_ped_appearance failed | Reason: Missing required parameters (player or data).') return end
    local genetics = data.genetics
    SetPedHeadBlendData(player, genetics.mother, genetics.father, nil, genetics.mother, genetics.father, nil, genetics.resemblence, genetics.skin, nil, true)
    SetPedEyeColor(player, genetics.eye_colour)
    local barber = data.barber
    SetPedComponentVariation(player, 2, barber.hair, 0, 0)
    SetPedHairColor(barber.hair_colour, barber.highlight_colour)
    for _, feature in ipairs(FACIAL_FEATURES) do
        SetPedFaceFeature(player, feature.id, tonumber(genetics[feature.value]) or 0)
    end
    for _, overlay in ipairs(OVERLAYS) do
        apply_overlay(player, overlay, barber)
    end
    for _, item in ipairs(CLOTHING_ITEMS) do
        apply_clothing(player, item, data.clothing)
    end
    ClearPedDecorations(player)
    apply_tattoos(player, data.tattoos, data.sex)
    debug_log('info', 'Ped appearance successfully updated.')
end

exports('set_ped_appearance', set_ped_appearance)
utils.character_creation.set_ped_appearance = set_ped_appearance

Example

--- Utils object
local appearance = utils.shared.style['m']
utils.character_creation.set_ped_appearance(PlayerPedId(), appearance)

--- Direct export
local appearance = utils.shared.style['m']
exports.boii_utils:set_ped_appearance(PlayerPedId(), appearance)

update_ped_data

Updates utils.shared.style with new values to be displayed on player.

Function

local function update_ped_data(sex, category, id, value)
    if not sex or not category or not id or not value then  debug_log('err', 'Function: update_ped_data failed | Reason: Missing one or more required parameters. - sex, category, id, or value.')  return end
    if id == 'resemblance' or id == 'skin' then
        value = value / 100
    end
    if type(utils.shared.style[sex][category][id]) == 'table' then -- 198
        for k, _ in pairs(utils.shared.style[sex][category][id]) do
            utils.shared.style[sex][category][id][k] = value[k]
        end
    else
        utils.shared.style[sex][category][id] = value
    end
    current_sex = sex
    preview_ped = (sex == 'm') and 'mp_m_freemode_01' or 'mp_f_freemode_01'
    set_ped_appearance(PlayerPedId(), utils.shared.style[sex])
end

exports('update_ped_data', update_ped_data)
utils.character_creation.update_ped_data = update_ped_data

Example

--- Specify sex
local sex = 'm'
--- Specify category
local category = 'genetics'
--- Specify id within category
local id = 'resemblance'
--- Define value to update to
local value = 75

--- Utils object
utils.character_creation.update_ped_data(sex, category, id, value)

--- Direct export
exports.boii_utils:update_ped_data(sex, category, id, value)

change_player_ped

Changes the players ped model based on selected sex.

Function

local function change_player_ped(sex)
    if not sex then
        debug_log('err', 'Function: change_player_ped failed. | Reason: Player sex was not provided.')
        return
    end
    current_sex = sex
    preview_ped = (sex == 'm') and 'mp_m_freemode_01' or 'mp_f_freemode_01'
    local model = GetHashKey(preview_ped)
    utils.requests.model(model)
    SetPlayerModel(PlayerId(), model)
    set_ped_appearance(PlayerPedId(), utils.shared.style[sex])
end

exports('change_player_ped', change_player_ped)
utils.character_creation.change_player_ped = change_player_ped

Example

--- Define sex
local sex = 'm' -- 'm' | 'f'

--- Utils object
utils.character_creation.change_player_ped(sex)

--- Direct export
exports.boii_utils:change_player_ped(sex)

rotate_ped

Rotates the current ped facing direction. Options: 'right', 'left', 'flip', 'reset'

Function

local function rotate_ped(direction)
    if not direction then
        return debug_log('err', 'Function: rotate_ped failed. | Reason: Direction parameter is missing.')
    end
    local player_ped = PlayerPedId()
    local current_heading = GetEntityHeading(player_ped)
    original_heading = original_heading or current_heading
    local rotations = {
            right = current_heading + 45,
            left = current_heading - 45,
            flip = current_heading + 180,
            reset = original_heading
        }
    local new_heading = rotations[direction]
    if not new_heading then
        return debug_log('err', "Function: rotate_ped failed. | Reason: Invalid direction parameter - Use 'right', 'left', 'flip', 'reset'.")
    end
    if direction == 'rotate_ped_reset' then
        original_heading = nil
    end
    SetEntityHeading(player_ped, new_heading % 360)
end

exports('rotate_ped', rotate_ped)
utils.character_creation.rotate_ped = rotate_ped

Example

--- Specify direction
local direction = 'left'

--- Utils object
utils.character_creation.rotate_ped(direction)

--- Direct export
exports.boii_utils:rotate_ped(direction)

load_character_model

Loads and applys appearence to character model.

Function

local function load_character_model(data)
    if not data.identity or not data.style.genetics or not data.style.barber or not data.style.clothing or not data.style.tattoos then debug_log('err', 'Function: load_character_model failed. | Reason: One or more required parameters are missing.') return end

    current_sex = data.identity.sex -- THIS WILL NEED TO BE UPDATED TO YOUR OWN METHOD OF GETTING THE PLAYERS SEX
    
    local model = GetHashKey(preview_ped)
    if not utils.requests.model(model) then debug_log('err', "Function: load_character_model failed. | Reason: Failed to request model: " .. preview_ped) return end
    local player_id = PlayerId()
    local player_ped = PlayerPedId()
    SetPlayerModel(player_id, model)
    SetPedComponentVariation(player_ped, 0, 0, 0, 1)
    utils.shared.style[current_sex].genetics = data.style.genetics
    utils.shared.style[current_sex].barber = data.style.barber
    utils.shared.style[current_sex].clothing = data.style.clothing
    utils.shared.style[current_sex].tattoos = data.style.tattoos
    set_ped_appearance(player_ped, utils.shared.style[current_sex])
end

exports('load_character_model', load_character_model)
utils.character_creation.load_character_model = load_character_model

Example

--- Define character data
local data = {
    identity = {
        sex = 'm'
    },
    style = {
        genetics = {
            mother = 21,
            father = 12,
            resemblence = 0.7,
            ...
        },
        barber = {
            ...
        },
        clothing = {
            ...
        },
        tattoos = {
            torso = {
                ...
            }
        }
    }
}

--- Utils object
utils.character_creation.load_character_model(data)

--- Direct export
exports.boii_utils:load_character_model(data)

Last updated