# Usage

##

This guide explains how to use the script as admin, owner, and customer.

### Admin workflow

#### 1. Create a shop

Command:

* `/createshop`

Steps:

1. open the admin UI
2. enter:
   * shop name
   * type (`regular`, `gun`, `it`, or custom type from config)
   * buy price (shop purchase price)
3. stand at desired locations and click:
   * `Set NPC here`
   * `Set Truck Spawn here`
   * `Set Truck Return here`
4. click `Create Shop`

#### 2. Edit existing shops

Command:

* `/checkshops`

You can update:

* NPC location
* truck spawn location
* truck return location

### Player workflow (customer)

1. go to a shop NPC
2. open store via target interaction (`Open store`)
3. add items to cart
4. buy items (`Buy`)

Notes:

* purchases use player **cash**
* the shop must have stock for each item

### Owner workflow

#### 1. Buy a shop

At NPC, select `Buy Shop`.

Conditions:

* shop has no owner
* player has enough **bank** money for buy price

Purchase effect:

* owner is set to player
* balance is reset to 0
* stock is initialized to 0 for all items of that shop type

#### 2. Company balance

Owner actions:

* `Deposit` (moves money from owner bank to company balance)
* `Withdraw` (moves money from company balance to owner bank)

Profit:

* part of each sale is added to company balance (`Config.PercentageToShop`)

#### 3. Item pricing

Owner can change item prices.

Restriction:

* price must stay inside limits defined by `Config.PriceChangeLimit`
* limits are calculated from item `buyPrice`

#### 4. Stock orders and delivery

Steps:

1. owner creates stock order from Owner UI (`Order`)
2. cost is deducted from company balance
3. delivery is created (`to_pickup`)
4. delivery vehicle spawns at `truckSpawn`
5. go to supplier location
6. at marker press `E` (while inside delivery vehicle) to pickup
7. stage changes to `to_return`
8. return to `truckReturn`
9. at marker press `E` (inside delivery vehicle) to complete
10. stock is added to shop

Important:

* only one active delivery per shop is allowed
* without stock, customers cannot buy items

#### 5. Selling a shop

`Sell to state`:

* selling to server returns 50% of buy price to owner

`Sell to player`:

* endpoint exists, but player-to-player sale is currently not implemented on server

### Commands

* `/createshop` - admin create shop UI
* `/checkshops` - admin edit existing shops

### Developer notes

* DB tables:
  * `player_shops`
  * `player_shop_deliveries`
* server callback for owner data:
  * `playerShops:getShopData`
* important server events:
  * `playerShops:buyShop`
  * `playerShops:checkout`
  * `playerShops:orderStock`
  * `playerShops:deliveryPickup`
  * `playerShops:deliveryReturn`
  * `playerShops:setItemPrice`
  * `playerShops:deposit`
  * `playerShops:withdraw`
