# Systems Overview

## Architecture and escrow

Open files handle most integration work.

Key files:

* `shared/config.lua` covers jobs, meds, pharmacies, insurance, supplies, bans, permissions, notify, and TextUI.
* `shared/lang.lua` stores UI strings and metadata description templates.
* `client/client_open.lua` handles animations, overdose, lean, panic hooks, shoplifting hooks, and client-side vehicle keys.
* `server/server_open.lua` handles Discord logging, metadata building, medication helpers, and server-side vehicle keys.
* `server/insurance.lua` and `client/insurance.lua` handle plans, payments, claims, and self-service insurance UI.
* `server/insurance_broker.lua` and `client/insurance_broker.lua` handle broker sales, commissions, and insurance bans.
* `server/pharmacy_supplies.lua` and `client/pharmacy_supplies.lua` handle stock, restocks, and supply reduction.
* `server/prescription_records.lua` manages DB prescription records and flagging.
* `server/employee_computer.lua` and `client/employee_computer.lua` power the staff computer.
* `server/shoplifting.lua` and `client/shoplifting.lua` handle shelf loot, detection, and bans.

Escrow keeps the core flow files protected.

The main open integration files are still available for your server-specific hooks.

## Critical config flags

These values change behavior fast:

* `Config.TestMode`
* `Config.Debug`
* `Config.PayIntoSociety`
* `Config.PayIntoInsuranceSociety`
* `Config.Target`
* `Config.ServerSidePeds`

{% hint style="warning" %}
Leave `Config.TestMode` off on live servers.

It changes how writing and test commands behave.
{% endhint %}

## Database

Representative tables used by the system:

* `prescription_records`
* `pharmacy_supplies`
* `medical_insurance`
* `medical_insurance_claims`
* `pharmacy_bans`
* `med_insurance_commissions`
* `med_insurance_bans`

`Config.DatabaseCleanup` handles retention for claims, adjuster activity, and inactive bans.

`Config.MaxPrescriptionRecords` caps how many records are kept per doctor.

## Prescriptions and medications

Authoring depends on:

* `Config.Job`
* `Config.MinimumGrade`
* `Config.ItemUse` with `Config.ItemName`
* or `Config.CommandName`

The prescription item uses metadata for patient details, doctor signature, medication, and dose tracking.

`Config.Medications` defines each medication entry.

Each entry can include:

* `item`
* `label`
* optional `total`
* `effects`
* `sideEffects`
* `anim`
* `costPerDose`

Pricing comes from the base medication cost plus the dose cost, then insurance modifies that total.

## Pharmacies

Each `Config.Pharmacies` entry can include:

* ped model and spawn
* blip
* customer interaction radius
* walk-to-counter behavior
* employee counter
* drug collection location
* restock location
* robbery shelves and loot

Staff permissions come from `Config.PharmacyPermissions`.

That controls records, flagging, unflagging, unbans, and history clearing.

## Insurance

`Config.InsuranceSystem` is the master insurance switch.

It also handles claim retention, payment cycle days, and medication rejection chance.

`Config.InsurancePlans` defines the plan list, fees, discount, down payment, and medication eligibility.

`Config.InsuranceJob` defines broker access, minimum grade, boss grade, commission, and self-service availability.

## Supplies and restock

`Config.SuppliesSystem` controls stock levels, low-stock checks, restock reward, and the supply box model.

`Config.RestockMission` and `Config.PharmacyRestockMissionLocations` control the delivery mission flow.

The server export `reducePharmacySupplies(pharmacyId)` returns whether stock was actually reduced.

## Shoplifting, bans, and records

`Config.Bans` controls ban history, repeat multipliers, and permanent ban thresholds.

Detection uses shelf chances and pharmacist busy-state style rolls.

The employee computer supports:

* prescription search
* flagged prescription review
* panic integration
* patient targeting for staff flows

## Lean, overdose, and hooks

Lean-related items:

* `Config.CoughSyrupItem`
* `Config.LeanCupItem`
* `Config.SprunkItem`
* `Config.LeanItem`
* `Config.LeanItems`

Overdose and narcan related values:

* `Config.NarcanItem`
* `DrugTaken(amount)`
* `StartOverdose()`
* `StopOverdose()`

Open integration points include dispatch, vehicle keys, notify, TextUI, and Discord logging.
