All resources

rsg-trader – Developer Docs#

Files#

FilePurpose
shared/config.luaSettings and shared pricing helpers (Config.GetBuyPrice, Config.GetSellPrice, Config.Round2)
server/database.luaAuto-creates/upgrades rsg_trader and rsg_trader_npcs (when Config.AutoDatabase = true), then fires rsg-trader:server:databaseReady
server/server.luaTrader cache (synced to clients via GlobalState.rsgTraders), buy/sell and admin callbacks
server/webhooks.lua / webhook_config.luaBatched, rate-limit-aware Discord logging (server only)
client/client.luaBlips, NUI bridge, shop and admin panel
client/npcs.luaDistance-based ped spawning with rsg-target option
html/*NUI (RDR2 leather & gold theme)

Database#

  • rsg_trader – traderid, item, stock, lowstock, highstock, baseprice (unique traderid + item)
  • rsg_trader_npcs – traderid (PK), tradername, npcmodel, x, y, z, heading, showblip

Pricing#

  • Buy price: baseprice × multiplier (lowStock when stock <= lowstock, highStock when stock >= highstock), clamped by minPriceFactor/maxPriceFactor.
  • Sell price: buy price × sellFactor. Keep sellFactor × lowStock < normalStock to prevent buy/sell profit loops.

Server callbacks (rsg-core CreateCallback)#

NameArgsAccess
rsg-trader:server:traderdatatraderidanyone
rsg-trader:server:buy / :selltraderid, item, amountplayer within InteractDistance, Cooldown applied
rsg-trader:server:admin:isAdmin–anyone (returns bool)
rsg-trader:server:admin:traders / :items– / traderidadmin
rsg-trader:server:admin:saveTrader{ traderid?, tradername, npcmodel, showblip, moveHere? }admin; position always taken from the admin's ped server-side
rsg-trader:server:admin:deleteTradertraderid, removeItemsadmin
rsg-trader:server:admin:saveItem{ traderid, item, stock, lowstock, highstock, baseprice, isNew }admin
rsg-trader:server:admin:deleteItemtraderid, itemadmin

All callbacks return { ok = bool, msg = string } for actions.

Security#

  • Prices, stock, money and items are all decided server-side; the client only sends trader id, item and amount.
  • Amounts are integer-clamped to 1..MaxBuyAmount/MaxSellAmount; items must exist in RSGCore.Shared.Items and be listed on that trader.
  • Stock is reserved with an atomic UPDATE ... WHERE stock >= ?; payment or inventory failures are rolled back.
  • Sales that would pay $0 are rejected.
  • Invalid input, distance failures and non-admin calls to admin callbacks are logged to the security webhook (throttled).

Commands#

  • /traderadmin (admin) – open the admin panel
  • /traderwebhooktest (admin) – send test embeds

Exports#

  • Server: exports['rsg-trader']:SendWebhook(event, src, title, fields, description)

Locales#

JSON files in locales/ (en, de, el, es, fr, ja, nl, pl, pt-br, ro, ru), loaded by @rsg-core/shared/locale.lua. Set language with setr rsg:locale <lang>.

rsg-economy integration#

Config.Economy = { Enabled }. econQuote(src, trader, mode, unitPrice, qty) finds the region with exports['rsg-economy']:GetRegionAt(trader position) and calls Quote with market = false.

  • rsg-trader:server:traderdata replaces buyprice and sellprice with the quote's per-unit total, so the UI shows the taxed price.
  • rsg-trader:server:buy / sell use quote.total as the amount charged or paid (server computed, never from the client). After the money and items have moved, Record(src, quote) banks the tax in the treasury.
  • Per-unit prices shown in the UI are rounded to cents, so a large order can differ from the shown unit price times the quantity by a few cents.
  • Skipped when rsg-economy is not started or the trader has no town within Config.RegionRadius of rsg-economy.
<!-- BEGIN AUTO-REFERENCE (generated from the code; re-run the generator instead of editing by hand) -->

Technical reference#

Generated from the source of rsg-trader 3.2.0. Names, arguments and defaults below are read straight from the code.

Dependencies#

rsg-core, rsg-inventory, rsg-target, oxmysql

Database#

Tables: rsg_trader, rsg_trader_npcs.

Tables are created automatically on start while Config.AutoDatabase = true (default). Nothing is ever dropped or overwritten. For a manual install set Config.AutoDatabase = false and import installation/rsg-trader.sql once.

-- shared/config.lua
Config.AutoDatabase = true -- false = import the SQL file yourself

Configuration#

OptionDefaultNotes
Config.Debugfalse
Config.AutoDatabasetruecreate/upgrade the database table on start (false = import installation/rsg-trader.sql manually)
Config.Image'rsg-inventory/html/images/'location of item images
Config.MaxBuyAmount10max items per buy transaction
Config.MaxSellAmount10max items per sell transaction
Config.InteractDistance5.0server-side max distance (m) from the trader to buy/sell
Config.Cooldown2000server-side cooldown (ms) between transactions per player
Config.Soundstable
Config.DistanceSpawn20.0
Config.FadeIntrue
Config.Pricingtable
Config.DefaultModel'mp_u_m_m_trader_01'
Config.DefaultBlip{ sprite = 'blip_shop_market_stall', scale = 0.2 }
Config.DefaultTraderstable
Config.DefaultItemstable
Config.EconomytableThe town is the one nearest to the trader (rsg-economy GetRegionAt). A trader too far from every town is untou
Config.Enabledtrue

Exports#

Server

ExportArgumentsFile
SendWebhook``server/webhooks.lua
-- example
local result = exports['rsg-trader']:SendWebhook()

Events#

Server events can be fired by any client, so every handler re-validates the player, the arguments and any permission, distance or cooldown on the server. Never add a reward to a handler without those checks.

EventSideArgumentsFile
rsg-trader:client:openAdminclient``client/client.lua
-- from a server script
TriggerClientEvent('rsg-trader:client:openAdmin', source)

Commands#

CommandNotesFile
/traderadminlocale('sv_cmd_admin')server/server.lua
/traderwebhooktestlocale('sv_cmd_webhooktest')server/webhooks.lua

Locales#

Language files in locales/: de, el, en, es, fr, ja, nl, pl, pt-br, ro, ru. Set the language with setr rsg:locale "en".

<!-- END AUTO-REFERENCE -->