Groups

CLIENT & SERVER SIDE

A lightweight standalone groups system. It allows you to check group memberships, retrieve group details, verify leadership, and dynamically update group data via server-side events.

Client Functions

in_group

Checks if the players is in the specified group.

Function

local function in_group(group_name)
    for _, group in pairs(client_groups) do
        for _, id in ipairs(group.members) do
            if id == GetPlayerServerId(PlayerId()) then
                return true
            end
        end
    end
    return false
end

exports('in_group', in_group)
utils.groups.in_group = in_group

Example

--- Define group name
local group_name = 'racing-1'

--- Utils object
local is_in_group = utils.groups.in_group(group_name)

if is_in_group then
    print('Player is in the group.')
else
    print('Player is not in the group.')
end

--- Direct export
exports.boii_utils:in_group(group_name)

get_player_groups

Gets all groups the player is a member of.

Function

local function get_player_groups()
    local player_groups = {}
    for group_name, group_data in pairs(client_groups) do
        for _, id in ipairs(group_data.members) do
            if id == GetPlayerServerId(PlayerId()) then
                player_groups[#player_groups + 1] = group_name
            end
        end
    end
    return player_groups
end

exports('get_player_groups', get_player_groups)
utils.groups.get_player_groups = get_player_groups

Example

--- Utils object
local player_groups = utils.groups.get_player_groups()

print('Player Groups:', json.encode(player_groups))

--- Direct export
local player_groups = exports.boii_utils:get_player_groups()

group_exists

Check if a group exists.

Function

local function group_exists(group_name)
    return client_groups[group_name] ~= nil
end

exports('group_exists', group_exists)
utils.groups.group_exists = group_exists

Example

--- Specify group name
local group_name = 'racing-1'

--- Utils object
local group_exists = utils.groups.group_exists(group_name)

if group_exists then
    print('Group exists!')
else
    print('Group does not exist.')
end

--- Direct export
exports.boii_utils:group_exists(group_name)

is_leader

Checks if the player is the leader of a specified group.

Function

local function is_leader(group_name)
    local group = client_groups[group_name]
    if group and group.leader == GetPlayerServerId(PlayerId()) then
        return true
    end
    return false
end

exports('is_leader', is_leader)
utils.groups.is_leader = is_leader

Example

--- Specify group name
local group_name = 'racing-1'

--- Utils object
local is_leader = utils.groups.is_leader(group_name)

if is_leader then
    print('Is group leader!')
else
    print('Is not group leader.')
end

--- Direct export
exports.boii_utils:is_leader(group_name)

is_member

Checks if player is a member of a specified group.

Function

local function is_member(group_name)
    local group = client_groups[group_name]
    if group then
        for _, id in ipairs(group.members) do
            if id == GetPlayerServerId(PlayerId()) then
                return true
            end
        end
    end
    return false
end

exports('is_member', is_member)
utils.groups.is_member = is_member

Example

--- Specify group name
local group_name = 'racing-1'

--- Utils object
local is_member = utils.groups.is_member(group_name)

if is_member then
    print('Is group leader!')
else
    print('Is not group leader.')
end

--- Direct export
exports.boii_utils:is_member(group_name)

get_group_members

Gets all members of a specified group.

Function

local function get_group_members(group_name)
    local group = client_groups[group_name]
    if group then
        return group.members
    end
    return {}
end

exports('get_group_members', get_group_members)
utils.groups.get_group_members = get_group_members

Example

--- Specify group name
local group_name = 'racing-1'

--- Utils object
local members = utils.groups.get_group_members(group_name)

if members then
    print('Group members:', json.encode(members))
else
    print('No members found.')
end

--- Direct export
exports.boii_utils:get_group_members(group_name)

get_group_members_by_id

Get all members of a group the player with specified ID is in.

Function

local function get_group_members_by_id(player_id)
    for group_name, group_data in pairs(client_groups) do
        for _, id in ipairs(group_data.members) do
            if id == player_id then
                return group_data.members
            end
        end
    end
    return {}
end

exports('get_group_members_by_id', get_group_members_by_id)
utils.groups.get_group_members_by_id = get_group_members_by_id

Example

--- Specify group name
local player_id = 'boii_123456'

--- Utils object
local members = utils.groups.get_group_members_by_id(player_id)

if members then
    print('Group members:', json.encode(members))
else
    print('No members found.')
end

--- Direct export
exports.boii_utils:get_group_members_by_id(group_name)

Server Functions

Last updated