# Server

How the server handles sales, inventory, and security.

## sellPawnItems Event

The main event triggered by the client when a player confirms a sale. All validation happens here, server-side.

### Validation chain

1. **Sell lock check**\
   If `sellLock[src]` is true, the request is rejected with a notification. The lock releases after 1 second.
2. **Player check**\
   `QBCore.Functions.GetPlayer(src)` — if nil the function returns early without punishment.
3. **Item config check**\
   The item name is searched in `Config.PawnItems`. If not found → **permanent ban**.
4. **Amount validation**\
   Must be a positive whole integer (`math.floor(n) == n`). Otherwise → **permanent ban**.
5. **Proximity check**\
   Player must be within 5.0 units of a `Config.PawnLocation` coord. Otherwise → **permanent ban**.
6. **Inventory check**\
   Actual item count verified server-side. If insufficient → notification, no ban.

## Universal Inventory Functions

### `getItemCount(src, itemName)`

Returns the player's count of an item. Detection order:

```lua
-- Detection order (first match wins):
-- 1. ox_inventory → exports['ox_inventory']:GetItemCount(src, itemName)
-- 2. qs-inventory → loops GetInventory result
-- 3. ps/qb-inventory → Player.Functions.GetItemByName(itemName)
```

### `removeItem(src, itemName, amount)`

Removes items using the same detection order. Returns `true` on success, `false` on failure.

## getInv Callback

Registered as `moh-pawnshop:server:getInv`. Called by the client before opening the UI. Returns a normalized array:

```lua
-- Return format (all inventories normalized to this):
-- {{ name = 'goldchain', amount = 3 }},
-- {{ name = 'diamond', amount = 1 }}
```

## Webhook

After a successful sale, `sendWebhook(message)` fires a POST to `Config.Webhook` with a Discord embed containing player name, item, quantity, price, total, money type, server ID, Discord mention, and license.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mohssins.gitbook.io/mohscriptsdocs/moh-pawnshop/server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
