rsg-scratchcards3.0.1 - Technical Documentation#
Summary#
Western themed "match three" scratch cards. Players use an item and scratch nine panels for cash. All results and payments are decided by the server.
| Version | 3.0.1 |
| Dependencies | rsg-core, rsg-inventory, oxmysql |
| Optional | rsg-log |
| Database tables | rsg_scratchcards |
| Exports | None |
| Commands | None |
| Interface | NUI |
Contents#
1. Installation#
- Copy
rsg-scratchcardsintoresources/[framework]. - Add the line in
installation/shared_items.luatorsg-core/shared/items.lua. - Copy
installation/scratchcard.pngtorsg-inventory/html/images/. - Add
scratchcardto a shop (price about $1) in your shop resource. ensure rsg-scratchcardsafteroxmysql,rsg-coreandrsg-inventory, then restart the server.
The table is created on first start. For a manual install set Config.AutoDatabase = false and import install.sql.
2. Architecture#
| File | Side | Purpose |
|---|---|---|
shared/config.lua | shared | Settings |
server/database.lua | server | Table creation |
server/server.lua | server | Item use, rolling, payment |
client/client.lua | client | NUI focus and callbacks |
html/ | NUI | Card and scratching |
3. How it works#
Using the item removes one card, rolls the result and saves it. The server builds a 3x3 grid: a winner has exactly three of one symbol, a loser never has three. The prize is claimed when all panels are revealed or the card is closed. Wins not claimed (disconnect, restart) are paid 5 seconds after the character next loads, or when the player next uses a card.
| Symbol | Prize | Chance |
|---|---|---|
| Horseshoe | $1 | 15% |
| Wagon wheel | $2 | 8% |
| Whiskey bottle | $5 | 3% |
| Hat | $10 | 1.2% |
| Sheriff star | $25 | 0.4% |
| Gold bars | $100 | 0.08% |
27.68% of cards win. The average payout is $0.76 per card, so sell cards for about $1 to keep it a money sink.
4. Configuration#
| Option | Default | Description |
|---|---|---|
Config.AutoDatabase | true | Create the table on start |
Config.AllowPushToTalkWhileOpen | true | Keep push-to-talk working while the card is open |
Config.PushToTalkControls | { 0x4BC9DABB } | Controls left enabled |
Config.Item | 'scratchcard' | Usable item name |
Config.UseCooldown | 3 | Seconds between cards |
Config.PayType | 'cash' | Money type for prizes |
Config.LogWinsFrom | 25 | Log prizes of this size or more (0 = never) |
Config.TotalWeight | 10000 | Total used for chances |
Config.Prizes | six prizes | symbol, prize (whole number), weight |
5. Items and commands#
Item scratchcard (usable, consumed, no metadata). No commands, keys or targets.
6. Exports#
None. This resource has no exports.
7. Events and callbacks#
| Name | Direction | Arguments | Notes |
|---|---|---|---|
rsg-scratchcards:client:open | server to client | { id, grid, prizes, win } | Internal |
rsg-scratchcards:server:claim | client to server | id | Internal. Checks owner and unclaimed |
NUI callbacks: revealed, close. No server callbacks.
8. Data and database#
Table rsg_scratchcards: id, citizenid, prize, claimed, created_at. One row per card used.
9. Security#
The client only sends a card id. The server checks that the card belongs to the character and marks it claimed before paying, so it pays once. Item removal, odds and prize amounts are all server-side. The client is sent the result when the card opens, so a cheat could read it early but cannot change it. Scripts that give or sell cards must do their own checks.
10. Integration examples#
-- placeholder: call from your own server-side reward code, with a real player source
if exports['rsg-inventory']:CanAddItem(src, 'scratchcard', 1) then
exports['rsg-inventory']:AddItem(src, 'scratchcard', 1, nil, nil, 'reward')
end
11. Localisation#
en, de, el, es, fr, ja, nl, pl, pt-br, ro, ru. Set with setr rsg:locale de.
12. Server owner how-tos#
- Change odds or prizes in
Config.Prizes; the console prints the win chance and average payout on start. - Old claimed rows can be removed with
DELETE FROM rsg_scratchcards WHERE claimed = 1;
13. Troubleshooting#
| Problem | Cause / fix |
|---|---|
| Using the card does nothing | Item missing from shared items, config invalid (see console), dead or handcuffed, or on cooldown |
| No item picture | Copy scratchcard.png into the inventory images folder |
14. Known limitations#
- Not run in game.
- Selling is left to your shop resource.
- Not connected to rsg-economy, rsg-reputation or rsg-skills.
- Rows are never pruned automatically.
License#
GPL-3.0-or-later. See LICENSE.
Support: https://rexshack.tebex.store