> 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-poker/admin-and-exports.md).

# Admin and exports

CAS Poker admin tools: /pokeradmin tables, bots and owed, the admin ace, the /pokertp and /pokermoney test commands, the table log, the GetTables export and money safety.

## Admin command

The admin command is `/pokeradmin` (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. Players without the ace get no answer.

| Command                     | What it does                                                                                                                                                                                             |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/pokeradmin tables`        | Lists every table: its phase, the hand number, the label and the seated players with their stacks (house players marked `npc`). `/pokeradmin` alone does the same.                                       |
| `/pokeradmin bots on\|off`  | Turns the house players on or off at every table, live. Not saved: a restart goes back to `Config.Bots.enabled`. See [House players](/script-documentation/cas-poker/house-players.md#turning-them-off). |
| `/pokeradmin owed <charId>` | Shows the money owed to a character: chips that could not be paid out at the time.                                                                                                                       |

Example output of `tables`:

```
blackwater [flop] hand 12 Blackwater Saloon | 1:John Smith($180) 3:Ezra Pike($120,npc)
```

The `charId` is the framework id with a prefix: `vorp:<charIdentifier>` on VORP and `rsg:<citizenid>` on RSG, for example `/pokeradmin 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 poker tools apart, set `Config.AdminAce = "poker.admin"` and grant that instead:

```
add_ace group.admin poker.admin allow
```

## Test commands

| Command                 | What it does                                                                                                                                                                 |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/pokertp <table id>`   | Teleports you a step behind seat 1 of that table, facing the felt (`valentine`, `blackwater`, `saintdenis`, `flatneck`, `tumbleweed`). Without an id it lists the table ids. |
| `/pokermoney <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 `/pokermoney`.
{% 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-poker/configuration.md#log)).

| Event              | What the line holds                                                                     | Console | Discord webhook |
| ------------------ | --------------------------------------------------------------------------------------- | ------- | --------------- |
| A player sits down | Table, character, name, seat and the buy-in                                             | Yes     | Yes             |
| A player leaves    | Table, character, name, the chips cashed out and what the player bought in at that seat | Yes     | Yes             |
| A hand ends        | Table and hand number (`showdown`, or `win` when everyone else folded)                  | Yes     | No              |

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

Amounts are in cents, so `buyIn=5000` is $50 and `chips=7350` is $73.50:

```
[cas-poker] sit buyIn=5000 char=vorp:12 name=John Smith seat=2 table=valentine
[cas-poker] showdown hand=12 table=valentine
[cas-poker] leave boughtIn=5000 char=vorp:12 chips=7350 name=John Smith table=valentine
```

## Server export

`GetTables()` is a server-side export that returns one entry per enabled table.

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

| Field     | Meaning                                                                                      |
| --------- | -------------------------------------------------------------------------------------------- |
| `id`      | The table id from `config/tables.lua`.                                                       |
| `label`   | The table label.                                                                             |
| `phase`   | `idle` between hands, otherwise the street being played: `preflop`, `flop`, `turn`, `river`. |
| `players` | Real players seated at the table.                                                            |
| `bots`    | House players seated at the table.                                                           |

## Money safety

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

* **The buy-in leaves the pocket when you sit down.** The server checks that the money really left before you get the seat. If the framework took less than asked, that part goes back and the seat is refused. Buying more chips works the same way.
* **Written down per character.** Every stack on a table is kept per character in the resource's KVP, the server's own key and value store, when you sit down, when you buy more chips and at the start and end of every hand. No SQL is needed.
* **Paid at the stand-up.** When you leave the table, your stack comes back to your pocket as cash.
* **Dropping or crashing.** A player who drops or crashes gives up the seat: a hand they are still in is folded (an all-in hand plays out first). Their chips are written down as owed and paid automatically on their next visit, at the latest when that character next opens the buy-in panel at a poker table. When it is paid as they join, they get the message "The house paid you $X left on the table last time."
* **Resource stop.** Stopping or restarting the resource pays out every seated player. A hand in play is called off and every player in it gets back the stack they had when it started. A player who is offline at that moment is owed the money.
* **Server crash.** When the server goes down without a clean stop, the stacks still on the tables become owed money at the next start, and the console says how many stacks and how much in all.
* **House players.** Their chips belong to the house, see [House players and your economy](/script-documentation/cas-poker/house-players.md#house-players-and-your-economy).
* **Rake.** Off by default. When it is on, the house keeps its share of each pot (see [Rake](/script-documentation/cas-poker/configuration.md#rake)).

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

## More

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