Skip to content

currencies/meta/sh_character

Source: gamemode/modules/currencies/meta/sh_character.lua

Get the amount of a specific currency this character has.

Documented functions: 10

Functions


character:AddCurrency(amount, uniqueID, bNoNetworking, recipients)

Add an amount of currency to this character. Clamps the result to be non-negative.

Realm: shared

Parameters

Name Type Description
amount number The amount to add (can be negative to subtract)
uniqueID string The unique identifier of the currency (defaults to "dollars")
bNoNetworking bool Optional flag to disable networking (server only)
recipients table Optional specific recipients for networking (server only)

Returns

  • number: The new total amount of currency

Usage

character:AddCurrency(500, "dollars")

character:AddMoney(amount, uniqueID, bNoNetworking, recipients)

Add dollars (alias for AddCurrency with "dollars").

Realm: shared

Parameters

Name Type Description
amount number The amount to add
bNoNetworking bool Optional flag to disable networking (server only)
recipients table Optional specific recipients for networking (server only)

Returns

  • number: The new total amount of dollars

Usage

character:AddMoney(500)

character:GetCurrency(uniqueID)

Get the amount of a specific currency this character has.

Realm: shared

Parameters

Name Type Description
uniqueID string\|nil The unique identifier of the currency (defaults to "dollars")

Returns

  • number: The amount of currency, or 0 if invalid currency or character

Usage

local money = character:GetCurrency("dollars")

character:GetMoney(uniqueID)

Convenience aliases for the default "dollars" currency These methods use "dollars" as the default currency ID

Get dollars amount (alias for GetCurrency with "dollars").

Realm: shared

Returns

  • number: The amount of dollars

Usage

local dollars = character:GetMoney()

character:HasCurrency(amount, uniqueID)

Check if this character has at least the specified amount of currency.

Realm: shared

Parameters

Name Type Description
amount number The amount to check
uniqueID string The unique identifier of the currency (defaults to "dollars")

Returns

  • bool: True if the character has at least this amount, false otherwise

Usage

if (character:HasCurrency(1000, "dollars")) then
    print("Character is wealthy")
end

character:HasMoney(amount, uniqueID)

Check if character has dollars (alias for HasCurrency with "dollars").

Realm: shared

Parameters

Name Type Description
amount number The amount to check

Returns

  • bool: True if the character has at least this amount

Usage

if (character:HasMoney(1000)) then
    print("Can afford purchase")
end

character:SetCurrency(amount, uniqueID, bNoNetworking, recipients)

Set the amount of a specific currency for this character. Clamps the value to be non-negative. Use AddCurrency or TakeCurrency for modifications.

Realm: shared

Parameters

Name Type Description
amount number The amount to set
uniqueID string The unique identifier of the currency (defaults to "dollars")
bNoNetworking bool Optional flag to disable networking (server only)
recipients table Optional specific recipients for networking (server only)

Usage

character:SetCurrency(1000, "dollars")

character:SetMoney(amount, uniqueID, bNoNetworking, recipients)

Set dollars amount (alias for SetCurrency with "dollars").

Realm: shared

Parameters

Name Type Description
amount number The amount to set
bNoNetworking bool Optional flag to disable networking (server only)
recipients table Optional specific recipients for networking (server only)

Usage

character:SetMoney(1000)

character:TakeCurrency(amount, uniqueID)

Remove an amount of currency from this character. Will not go below zero. Returns false if the character doesn't have enough.

Realm: shared

Parameters

Name Type Description
amount number The amount to remove (must be positive)
uniqueID string The unique identifier of the currency (defaults to "dollars")

Returns

  • bool: True if the full amount was taken, false if insufficient funds

Usage

if (character:TakeCurrency(100, "dollars")) then
    print("Purchased item")
else
    print("Not enough dollars")
end

character:TakeMoney(amount, uniqueID)

Remove dollars (alias for TakeCurrency with "dollars").

Realm: shared

Parameters

Name Type Description
amount number The amount to remove

Returns

  • bool: True if successful, false if insufficient funds

Usage

if (character:TakeMoney(100)) then
    print("Purchase successful")
end