# Documents

***

### What this script does

**Codex Documents** is an in-game **document issuing and viewing system** for RedM built on **CodexCore**.

It provides:

* A paper-style NUI document UI
* A **My Documents** panel for players
* A job/grade-restricted **Issue Document** panel
* A proximity-based **Show Document** feature
* An **Admin Document Builder** for managing document templates

The system is based on:

* **Document templates** (types) stored in the database
* **Issued documents** linked to a specific character

***

### Dependencies

#### Required

* **codex\_core**

This resource depends on CodexCore for:

* Character identification
* Job and grade handling
* SQL execution
* Notifications
* Inventory item usage

***

### How the script works

#### Opening the UI

Players can open the document UI using:

* `/documents` command
* Client event: `codex_documents:open`

When opened, the script retrieves:

* Player job
* Job grade
* Character identifier

The UI displays:

* **My Documents** (always visible)
* **Issue Document** (only if the player has permission)

***

#### My Documents

Shows all documents owned by the current character.

Players can:

* View document details
* Show documents to nearby players (within a configured distance)

***

#### Issuing documents

Authorized jobs and grades can issue documents by:

1. Selecting a document template
2. Entering a target character ID
3. Filling document details (issuer, description, signature, expiration)
4. Issuing the document

The issued document:

* Is stored in the database
* Is assigned to the target character
* Optionally gives the target an inventory document item if online

***

#### Inventory document item

The script registers a usable inventory item defined in config.

When used:

* The script reads the document ID from item metadata
* The document opens in view-only mode

***

#### Showing documents to others

From the document UI:

* Players can show a document to the nearest player
* The target player must be within the configured distance
* Only the document owner can show it

***

#### Admin Document Builder

Players in the configured admin permission group can:

* Create document templates
* Edit existing templates
* Delete templates

***

### Permissions & job rules

Permissions are based on CodexCore job and grade.

#### Issuing documents

Controlled by:

* `Config.JobRules[job].issueMinGrade`

#### Managing templates (non-admin)

Controlled by:

* `Config.JobRules[job].manageMinGrade`

#### Admin access

Controlled by:

* `Config.AdminPermGroup`

***

### Configuration

All user-editable settings are located in **`shared/config.lua`**.

#### Document item

```lua
Config.DocumentItem = "codex_document"
```

#### Admin permission group

```lua
Config.AdminPermGroup = "admin"
```

#### UI animation

```lua
Config.PlayerAnimation = "WORLD_HUMAN_WRITE_NOTEBOOK"
```

#### Job categories

```lua
Config.Jobs = { ... }
Config.JobCategory = { ... }
```

#### Job grade rules

```lua
Config.JobRules = {
  police = { issueMinGrade = 1, manageMinGrade = 2 },
  doctor = { issueMinGrade = 1, manageMinGrade = 2 },
}
```

#### Show distance

```lua
Config.ShowDistance = 1.5
```

***

### Database

The resource requires:

* `codex_documents` table (templates)
* `codex_docs` table (issued documents)

These must be imported before use.

***

### Player usage examples

#### Issue a document

1. Run `/documents`
2. Open **Issue Document**
3. Select template
4. Enter target character ID
5. Fill document details
6. Issue

***

#### View a document

* Open `/documents`
* Select a document from **My Documents**
* Or use the document item from inventory

***

#### Show a document

1. Open `/documents`
2. Select a document
3. Click **Show**
4. Nearest player within range sees the document

***

### Notes

* Script logic and UI cannot be modified due to CFX escrow
* Only config values can be changed
* Permissions are enforced server-side

***

### Troubleshooting

#### Issue panel not visible

Check:

* Job name
* Job grade
* `Config.JobRules`

#### Show document fails

Increase:

* `Config.ShowDistance`

#### Inventory document does not work

Ensure:

* Document item exists in inventory
* Inventory supports metadata
