> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-blackjack/admin-and-exports.md).

# Admin and exports

CAS Blackjack admin tools: /blackjackadmin tables and owed, the admin ace, the /bjtp and /bjmoney test commands, the GetTables server export and how bets are kept safe.

## Admin command

The admin command is `/blackjackadmin` (renamed with `Config.AdminCommand`). It works from the server console and for players who have the ace in `Config.AdminAce` (default `command`). In game the answer comes in the chat, in the console it is printed.

| Command                         | What it does                                                                                                                                              |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/blackjackadmin tables`        | Lists every table: its phase, the round number, the cards left in the shoe and the seated players with their bets. `/blackjackadmin` alone does the same. |
| `/blackjackadmin owed <charId>` | Shows the money owed to a character: bets and winnings that could not be paid at the time.                                                                |

Example output of `tables`:

```
blackwater [betting] round 12 shoe 287 | 1:John Smith($10) 3:Sadie Adler($25)
```

The `charId` is the framework id with a prefix: `vorp:<charIdentifier>` on VORP and `rsg:<citizenid>` on RSG, for example `/blackjackadmin owed vorp:12`.

### Giving the ace

Most `server.cfg` files already give the `command` ace to the admin group:

```
add_ace group.admin command allow
```

To keep the blackjack tools apart, set `Config.AdminAce = "blackjack.admin"` and grant that instead:

```
add_ace group.admin blackjack.admin allow
```

## Test commands

| Command              | What it does                                                                                                          |
| -------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `/bjtp <table id>`   | Teleports you next to a seat at that table (`blackwater`, `rhodes`, `vanhorn`). Without an id it lists the table ids. |
| `/bjmoney <dollars>` | Gives you that amount of the table money, from 1 to 100000 (500 when left out).                                       |

They are for admins only (the same ace as the admin command) and they do not run from the server console. `Config.TestCommands = true` lets every player use them.

{% hint style="danger" %}
Only turn `Config.TestCommands` on for a test server. With it on, every player can give themselves money with `/bjmoney`.
{% endhint %}

To rename them, add `Config.TeleportCommand = "yourname"` and `Config.MoneyCommand = "yourname"` to `config/config.lua`.

## Table log

`Config.Log` in `config/config.lua` keeps a history of the tables (see [Configuration](/script-documentation/cas-blackjack/configuration.md#log)).

| Event              | What the line holds                                                      |
| ------------------ | ------------------------------------------------------------------------ |
| A player sits down | Table, character, name and seat                                          |
| A player leaves    | Table, character and name                                                |
| A hand is settled  | Table, character, net result and payout, one line per seat at the settle |

* `console = true` prints every line to the server console.
* `webhook` set to a Discord webhook URL posts every line to that channel: each sit-down, each leave and every settled hand. The posts go out under the name in `username`.

Amounts are in cents, so `net=500` is $5:

```
[cas-blackjack] sit char=vorp:12 name=John Smith seat=1 table=blackwater
[cas-blackjack] settle char=vorp:12 net=500 payout=1000 table=blackwater
[cas-blackjack] leave char=vorp:12 name=John Smith table=blackwater
```

## Server export

`GetTables()` is a server-side export that returns one entry per enabled table with its `id`, `label` and `phase`.

```lua
local tables = exports["cas-blackjack"]:GetTables()
for _, t in ipairs(tables) do
    print(t.id, t.label, t.phase)
end
```

| Phase       | Meaning                                                               |
| ----------- | --------------------------------------------------------------------- |
| `idle`      | No bets on the table.                                                 |
| `betting`   | Betting is open.                                                      |
| `dealing`   | The dealer is dealing.                                                |
| `insurance` | Players are answering the insurance offer.                            |
| `playing`   | Players are playing their hands.                                      |
| `cleanup`   | The round is settled and the dealer is paying and sweeping the cards. |

## Money safety

Bets are real money taken from the character, so the script keeps track of every dollar on the felt.

* **Bets leave the pocket when they are placed.** The server checks that the money really left before the bet counts. If the framework took less than asked, that part goes back and the bet is refused.
* **Extra stakes are taken on the spot.** Double down, split and insurance take their money when you choose them. Without enough money on you, a message says so and the move is not made.
* **Written down per character.** Every stake on the table is kept per character in the resource's KVP, the server's own key and value store. No SQL is needed.
* **Paid at the settle.** The stake and the winnings come back together at the end of the round.
* **Leaving during betting.** Taking a bet back or leaving the table during betting gives the bet back at once.
* **Dropping mid round.** A player who leaves, drops or crashes mid round is not lost: their open hands stand and the round settles as normal. The winnings go straight to the player when they are still online on the same character. Otherwise the money is written down as owed and paid automatically on their next visit, at the latest when that character next sits down at a blackjack table.
* **Resource stop.** Stopping or restarting the resource calls off a round in play and every bet on the felt goes back to its player (or is owed when the player is offline).
* **Server crash.** When the server goes down without a clean stop, the bets still on the tables become owed money at the next start, and the console says how many bets and how much in all.

Check what a character is owed with `/blackjackadmin owed <charId>`.

## More

* [Buy CAS Blackjack](https://codeaftersex.com/script/blackjack)
* [Support Discord](https://discord.gg/codeaftersex)
* [All CodeAfterSex scripts](https://codeaftersex.com/scripts)
