Blips
CLIENT SIDE ONLY
A comprehensive standalone blip manager designed to streamline the creation, management, and manipulation of blips in your projects. It provides a robust set of functions for creating, updating, toggling, and removing blips.
Functions
create_blip
Creates a new blip.
Function
local function create_blip(blip_data)
local blip = AddBlipForCoord(blip_data.coords.x, blip_data.coords.y, blip_data.coords.z)
SetBlipSprite(blip, blip_data.sprite)
SetBlipColour(blip, blip_data.color)
SetBlipScale(blip, blip_data.scale)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(blip_data.label)
EndTextCommandSetBlipName(blip)
save_blip(blip, {
coords = blip_data.coords,
sprite = blip_data.sprite,
color = blip_data.color,
scale = blip_data.scale,
label = blip_data.label,
category = blip_data.category
})
end
exports('create_blip', create_blip)
utils.blips.create_blip = create_blip
Example
--- Define blip data
local blip = {
coords = vector3(100.0, 200.0, 30.0), -- Coordinates
sprite = 1, -- Sprite ID
color = 2, -- Color ID
scale = 0.8, -- Scale
label = "Shop", -- Label
category = "shops" -- Category
}
--- Utils object
utils.blips.create_blip(blip)
--- Direct export
exports.boii_utils:create_blip(blip)
create_blips
Create multiple blips from a single table.
Function
local function create_blips(blip_list)
for _, blip_data in ipairs(blip_list) do
create_blip(blip_data)
end
end
exports('create_blips', create_blips)
utils.blips.create_blips = create_blips
Example
--- Define blips
local blips = {
{
coords = vector3(100.0, 200.0, 30.0),
sprite = 1,
color = 2,
scale = 0.8,
label = "Shop 1",
category = "shops"
},
{
coords = vector3(150.0, 250.0, 35.0),
sprite = 2,
color = 3,
scale = 0.8,
label = "Shop 2",
category = "shops"
}
}
--- Utils object
utils.blips.create_blips(blips)
--- Direct export
exports.boii_utils:create_blips(blips)
remove_blip
Remove a single blip.
Function
local function remove_blip(blip)
if is_valid_blip(blip) then
RemoveBlip(blip)
delete_blip(blip)
end
end
exports('remove_blip', remove_blip)
utils.blips.remove_blip = remove_blip
Example
--- Define blip ID
local blip = 'your blip id'
--- Utils object
utils.blips.remove_blip(blip)
--- Direct export
exports.boii_utils:remove_blip(blip)
remove_all_blips
Remove all blips.
Function
local function remove_all_blips()
for blip in pairs(created_blips) do
RemoveBlip(blip)
end
created_blips = {}
end
exports('remove_all_blips', remove_all_blips)
utils.blips.remove_all_blips = remove_all_blips
Example
--- Utils object
utils.blips.remove_all_blips()
--- Direct export
exports.boii_utils:remove_all_blips()
remove_blips_by_category
Remove blips by specified category.
Function
local function remove_blips_by_category(category)
for blip, data in pairs(created_blips) do
if data.category == category then
RemoveBlip(blip)
delete_blip(blip)
end
end
end
exports('remove_blips_by_category', remove_blips_by_category)
utils.blips.remove_blips_by_category = remove_blips_by_category
Example
--- Specify the category to remove
local category = 'shops'
--- Utils object
utils.blips.remove_blips_by_category(category)
--- Direct export
exports.boii_utils:remove_blips_by_category(category)
toggle_blips_by_category
Toggle blip visibility by category.
Function
local function toggle_blips_by_category(category, state)
local display = state and 2 or 0
for blip, data in pairs(created_blips) do
if data.category == category then
SetBlipDisplay(blip, display)
end
end
category_state[category] = state
end
exports('toggle_blips_by_category', toggle_blips_by_category)
utils.blips.toggle_blips_by_category = toggle_blips_by_category
Example
--- Define category
local category = 'shops'
--- Set to true to show, false to hide
local state = true
--- Utils object
utils.blips.toggle_blips_by_category(category, state)
--- Direct export
exports.boii_utils:toggle_blips_by_category(category, state)
update_blip_property
Update properties of a blip.
Function
local function update_blip_property(blip, property, value)
if not is_valid_blip(blip) then return end
if property == 'label' then
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(value)
EndTextCommandSetBlipName(blip)
elseif property == 'sprite' then
SetBlipSprite(blip, value)
elseif property == 'color' then
SetBlipColour(blip, value)
elseif property == 'scale' then
SetBlipScale(blip, value)
end
created_blips[blip][property] = value
end
exports('update_blip_property', update_blip_property)
utils.blips.update_blip_property = update_blip_property
Example
--- Define blip ID
local blip = 'your blip id'
--- Specify propert to update; (label, sprite, color, scale)
local property = 'label'
--- Define value for the property
local value = 'New Label'
--- Utils object
utils.blips.update_blip_property(blip, property, value)
--- Direct export
exports.boii_utils:update_blip_property(blip, property, value)
get_all_blips
Gets all blips in created_blips table.
Function
local function get_all_blips()
return created_blips
end
exports('get_all_blips', get_all_blips)
utils.blips.get_all_blips = get_all_blips
Example
--- Utils object
local blips = utils.blips.get_all_blips()
print("Blips:", json.encode(blips))
--- Direct export
local blips = exports.boii_utils:get_all_blips()
print("Blips:", json.encode(blips))
get_blips_by_category
Get blips by specified category.
Function
local function get_blips_by_category(category)
local result = {}
for blip, data in pairs(created_blips) do
if data.category == category then
table.insert(result, blip)
end
end
return result
end
exports('get_blips_by_category', get_blips_by_category)
utils.blips.get_blips_by_category = get_blips_by_category
Example
--- Specify category to get
local category = 'shops'
--- Utils object
local blips = utils.blips.get_blips_by_category(category)
print("Blips in category 'shops':", json.encode(blips))
--- Direct export
local blips = exports.boii_utils:get_blips_by_category(category)
print("Blips in category 'shops':", json.encode(blips))
Last updated