Exports and API
Read a player's divisions from another script, open menus, add vehicles to a garage.
#A player's divisions (server)
Lua
exports['tc-divisions']:GetPlayerDivisions(src) -- { { id, label, color }, ... } (all of them)
exports['tc-divisions']:GetPlayerDivision(src) -- the first one: { job, id, label, divisions } or nil
exports['tc-divisions']:IsPlayerInDivision(src, 'SWAT') -- id or label; true if they belong to it
exports['tc-divisions']:GetJobDivisions('lspd') -- a job's divisions#State bag
Lua
Player(src).state.tcDivision -- { job, id, label, divisions = {...} } or falseHandy for checking the division client-side without a server call.
#Example: restrict an action to a division
server.lua
RegisterNetEvent('myscript:armoury', function()
local src = source
if not exports['tc-divisions']:IsPlayerInDivision(src, 'SWAT') then
return tc.notify(src, { description = 'SWAT only.', type = 'error' })
end
-- ... give the equipment
end)#Menus (client)
Lua
exports['tc-divisions']:OpenDivisionMenu() -- same menu as /division
exports['tc-divisions']:OpenGestionMenu() -- staff menu (/divgestion), permission checked by the server#Garages: external fleet resource
Three server exports let a fleet resource add vehicles directly to a garage. The calling resource checks its own player's permission itself.
Lua
exports['tc-divisions']:GetFleetGarages()
-- { { id, label, enabled, count, jobs = { {name, label} }, divisions = { {id, job, label, color} },
-- vehicles = { {id, model, label} } }, ... }
exports['tc-divisions']:AddFleetVehicle(garageId, data, actor)
-- data = { model, label, props, divisions = { ids }, shared, callsign }
-- A vehicle with the same model and name in that garage is replaced, otherwise it is added at the end.
-- Returns: { ok = true, id, replaced, count } or { ok = false, err = '…' }
exports['tc-divisions']:PatchFleetProps(patches, actor)
-- patches = { [lowercase model] = { key = value } }: merged into the props of every
-- vehicle of that model, in every garage (service performance applied by a fleet resource).
-- Returns: { ok = true, … } or { ok = false, err = '…' }actor is free text (name of the person or resource) written to the journal.
Loading
While tc-divisions has not finished loading, these exports answer { ok = false, err = '… loading.' }. Retry a few seconds later.
#Discord journal
With tc-logs started and Config.Integrations.logs = true, the journal is copied to Discord (webhooks are set in tc-logs).