Store

Integration

Exports, preset system, and integration guide for legacy-shops

Client Exports#

OpenStore#

Opens the store UI for a specific shop by its database ID.

exports['legacy-shops']:OpenStore(shopId)
ParameterTypeRequiredDescription
shopIdnumberYesThe shop's database ID

Example

-- Open shop with ID 3
exports['legacy-shops']:OpenStore(3)

The store UI displays all items grouped by category, shows the player's cash and bank balance, and handles the purchase flow.

OpenCreator#

Opens the admin shop creator panel.

exports['legacy-shops']:OpenCreator()

This export performs an admin permission check before opening. Non-admin players will see an error notification.

Preset System#

Presets are shop templates that pre-configure a shop's name, ped model, blip settings, categories, and items. When an admin creates a new shop and selects a preset, all of the preset's data is automatically applied.

Default Presets#

The following presets are seeded on first startup if the presets table is empty:

PresetPed ModelBlip SpriteCategories
General Storemp_m_shopkeep_0152Food & Drinks, Medical, Supplies
Digital Dens_m_y_xmech_02521Phones, Accessories, Storage
Hardware Stores_m_m_strvend_01566Tools, Materials, Automotive
Ammunations_m_y_ammucity_01110Weapons, Ammo, Armor & Gear
Clothing Stores_f_y_shop_mid73Tops, Bottoms, Accessories
Pharmacys_m_m_doctor_0161Medicine, First Aid, Wellness
Bar / Nightclubs_f_y_bartender_0193Drinks, Snacks, Specials
Fishing Stores_m_m_fisherman68Rods & Tackle, Bait, Accessories

Custom Presets#

Admins can create and manage custom presets through the creator UI. Custom presets are stored in the legacy_shops_presets table and support:

  • Custom name and label
  • Ped model selection
  • Blip sprite, color, and scale
  • Custom category lists
  • Pre-configured item lists with prices and stock levels

Item labels and images are automatically resolved from ox_inventory at runtime, so presets only store the item name, category, price, and stock values.

Price Fluctuation#

When Config.FluctuationEnabled is true, the server recalculates randomized prices for all items at the interval defined by Config.FluctuationInterval. Each item gets a random modifier between -FluctuationRange% and +FluctuationRange% applied to its base price.

Key details:

  • The minimum fluctuated price is always $1 (never zero or negative)
  • Base prices in the database are never modified
  • Fluctuated prices are calculated server-side and sent to clients on shop open
  • All players see the same fluctuated prices until the next recalculation

Restock System#

When Config.RestockEnabled is true, items with limited stock are automatically restocked on a timer.

Key details:

  • Only items with stock >= 0 and max_stock > 0 are restocked
  • Items with stock = -1 (unlimited) are never affected
  • Each tick adds RestockPercent% of max_stock to the current stock, capped at max_stock
  • Stock updates are saved to the database and all clients are notified

Stock Values#

Stock behavior is controlled by two fields on each item:

Valuestockmax_stockBehavior
Unlimited-1-1Item never runs out, not restocked
Limited50100Starts at 50, restocked up to 100
Out of stock0100Cannot be purchased until restocked

Purchase Flow#

  1. Player interacts with a shop ped to open the store
  2. Items are displayed with their fluctuated prices (if enabled) and current stock
  3. Player adds items to cart and selects a payment method (cash or bank)
  4. Server validates: item availability, stock levels, carry capacity, and sufficient funds
  5. On success: funds are deducted, items are added to inventory, stock is updated, and the purchase is logged to legacy_shops_history

Database Tables#

legacy_shops_history#

All purchases are logged for auditing:

ColumnTypeDescription
shop_idINTThe shop where the purchase occurred
identifierVARCHAR(100)Player framework identifier
player_nameVARCHAR(100)Player's character name
item_nameVARCHAR(100)Item purchased
quantityINTQuantity purchased
price_paidINTTotal price paid for this item
payment_methodVARCHAR(20)'cash' or 'bank'
purchased_atTIMESTAMPTimestamp of purchase