Skip to content

ax.currencies

Source: gamemode/modules/currencies/libraries/sh_currencies.lua

Character-based currency system for managing multiple currencies in roleplay scenarios.

Documented functions: 7

Functions


ax.currencies:Format(amount, uniqueID)

Format a currency amount using the currency's formatter. Falls back to basic formatting if currency is not found or invalid.

Realm: shared

Parameters

Name Type Description
amount number The amount to format
uniqueID string The unique identifier of the currency

Returns

  • string: Formatted currency string (e.g., "1,234 dollars")

Usage

local formatted = ax.currencies:Format("dollars", 1000)
-- Returns: "1,000 dollars"

ax.currencies:FormatWithSymbol(amount, uniqueID, useSymbol, symbolPosition)

Format a currency amount with symbol prefix or suffix.

Realm: shared

Parameters

Name Type Description
amount number The amount to format
uniqueID string The unique identifier of the currency
useSymbol boolean Whether to include the currency symbol (default: false)
symbolPosition string "prefix" or "suffix" to position the symbol (default: "prefix")

Returns

  • string: Formatted currency string with symbol (e.g., "$1,000" or "1,000$")

Usage

local formatted = ax.currencies:FormatWithSymbol(1000, "dollars", true, "prefix")
-- Returns: "$1,000"

ax.currencies:Get(uniqueID)

Get a registered currency by its unique ID.

Realm: shared

Parameters

Name Type Description
uniqueID string The unique identifier of the currency

Returns

  • table|nil: The currency data table if found, nil otherwise

Usage

local dollars = ax.currencies:Get("dollars")

ax.currencies:GetAll()

Get all registered currencies.

Realm: shared

Returns

  • table: Table of all registered currencies keyed by their unique IDs

Usage

for id, currencyData in pairs(ax.currencies:GetAll()) do
    print(id, currencyData.name)
end

ax.currencies:IsValid(uniqueID)

Check if a currency is valid and registered.

Realm: shared

Parameters

Name Type Description
uniqueID string The unique identifier to check

Returns

  • bool: True if the currency exists, false otherwise

Usage

if (ax.currencies:IsValid("dollars")) then
    print("Credits currency is registered")
end

ax.currencies:Register(uniqueID, data)

Register a new currency type. Creates a currency definition that can be used for character money management. Automatically registers a character variable for storing the currency value.

Realm: shared

Parameters

Name Type Description
uniqueID string The unique identifier for the currency (e.g., "dollars", "tokens")
data table Currency configuration table with the following fields: - name (string): Display name of the currency - symbol (string): Currency symbol (e.g., "$", "¥", "₹") - default (number): Default starting amount (defaults to 0) - singular (string): Singular form of currency name (e.g., "dollar") - plural (string): Plural form of currency name (e.g., "dollars") - format (function): Optional custom formatting function(amount) -> string

Returns

  • bool: True if registration succeeded, false otherwise

Usage

ax.currencies:Register("dollars", {
    name = "Credits",
    symbol = "$",
    default = 100,
    singular = "dollar",
    plural = "dollars"
})

ax.currencies:Spawn(amount, uniqueID, position, angle)

Register default currency immediately Spawn a currency entity in the world (server only). Creates a physical entity representing dropped currency that players can pick up.

Realm: server

Parameters

Name Type Description
amount number The amount of currency to spawn
uniqueID string The unique identifier of the currency (defaults to "dollars")
position vector\|Player The position to spawn at, or a player (spawns at their drop position)
angle Angle Optional angle for the entity (defaults to random)

Returns

  • Entity|nil: The spawned currency entity, or nil if invalid parameters

Usage

local money = ax.currencies:Spawn(500, "dollars", player:GetPos() + Vector(0, 0, 32))