# Setup

## Installation

1. **Download & Extract**: Place the script in your `resources` folder.
2. **Add to Server CFG**: Add `ensure cs_bodycam`to your `server.cfg`.
3. **Configure Settings**: Modify `config.lua` as needed.
4. **Add Inventory Items `(Only QB,QBOX & ESX)`**:
   * **Ox Inventory:** Add the following to `ox_inventory/data/items.lua`:

     ```lua
     ['bodycam'] = {
         label = 'Radio',
         weight = 500,
         stack = false,
         description = 'A portable body camera used by law enforcement.',
         client = {
             event = 'cs:bodycam:useBodyCam',
             remove = function(total)
                 if total < 1 then
                     TriggerEvent('cs:bodycam:forceStop')
                 end
             end
         }
     },
     ['dashcam'] = {
         label = 'Dash Cam',
         weight = 500,
         stack = false,
         description = 'A vehicle-mounted dashcam used for recording footage.',
         client = {
             event = 'cs:bodycam:useDashCam',
         }
     },
     ```
   * **QB Inventory:** Add the following to `qb-core/shared/items.lua`:

     ```lua
     ["bodycam"] = {
         name = "bodycam",
         label = "Body Cam",
         weight = 500,
         type = "item",
         image = "bodycam.png",
         unique = true,
         description = "A portable body camera used by law enforcement."
     },

     ["dashcam"] = {
         name = "dashcam",
         label = "Dash Cam",
         weight = 500,
         type = "item",
         image = "dashcam.png",
         unique = true,
         description = "A vehicle-mounted dashcam used for recording footage."
     },
     ```
   * **ESX Inventory:** Run the following SQL query in your database:

     ```lua
     INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
     ('bodycam', 'Body Cam', 1, 0, 1),
     ('dashcam', 'Dash Cam', 1, 0, 1);
     ```

### Configuration

Modify the `config.lua` file to customise the script:

#### General Framework Settings

```lua
Config.ServerType = 'QB'  -- Choose the framework:
                              -- 'QB' for QBCore or Qbox Framework
                              -- 'ESX' for ESX Framework
                              -- false for Standalone Mode
```

#### Dashboard Panel & Groups

```lua
Config.Dashboard = {
    ['police'] = { --job
        Title = 'Los Santos Police Department', -- Main title displayed on the UI
        DashBoard_Access = 4,                   -- Min rank required to open the dashboard
        Logo = 'police.png',                    -- Logo file name located in: ui/image/
        Location = {                            -- Map coordinates for physical dashboard access
            vector4(459.74, -989.2, 24.91, 279.71)
        }
    },
    ['ambulance'] = { 
        Title = 'Pillbox Hospital Department',
        DashBoard_Access = 4,
        Logo = 'ambulance.png'
    },
}
```

#### Using Standalone Mode

If you are running a standalone server (not using QBCore or ESX), you need to define user permissions manually using Steam, Ace Permissions, Discord IDs, or Role IDs. Here’s how to configure it:

```lua
Config.Dashboard = {
    -- If using standalone, use Steam Hex, Ace Group, or Discord Role ID as the key.
    ['put_perms_here'] = {           
        Title = 'YOUR Department',
        DashBoard_Access = 'put_perms_here', 
        Logo = 'police.png',
        Location = {            
            vector4(485.74, -989.2, 24.91, 279.71)
        }
    },
}
```

* **DashBoard\_Access**: Replace `'put_perms_here'` with Steam HEX, Ace Group, Discord ID, or Role ID.
* **Title**: Department name.
* **Logo**: Path to department logo.
* **Location**: If set, players must stand at this position to access the dashboard. Set to `false` if not required.

#### BodyCam Settings

```lua
Config.BodyCam = {
    Enable = true,
    AllowCivilians = true,  -- If false, restricts usage to jobs defined in Config.Dashboard
    ShowProfilePic = true,  -- Automatically takes a mugshot/profile pic when bodycam is active
    Use = {
        WithItem = false,   -- Require an item to toggle the bodycam
        ItemName = 'bodycam',
        DisconnectOnNo_BodyCam = false, -- Auto-off if the item is removed (Requires use WithItem)
        
        WithCommand = true, -- Allow toggling via command
        CommandName = 'bodycam'
    },
}
```

#### DashCam Settings

```lua
Config.DashCam = {
    Enable = true,
    UseMPH = false,  -- Set to true for MPH, false for KM/H
    Use = {
        WithItem = false,
        ItemName = 'dashcam',
        RemoveItemOnUse = false, -- Consume the item upon installation

        WithCommand = true,
        CommandName = 'dashcam'
    },
    -- Set to 'false' to allow dashcams in ALL vehicles.
    Restrict_Vehicle = {  
        [`police`] = true,
        [`polgauntlet`] = true,
        [`ambulance`] = true,
    }
}
```

#### Recording Settings

```lua
Config.Recording = {
    Enable = false,       -- Enable or disable the video recording system
    Fivemanage = false,   -- Set to true to use Fivemanage API (Recommended for long clips)
    CustomUpload = false, -- Set to true to use your own custom uploader in index.html
    RecordFPS = 45,       -- Recording framerate (Higher = smoother but larger files)

    -- [ UPLOAD LOGIC ] --
    -- If Fivemanage and CustomUpload are both 'false', the script defaults to DISCORD.
    -- To configure your Webhook URL or API Keys, edit: config/functions/sv_function.lua
    
    -- *NOTE: Discord has a strict upload limit (usually 25MB). 
    -- For longer recordings, it is highly recommended to use Fivemanage.
}
```

> **Note:** For longer recordings, it is highly recommended to use Fivemanage

#### Enabling Automatic Recording When Using BodyCam (Item)

Modify and replace existing code in`cs_bodycam\config\functions\sv_function.lua` at line 90 with the below code to automatically start recording when a bodycam is used:

```lua
if Config.BodyCam.Use.WithItem then
    local itemName = Config.BodyCam.Use.ItemName
    if Config.ServerType == 'QB' then
        QBCore.Functions.CreateUseableItem(itemName, function(source, item)
            TriggerClientEvent('cs:bodycam:useBodyCam', source)
            Wait(500)
            TriggerClientEvent('cs:bodycam:toggleRecording', source)
        end)
    elseif Config.ServerType == 'ESX' then
        ESX.RegisterUsableItem(itemName, function(source)
            TriggerClientEvent('cs:bodycam:useBodyCam', source)
            Wait(1000)
            TriggerClientEvent('cs:bodycam:toggleRecording', source)
        end)
    else
        --Standalone [You can edit this accordingly] --
    end
end
```

This ensures the recording automatically starts when a player uses the bodycam item.

#### **Adding a Keybind for Recording**

To allow players to start recording by pressing `Y (configurable)`, add the following code to `cs_bodycam\config\functions\cl_function.lua`:

```lua
lib.addKeybind({
    name = 'record',
    description = 'Press Y to record',
    defaultKey = 'Y',
    onPressed = function(self)
        TriggerEvent('cs:bodycam:toggleRecording')
    end,
})
```

This binds the `Y` key to toggle recording, providing a convenient way for players to start and stop recording manually.

### How to Use

1. **Access Dashboard**: Stand at the designated location (if set) or use the command `/camdash` to open UI.
2. **Use BodyCam**: Run `/bodycam` (if enabled) or activate via inventory.
3. **Use DashCam**: Run `/dashcam` in a valid vehicle.
4. **Use Recording**: Run `/recording` to open the record panel.
