API Reference

Server exports GetSetting and SetSetting, server and client events, item metadata and integration examples for oxide-dice.

Server exports and events provided by oxide-dice, for developers integrating other resources (shops, events, admin panels, leaderboards).

Any server resource can call these after oxide-dice has started. There are no exports for games, bets or payouts: money only moves through the game's own rules.

Server Exports

GetSetting(key)

Reads a live setting (the values stored in the oxide_settings table and edited from /dice settings; see Configuration). The key is the top-level config name without the Config. prefix.

local street = exports['oxide-dice']:GetSetting('Street')       -- the whole Config.Street table
local alerts = exports['oxide-dice']:GetSetting('Dispatch')

Parameters:

NameTypeDescription
keystringA top-level config key, for example 'Street', 'Tables', 'SideBets', 'Timing', 'Store' or 'Dispatch'

Returns: the current value (any type: boolean, number, string or table), or nil for an unknown key. The value you get is a copy: changing it changes nothing until you pass it to SetSetting.

The config-file-only keys (UseHudAccent, TableModels, DiceTypes, ModelHints) can be read too, and always return the file's value.

Before the settings have loaded at startup, this returns the factory default from the config files. Wait for oxide:dice:server:initialized if you read settings while the server boots.


SetSetting(key, value)

Changes a live setting. It applies on the server straight away, is saved to the database, and is sent to every client. It's the same as saving it in the settings menu, and it lasts through restarts. Renaming an item through it registers the new item name straight away, and saving Tables re-publishes the fixed tables, exactly as the menu does.

local ok = exports['oxide-dice']:SetSetting('Timing', { idleSeconds = 90, turnSeconds = 60, settleMs = 4500 })

Parameters:

NameTypeDescription
keystringA top-level config name without Config.
valueanyThe whole new value for that key. For a table like Street, pass the entire table, not just the field you're changing.

Returns: boolean. true once the setting is applied and saved. It returns false, and the setting keeps its old value, when:

  • the key is one of the config-file-only keys (UseHudAccent, TableModels, DiceTypes, ModelHints)
  • settings are still loading at startup
  • the value holds a number that is not finite (NaN or infinity)
  • the value can't be saved to the database

Only true or false comes back, never a reason. A warning or error in the server console says why it was refused.

SetSetting doesn't check the value against the menu's limits and cross-checks (for example a minimum bet above the maximum, or a table model that doesn't exist), so pass a complete, valid value. The easiest way is to read the current value with GetSetting, change the field you want, and pass the whole table back.

Prefer GetSetting / SetSetting over reading or writing the oxide_settings table directly. They keep the server, database and connected clients in sync in one call.

Server Events

oxide:dice:server:initialized

Raised once on the server when oxide-dice has finished starting: settings loaded, tables created, stakes from interrupted games given back, placed tables loaded and the items registered. It has no arguments.

AddEventHandler('oxide:dice:server:initialized', function()
    local street = exports['oxide-dice']:GetSetting('Street')
    print(('Street dice: $%d to $%d'):format(street.minBet, street.maxBet))
end)

If the database user can't create the resource's tables, start-up stops before this event and it never fires.


oxide:dice:configUpdated (server)

Raised on the server whenever a setting changes, from the menu, a reset, or SetSetting. The argument is the top-level key that changed. It is also raised once with no argument when the settings first finish loading at startup.

AddEventHandler('oxide:dice:configUpdated', function(key)
    if key == nil or key == 'Dispatch' then
        local alerts = exports['oxide-dice']:GetSetting('Dispatch')
        print(('Dice police alert chance is now %s'):format(alerts.chance))
    end
end)

Client Events

oxide:dice:configUpdated (client)

Raised on each client when a changed setting has arrived there, with the top-level key that changed, and once with no argument when the client has received every setting after joining. The new value is already in place when it fires.

AddEventHandler('oxide:dice:configUpdated', function(key)
    -- key: 'Street', 'Store', ... or nil for the first full load
end)

Item Metadata

ItemMetadata fields
dicetype (optional): a key of Config.DiceTypes. Only street ships, and a dice item with no type (or a type that isn't in the file) plays as street. You never need to set it.
dice_tableNone
dice_folding_tableNone

The dice item isn't used up when a game starts. A table item (dice_table or dice_folding_table) is removed when its table is placed, and the same item is given back to whoever packs the table up.

Integration Examples

Sell dice in your own shop

The dice items are ordinary inventory items, so any shop can sell them. Using the dice from the inventory is all a player needs to start a game.

-- In your shop resource, after taking payment through your framework
-- (ox_inventory shown; use your inventory's own add-item call):
local ok = exports.ox_inventory:AddItem(source, 'dice', 1)

If you renamed the item in /dice settings, read the current name instead of hard-coding it:

local diceItem = exports['oxide-dice']:GetSetting('Street').item

Switch street games off during an event

local function setStreetDice(enabled)
    local street = exports['oxide-dice']:GetSetting('Street')
    street.enabled = enabled
    return exports['oxide-dice']:SetSetting('Street', street)
end

setStreetDice(false)   -- the dice item now says "Street games are switched off here."; running games finish
-- ...later
setStreetDice(true)

Turn police alerts on at night

-- Call from your own time or weather script.
local function setDiceAlertChance(chance)
    local alerts = exports['oxide-dice']:GetSetting('Dispatch')
    alerts.chance = math.max(0.0, math.min(1.0, chance))
    return exports['oxide-dice']:SetSetting('Dispatch', alerts)
end

setDiceAlertChance(0.3)   -- three street games in ten raise an alert

Each SetSetting call is saved to the database, so a setting changed this way is still in place after a restart. Change it back yourself when the event or the night ends.

Next Steps