Skip to content

imperfect-fivem/utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FiveM Utilities

Opinionated utilities for FiveM development environment.
Note: This script is under development and not fully functional, star and watch the repo for updates.
Download Link

Makes a resource depend on another server-only resource without breaking client loading.
Example fxmanifest.lua:

  • api_resource
server_only 'yes'
  • logic_resource
server_dependency 'api_resource'

📥 Lua Imports

The require function that is used in this section is defined in ox_lib.
If you don't want to use it then load the target file manually in your resource fxmanifest.lua.

require '@utils.imports.promise'

Example

local function operation(p1, callback, p2)
  --- ...
  callback(true, 123, 'text')
end

local results = promise:new()
operation('whatever', results:resolveCallback(), 'whatever2')
local bool, int, str = results:awaitCallback()
print(bool, int, str) --- true    123    text
require '@utils.imports.exports'

Example

provideExport('resource', 'method', function(...)
  -- ...
end)
require '@utils.imports.convar'

Example

local debugging = GetConvarBoolean('resource:debug', false)

client

require '@utils.imports.network'

Example

RegisterNetEvent('TurnOffVehicleRadio', function(vehicleNetId)
    local attempts, attemptDelay = 2, 5000
    local vehicle = WaitEntityWithNetworkIdToExistLocally(vehicleNetId, attempts, attemptDelay)
    if not vehicle then
        TriggerEvent('WaitedForVehicleToLoadForTooLong', vehicleNetId)
        return
    end
    NetworkWaitUntilHaveControlOfNetworkId(vehicleNetId)
    SetVehRadioStation(vehicle, "OFF")
end)
require '@utils.imports.patterns'

lua 5.4

require '@utils.imports.colors'

Examples

local color = Color('#4287f5', 0.39)
print('opacity:', color.opacity) -- 0.39
print('decimal:', color.decimal) -- 4360181
print('hex:', color.hex) -- #4287f5
local rgb = color.rgb
print('rgb:', rgb.r, rgb.b, rgb.g) -- 66      245     135
local rgba = color.rgba
print('rgba:', rgba.r, rgba.b, rgba.g, rgba.a) -- 66      245     135     100
local color = Color('rgba(252, 3, 182, 51)')
print('opacity:', color.opacity) -- 0.2
print('decimal:', color.decimal) -- 16516022
print('hex:', color.hex) -- #fc03b6
local rgb = color.rgb
print('rgb:', rgb.r, rgb.b, rgb.g) -- 252     182     3
local rgba = color.rgba
print('rgba:', rgba.r, rgba.b, rgba.g, rgba.a) -- 252     182     3       51

🤖 Language Server

Install Sumneko Lua Language Server on Visual Studio Code.

About

Utilities for FiveM development environment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages