🔄Server Exports

What are Exports?

Exports are functions that can be called from other resources in your FiveM server. They allow different scripts to communicate and share functionality without modifying each other's code.

Think of exports as a public API - other resources can use these functions to interact with the Boss Menu system.


Money & Society Functions

GetSocietyBalance

Get the current balance of a company/job.

Parameters:

  • jobName (string) - Name of the job/company

Returns: number - Current balance

Example:

local balance = exports['m-BossMenu']:GetSocietyBalance('ambulance')
print("Hospital balance: $" .. balance)

AddSocietyMoney

Add money to a company account.

Parameters:

  • jobName (string) - Name of the job/company

  • amount (number) - Amount to add

Returns: boolean - Success status

Example:

-- Give $10,000 to the police department
local success = exports['m-BossMenu']:AddSocietyMoney('police', 10000)
if success then
    print("Money added successfully!")
end

RemoveSocietyMoney

Remove money from a company account.

Parameters:

  • jobName (string) - Name of the job/company

  • amount (number) - Amount to remove

Returns: boolean - Success status

Example:

-- Deduct $5,000 from mechanic shop
local success = exports['m-BossMenu']:RemoveSocietyMoney('mechanic', 5000)
if success then
    print("Money deducted successfully!")
end

Invoice Functions

CreateInvoice

Create a new invoice from a company to a player.

Parameters:

  • senderId (number) - Source ID of the sender

  • targetId (number) - Source ID or identifier of the target

  • amount (number) - Invoice amount

  • reason (string) - Reason/description for the invoice

  • jobName (string, optional) - Job name (defaults to sender's job)

Returns: table - { success = boolean, message = string }

Example:

local result = exports['m-BossMenu']:CreateInvoice(
    source,              -- Sender (boss)
    targetPlayerId,      -- Target player
    2500,                -- Amount: $2,500
    "Vehicle repair",    -- Reason
    "mechanic"           -- Job name
)

if result.success then
    print("Invoice created: " .. result.message)
else
    print("Failed: " .. result.message)
end

GetInvoices

Get all invoices for a specific job.

Parameters:

  • jobName (string) - Name of the job/company

  • status (string, optional) - Filter by status: "pending", "paid", "cancelled"

Returns: table - Array of invoice objects

Example:

-- Get all pending invoices for police
local invoices = exports['m-BossMenu']:GetInvoices('police', 'pending')

for _, invoice in ipairs(invoices) do
    print("Invoice #" .. invoice.id .. ": $" .. invoice.amount)
end

CancelInvoice

Cancel an existing invoice.

Parameters:

  • invoiceId (number) - ID of the invoice to cancel

Returns: boolean - Success status

Example:

local success = exports['m-BossMenu']:CancelInvoice(42)
if success then
    print("Invoice cancelled!")
end

Employee Management

GetEmployees

Get all employees of a specific job.

Parameters:

  • jobName (string) - Name of the job/company

Returns: table - Array of employee objects

Example:

local employees = exports['m-BossMenu']:GetEmployees('police')

print("Total employees: " .. #employees)
for _, emp in ipairs(employees) do
    print(emp.name .. " - Grade: " .. emp.grade)
end

HireEmployee

Hire a player to a job.

Parameters:

  • citizenid (string) - Citizen ID of the player

  • jobName (string) - Job to hire them for

  • grade (number, optional) - Starting grade (default: 0)

Returns: boolean - Success status

Example:

local success = exports['m-BossMenu']:HireEmployee(
    'ABC12345',  -- Citizen ID
    'police',    -- Job
    1            -- Grade (Officer)
)

FireEmployee

Fire an employee (set them to unemployed).

Parameters:

  • citizenid (string) - Citizen ID of the employee

Returns: boolean - Success status

Example:

local success = exports['m-BossMenu']:FireEmployee('ABC12345')
if success then
    print("Employee fired!")
end

SetEmployeeGrade

Promote or demote an employee.

Parameters:

  • citizenid (string) - Citizen ID of the employee

  • grade (number) - New grade/rank

Returns: boolean - Success status

Example:

-- Promote to grade 3
local success = exports['m-BossMenu']:SetEmployeeGrade('ABC12345', 3)

Warehouse Functions

GetWarehouseStock

Get all items in a company's warehouse.

Parameters:

  • jobName (string) - Name of the job/company

Returns: table - Array of stock items

Example:

local stock = exports['m-BossMenu']:GetWarehouseStock('mechanic')

for _, item in ipairs(stock) do
    print(item.item_name .. ": " .. item.quantity)
end

AddWarehouseItem

Add items to the warehouse.

Parameters:

  • jobName (string) - Name of the job/company

  • itemName (string) - Item identifier

  • quantity (number) - Amount to add

Returns: boolean - Success status

Example:

-- Add 50 repair kits to mechanic warehouse
local success = exports['m-BossMenu']:AddWarehouseItem('mechanic', 'repairkit', 50)

RemoveWarehouseItem

Remove items from the warehouse.

Parameters:

  • jobName (string) - Name of the job/company

  • itemName (string) - Item identifier

  • quantity (number) - Amount to remove

Returns: boolean - Success status

Example:

-- Remove 10 bandages from hospital warehouse
local success = exports['m-BossMenu']:RemoveWarehouseItem('ambulance', 'bandage', 10)
if not success then
    print("Not enough items in warehouse!")
end

Transaction Functions

GetTransactions

Get transaction history for a company.

Parameters:

  • jobName (string) - Name of the job/company

  • limit (number, optional) - Maximum number of transactions to return

Returns: table - Array of transaction objects

Example:

-- Get last 10 transactions
local transactions = exports['m-BossMenu']:GetTransactions('police', 10)

for _, tx in ipairs(transactions) do
    print(tx.date .. " - " .. tx.type .. ": $" .. tx.amount)
end

AddTransaction

Manually add a transaction record.

Parameters:

  • jobName (string) - Name of the job/company

  • type (string) - Transaction type: "deposit", "withdraw", "payment", etc.

  • amount (number) - Transaction amount

  • description (string) - Transaction description

  • clientName (string, optional) - Client name (default: "System")

Returns: boolean - Success status

Example:

exports['m-BossMenu']:AddTransaction(
    'police',
    'fine',
    500,
    'Speeding ticket',
    'John Doe'
)

Duty Clock Functions

GetDutyStatus

Check if a player is currently on duty.

Parameters:

  • citizenid (string) - Citizen ID of the player

Returns: table - { onDuty = boolean, data = table or nil }

Example:

local status = exports['m-BossMenu']:GetDutyStatus('ABC12345')

if status.onDuty then
    print("Player is on duty since: " .. status.data.clock_in)
else
    print("Player is not on duty")
end

ClockIn

Clock in a player to start their duty.

Parameters:

  • citizenid (string) - Citizen ID of the player

  • jobName (string) - Job name

Returns: boolean - Success status

Example:

local success = exports['m-BossMenu']:ClockIn('ABC12345', 'police')
if success then
    print("Clocked in successfully!")
end

ClockOut

Clock out a player to end their duty.

Parameters:

  • citizenid (string) - Citizen ID of the player

Returns: boolean - Success status

Example:

local success = exports['m-BossMenu']:ClockOut('ABC12345')
if success then
    print("Clocked out successfully!")
end

GetDutyHours

Get total duty hours for a player.

Parameters:

  • citizenid (string) - Citizen ID of the player

  • period (string, optional) - Time period: "today", "week", "month", or nil (all time)

Returns: number - Total hours worked

Example:

local todayHours = exports['m-BossMenu']:GetDutyHours('ABC12345', 'today')
local weekHours = exports['m-BossMenu']:GetDutyHours('ABC12345', 'week')
local allTimeHours = exports['m-BossMenu']:GetDutyHours('ABC12345')

print(string.format("Today: %dh | Week: %dh | Total: %dh", todayHours, weekHours, allTimeHours))

Practical Use Cases

Example 1: Custom Job Payment System

-- Give salary to all online employees
local employees = exports['m-BossMenu']:GetEmployees('police')

for _, emp in ipairs(employees) do
    local Player = QBCore.Functions.GetPlayerByCitizenId(emp.citizenid)
    if Player then
        Player.Functions.AddMoney('bank', emp.salary)
        
        -- Log transaction
        exports['m-BossMenu']:AddTransaction(
            'police',
            'salary',
            emp.salary,
            'Monthly salary payment',
            emp.name
        )
    end
end

Example 2: Auto-Fine System

-- When player gets a speeding ticket
RegisterNetEvent('police:speedingTicket', function(targetId, amount)
    local result = exports['m-BossMenu']:CreateInvoice(
        source,
        targetId,
        amount,
        'Speeding ticket - ' .. amount .. ' km/h over limit',
        'police'
    )
    
    if result.success then
        TriggerClientEvent('QBCore:Notify', source, 'Ticket issued!', 'success')
    end
end)

Example 3: Warehouse Integration

-- Custom crafting system that uses warehouse stock
RegisterNetEvent('mechanic:craftItem', function()
    local src = source
    
    -- Check if warehouse has materials
    local stock = exports['m-BossMenu']:GetWarehouseStock('mechanic')
    local hasSteel = false
    
    for _, item in ipairs(stock) do
        if item.item_name == 'steel' and item.quantity >= 10 then
            hasSteel = true
            break
        end
    end
    
    if hasSteel then
        -- Remove materials from warehouse
        exports['m-BossMenu']:RemoveWarehouseItem('mechanic', 'steel', 10)
        
        -- Give crafted item to player
        local Player = QBCore.Functions.GetPlayer(src)
        Player.Functions.AddItem('repairkit', 1)
    end
end)

Example 4: Company Balance Check

-- Before allowing expensive purchases
RegisterNetEvent('shop:buyExpensiveItem', function(itemPrice)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    local job = Player.PlayerData.job.name
    
    local balance = exports['m-BossMenu']:GetSocietyBalance(job)
    
    if balance >= itemPrice then
        exports['m-BossMenu']:RemoveSocietyMoney(job, itemPrice)
        Player.Functions.AddItem('expensive_item', 1)
    else
        TriggerClientEvent('QBCore:Notify', src, 'Company has insufficient funds!', 'error')
    end
end)

Important Notes

  1. Server-Side Only: All exports are server-side only for security

  2. Error Handling: Always check return values before proceeding

  3. Citizen ID Format: Use the correct identifier format for your framework (QBCore vs ESX)

  4. Database: Ensure all database tables are properly installed


Last updated