> 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-advanced-darts-system/installation.md).

# Installation

Install CAS Advanced Darts System on VORP Core, RSG Core or standalone. server.cfg lines, ace, the two board items, OneSync, database and a first check.

## What you need

* A RedM server with **OneSync** on.
* **oxmysql**.
* One of these, or none of them for standalone:
  * VORP Core with `vorp_inventory`
  * RSG Core with `rsg-inventory`

## 1. Copy the resources

The download has a folder `[cas_darts]` with two resources. Copy it into your `resources` folder.

| Resource           | What it holds                                                                                                                  |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `cas-darts-assets` | The models: dartboard with its surround, oche bar, throwing mat, board stand and the dart, plus `cas_darts.ytyp`. Nothing else |
| `cas-darts`        | The script: config, locale, server, client and the interface (`html/`)                                                         |

Inside `cas-darts` there is also an `install` folder. The game does not load it. It holds what you add to your inventory:

| File                                          | What it is                          |
| --------------------------------------------- | ----------------------------------- |
| `cas-darts/install/items_vorp.sql`            | The two items for VORP              |
| `cas-darts/install/items_rsg.lua`             | The two items for RSG               |
| `cas-darts/install/img/darts_board_wall.png`  | Picture of the Dartboard            |
| `cas-darts/install/img/darts_board_stand.png` | Picture of the Dartboard on a Stand |

The Open Source build also has `cas-darts/web/`, the source of the interface. You only need it to rebuild the interface: `cd cas-darts/web`, `npm install`, `npm run build` (with `NODE_ENV=production` if your shell sets it to development). The build replaces `cas-darts/html` and nothing else.

The models live in their own resource on purpose. That way `cas-darts` can be restarted while players are in game, and `cas-darts-assets` never has to be.

## 2. server.cfg

Add the lines in this order, after oxmysql and your framework:

```cfg
ensure oxmysql
# your framework here: vorp_core and vorp_inventory, or rsg-core and rsg-inventory

ensure cas-darts-assets
ensure cas-darts

add_ace group.admin casdarts.admin allow
```

Why the order matters:

* **oxmysql before cas-darts.** The tables are created when `cas-darts` starts. If oxmysql is not running at that moment, the console says `oxmysql is not running: boards, stats and stakes will NOT be saved` and nothing survives a restart.
* **The framework before cas-darts.** With `Config.Framework = 'auto'` the script looks for a started `vorp_core` or `rsg-core` when it starts. If neither is started yet, it runs standalone: no items and no money.
* **cas-darts-assets before cas-darts.** `cas-darts` declares it as a dependency.

## 3. Admins

An admin can hang boards without an item, take down any player board, write the config line of a decor board and clear the hit-rate watch. A player is an admin when one of these is true:

* They have the ace `casdarts.admin` (`Config.AdminAce`). The `add_ace` line above gives it to `group.admin`. Add players to that group as usual:

  ```cfg
  add_principal identifier.license:YOUR_LICENSE group.admin
  ```
* **VORP:** their user group is one of `Config.AdminGroups` (`admin`, `superadmin` by default).
* **RSG:** they have one of the RSG permissions in `Config.AdminGroups`.

In standalone mode only the ace works. The server console always counts as an admin for `/darts_unflag`.

## 4. The two board items

| Item name           | Label                | Picture                 | What it does                   |
| ------------------- | -------------------- | ----------------------- | ------------------------------ |
| `darts_board_wall`  | Dartboard            | `darts_board_wall.png`  | Hangs a board on a wall        |
| `darts_board_stand` | Dartboard on a Stand | `darts_board_stand.png` | Sets a board up on flat ground |

Both pictures are 256 x 256 PNG files in `cas-darts/install/img`. The item names must match `Config.Items` in `config/config.lua`.

### VORP Core

1. Run `cas-darts/install/items_vorp.sql` on your database:

   ```sql
   INSERT IGNORE INTO `items` (`item`, `label`, `limit`, `can_remove`, `type`, `usable`, `desc`, `weight`) VALUES
     ('darts_board_wall', 'Dartboard', 1, 1, 'item_standard', 1, 'An elm dartboard with a set of darts and an oche strip. Use it to hang the board on a wall.', 2.5),
     ('darts_board_stand', 'Dartboard on a Stand', 1, 1, 'item_standard', 1, 'A dartboard on a folding wooden stand, for camps and the open air. Use it to set it up on flat ground.', 6.0);
   ```
2. Copy `darts_board_wall.png` and `darts_board_stand.png` from `cas-darts/install/img/` into `vorp_inventory/html/img/items/`.
3. **Restart the server.** `vorp_inventory` reads the items table only when it starts, so the new items do not work until then.

### RSG Core

1. Add the two lines of `cas-darts/install/items_rsg.lua` to `rsg-core/shared/items.lua`:

   ```lua
   darts_board_wall = { name = 'darts_board_wall', label = 'Dartboard', weight = 2500, type = 'item', image = 'darts_board_wall.png', unique = false, useable = true, shouldClose = true, description = 'An elm dartboard with a set of darts and an oche strip. Use it to hang the board on a wall.' },
   darts_board_stand = { name = 'darts_board_stand', label = 'Dartboard on a Stand', weight = 6000, type = 'item', image = 'darts_board_stand.png', unique = false, useable = true, shouldClose = true, description = 'A dartboard on a folding wooden stand, for camps and the open air. Use it to set it up on flat ground.' },
   ```
2. Copy `darts_board_wall.png` and `darts_board_stand.png` from `cas-darts/install/img/` into `rsg-inventory/html/images/`.

### Standalone

There are no items and no money. Admins hang boards with `/darts_place wall` or `/darts_place stand`. You can also put boards on the map from the config (`Config.DecorBoards`, see Configuration). Players are told apart by their license, and their stats are kept under it.

{% hint style="info" %}
To run standalone on a server that has VORP or RSG started, set `Config.Framework = 'standalone'`.
{% endhint %}

## 5. OneSync

Turn OneSync on, for example with `set onesync on` in server.cfg, `+set onesync on` on the start line, or the OneSync setting of txAdmin.

The server reads where the players stand. It uses that to check that:

* a board is hung close to the player,
* a player is near the board to set up or join a match,
* the thrower stands at the oche when a dart arrives,
* a player is near enough to take a board down,
* a player who walks more than 20 m away is taken out of the lobby or the match.

Without OneSync the server cannot see the players. The client still checks the distances, but the server lets every distance pass and the walk-away rule never fires. The admin commands `/darts_remove` and `/darts_decor` work either way: without OneSync they use the position the admin's game sends.

## 6. Database

You do not import any table. On every start `cas-darts` runs `CREATE TABLE IF NOT EXISTS` for these five:

| Table               | What it keeps                                                                                                            |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `cas_darts_boards`  | Every hung board and every decor board, with its position and owner                                                      |
| `cas_darts_matches` | Every finished match except practice: mode, options, players, result, stake                                              |
| `cas_darts_stats`   | Stats per character and the hit-rate watch                                                                               |
| `cas_darts_payouts` | What is owed to a character: money from a payout or a stake, or a board item an admin took down while its owner was away |
| `cas_darts_escrow`  | Stakes held for lobbies and running matches                                                                              |

The only SQL you run by hand is the VORP item file. The columns are listed in Commands and exports.

## 7. Restart rules

* **Never restart `cas-darts-assets` while players are in game.** Start it once with the server.
* **`cas-darts` can be restarted at any time**, for example after a config change (`restart cas-darts`):
  * Boards stay. They are in the database.
  * Lobbies and running matches stop. They are not saved and do not count for the stats.
  * Every stake that was held is owed back. On start the console says `N stakes from before the restart are owed back`, and each player gets the money as soon as their client is back (a moment after the restart) or at their next character load.
  * The stats of online players are saved when the resource stops.
* Anything still owed to a player who is online (money the framework refused, a board item while their satchel was full) is tried again every 60 seconds.

## 8. First check

1. Start the server and look at the console. You should see:

   ```
   [cas-darts] [info] framework: vorp
   [cas-darts] [info] 0 boards ready
   ```

   The framework line says `vorp`, `rsg` or `standalone`. If it says `standalone` on a VORP or RSG server, your framework started after `cas-darts`.
2. In game, give yourself a Dartboard (or type `/darts_place wall` as an admin).
3. Use it, look at a wall and press **Enter**. The console logs a line like `board 1 (wall) hung by vorp:12 at ...`.
4. Walk to the oche line on the floor in front of the board and press **E** (**Darts**).
5. Pick **Practice** and press **Start practice**. At the oche press **E** (**Throw**), aim with the mouse, hold the left mouse button and release.

If nothing happens when you use the item:

* On VORP, check that you restarted the server after running the SQL.
* Set `Config.Debug = true` and look at F8. The line `board models did not load (cas-darts-assets started?)` means `cas-darts-assets` is not started.
