# Setup

The phone needs two libraries the rest of c3r doesn't, plus a couple of optional steps for items and uploads.

## Requirements

| Resource | Why |
|---|---|
| [ox_lib](https://github.com/overextended/ox_lib) | Callbacks, key bindings. **Required** |
| [oxmysql](https://github.com/overextended/oxmysql) | The database (MariaDB 10.2+ or MySQL 8). **Required** |
| A framework *(optional)* | qbx_core, qb-core, es_extended, ox_core or ND_Core. Without one it runs standalone |
| A voice script *(optional)* | pma-voice, saltychat or mumble-voip, for sound on calls |
| An inventory *(optional)* | The phone as an item |
| A [Fivemanage](https://fivemanage.com) token *(optional)* | The camera, voice messages, voice memos and voicemail |
| OneSync *(optional)* | Speaker, AirShare, hiring and locating a vehicle |

## Start order

The phone must start after ox_lib, oxmysql, your framework, inventory and voice script:

```cfg
ensure ox_lib
ensure oxmysql
# ...framework, inventory, voice...
ensure [c3r_core]
```

Tables are created on first start; there's no SQL to import.

> [!WARNING]
> Remove your old phone first, so two phones don't fight over the same key and command. Coming from NPWD or GCPhone? Leave its database tables where they are: setup offers to bring everyone's data across.

## Admin access

```cfg
add_ace group.admin lwk_phone.admin allow
```

## The phone as an item

On a framework server with a supported inventory, the phone is an item and **each item is its own phone**: the number is written onto the item and every bit of phone data is keyed by it. Give the item away, or have it taken, and the phone goes with it.

**ox_inventory** (also used by Qbox, ox_core and ND_Core), in `ox_inventory/data/items.lua`:

```lua
['phone'] = { label = 'Phone', weight = 190, stack = false, consume = 0, client = { export = 'lwk_phone.usePhone' } },
```

**Every other inventory:** an item named `phone` in its item list (`qb-core/shared/items.lua`, the inventory's own list, or ESX's `items` table): not stackable, usable, closing the inventory when used.

With several phones in a pocket, using one opens that one. Where the inventory doesn't say which was used, the first is opened. In the config, `item.require = false` drops the item altogether, and `item.unique = false` keeps the item but ties the phone to the character.

## Photos, video and voice messages

These upload to [Fivemanage](https://fivemanage.com). Put your API token in `config/keys.lua` (only the server reads that file), or in `server.cfg`:

```cfg
set lwk_phone_fivemanage "your-token"
```

Without a token the camera says storage isn't set up, and everything else still works.

Pictures, video and voice messages in texts and posts are only accepted from the hosts in `upload.hosts` (your upload host by default). Without that limit, a player could post a link to their own server and collect the IP address of everyone whose phone shows it.

## Logs

Put a Discord webhook in `config/keys.lua`, or:

```cfg
set lwk_phone_webhook "https://discord.com/api/webhooks/..."
```

It logs posts, money transfers, company account deposits and withdrawals, old-phone transfers and admin prunes. Leave it empty to turn logs off.

## Updating

Replace the folder, keeping your own copies of the three files you may have edited: `config/config.lua`, `config/keys.lua` and `web/dist/theme.json`. The database looks after itself: tables and columns are added on start and nothing is ever removed, so going back to the previous version is just putting the old folder back.
