Events

Information regarding boii_base server multicharacter events

get_character_list

Event used to get the users character list to display in character selection.

RegisterServerEvent('boii_base:sv:get_character_list', function()
    local _src = source
    local license = boii.get_identifier(_src, 'license2')
    local unique_id = boii.get_unique_id(license)
    local query = 'SELECT * FROM players WHERE unique_id = ?'
    local params = {unique_id}
    MySQL.Async.fetchAll(query, params, function(result)
        for i, character in ipairs(result) do
            character.identity = json.decode(character.identity)
            character.genetics = json.decode(character.genetics)
            character.barber = json.decode(character.barber)
            character.clothing = json.decode(character.clothing)
            character.tattoos = json.decode(character.tattoos)
        end
        TriggerClientEvent('boii_base:cl:receive_characters', _src, result)
    end)
end)

create_character

Event used to create a new character with the provided data.

RegisterServerEvent('boii_base:sv:create_character', function(character_data)
    local _src = source
    local name = GetPlayerName(_src)
    local license = boii.get_identifier(_src, 'license2')
    local unique_id = boii.get_unique_id(license)
    if not unique_id then boii.print(1, language.multi_character.prints.label, (language.multi_character.prints.no_unique_id):format(name)) return end
    local inventory_data = { items = server_config.new_characters.inventory.starter_items, slots = server_config.new_characters.inventory.slots, weight = server_config.new_characters.inventory.weight }
    local default_spawn = server_config.routing_buckets.buckets[0].default_spawn
    local position = {x = default_spawn.x, y = default_spawn.y, z = default_spawn.z, w = default_spawn.w}
    local count_query = 'SELECT COUNT(*) AS count FROM players WHERE unique_id = ?'
    local count_params = {unique_id}
    local count_result = MySQL.Sync.fetchScalar(count_query, count_params)
    local char_id = count_result and count_result + 1 or 1
    local insert_query = [[
        INSERT INTO players (unique_id, char_id, identity, balances, jobs, paychecks, skills, statuses, booleans, licences, genetics, barber, clothing, tattoos, position, inventory)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    ]]
    local insert_params = {unique_id, char_id, json.encode(character_data.identity), json.encode(server_config.new_characters.balances), json.encode(server_config.new_characters.jobs), json.encode({}), json.encode(server_config.new_characters.skills), json.encode(server_config.new_characters.statuses), json.encode(server_config.new_characters.booleans), json.encode(server_config.new_characters.licences), json.encode(character_data.genetics), json.encode(character_data.barber), json.encode(character_data.clothing), json.encode(character_data.tattoos), json.encode(position), json.encode(inventory_data)}
    MySQL.Async.insert(insert_query, insert_params, function(success)
        if success then
            boii.print(2, language.multi_character.prints.label, (language.multi_character.prints.character_added):format(name))
            TriggerClientEvent('boii_base:cl:open_character_create', _src)
        else
            boii.print(1, language.multi_character.prints.label, (language.multi_character.prints.insert_failed):format(name))
        end
    end)
end)

validate_name

Event used to validate the characters name if the name is unique will return true

RegisterServerEvent('boii_base:sv:validate_name', function(first_name, last_name)
    local _src = source
    local query = 'SELECT 1 FROM players WHERE JSON_EXTRACT(identity, ?) = ? AND JSON_EXTRACT(identity, ?) = ?'
    local params = { '$.first_name', first_name, '$.last_name', last_name }
    MySQL.Async.fetchAll(query, params, function(result)
        if result[1] then
            TriggerClientEvent('boii_base:cl:validation_result', _src, false)
        else
            TriggerClientEvent('boii_base:cl:validation_result', _src, true)
        end
    end)
end)

select_character

Event used to select the chosen characters information and decode ready to create the player object.

RegisterServerEvent('boii_base:sv:select_character', function(character_id)
    local _src = source
    local license = boii.get_identifier(_src, 'license2')
    local unique_id = boii.get_unique_id(license)
    local query = 'SELECT * FROM players WHERE unique_id = ? AND char_id = ?'
    local params = {unique_id, character_id}
    MySQL.Async.fetchAll(query, params, function(result)
        for i, character in ipairs(result) do
            character.identity = json.decode(character.identity)
            character.balances = json.decode(character.balances)
            character.jobs = json.decode(character.jobs)
            character.paychecks = json.decode(character.paychecks)
            character.skills = json.decode(character.skills)
            character.inventory = json.decode(character.inventory)
            character.statuses = json.decode(character.statuses)
            character.booleans = json.decode(character.booleans)
            character.licences = json.decode(character.licences)
            character.genetics = json.decode(character.genetics)
            character.barber = json.decode(character.barber)
            character.clothing = json.decode(character.clothing)
            character.tattoos = json.decode(character.tattoos)
            character.position = json.decode(character.position)
            boii.create_player(_src, unique_id, character_id, character)
        end
    end)
end)

Last updated