Currencies gives characters and containers money in any number of currencies. A currency is registered with Currencies:register_currency. A character gets a Currency record with a balance for every registered currency when it is created, and containers hold money as well. Balances are read and changed through the Entity extensions, such as Entity:get_money, Entity:give_money and Entity:give_money_to. Players give money to what they are looking at, drop it as an fl_money entity, and move it in and out of containers with the money panel next to their inventory.

One currency is the default one: the money commands use it when no currency is named, and so can any other plugin, by calling Currencies:get_default_currency. It is named by the default_currency config; while that config is not set, the only registered currency is the default one.

A new character starts with the starting_amount of every currency, which is 0 unless the currency is registered with another one. The starting_money config replaces it for the default currency, and the GetStartingMoney hook has the last word.

Money that lies in the world is kept over restarts while the save_dropped_money config is on: it is saved for every map whenever the framework saves its data, and put back when the map is loaded again.

Hooks decide what is allowed: CanContainMoney names the entities that can hold money, CanPlayerTransferMoney, CanGiveMoney, CanPlayerDropMoney and CanPlayerPickupMoney can refuse to move it, PlayerPickupMoney can refuse a pickup, AdjustReceivedMoney changes or refuses the money that an entity is given, EntityMoneyReceived reports the money it was given and EntityMoneyChanged reports every change of a balance.

Summary

Hooks

Allows players that are not bots and have a character loaded to hold money.
Checks that the giver may transfer the money and that the target is valid, is not the giver, is able to contain money and is within 120 units of the giver's eyes.
Checks that the player may transfer the money, that the drop position is within 120 units of their eyes and that they are neither on pickup cooldown nor have dropped money less than half a second ago.
Blocks money pickup while the player or the money entity is on its pickup cooldown.
Checks that the amount is a positive, finite number with no more decimals than the currency has (a whole number for a currency without decimals), that the currency exists and that the entity can afford it.
Adds a money submenu to the player interaction menu with a 'give' option for every currency that is not hidden or that the local player owns.
Puts the saved money back into the world when the framework loads its data, if the save_dropped_money config is on.
Clears the networked currency balances of a player who drops their character.
Networks the currency balances of the newly active character to the player entity.
Creates or refreshes the money panel below an opened container's inventory.
Creates or refreshes the money panel that sits next to the 'pockets' inventory panel.
Adds a Currency record for every registered currency to a new character, with the starting amount of that currency as its balance.
Gives a container zero balances for every currency if it has none yet and networks its balances.
Saves the money that lies in the world when the framework saves its data, if the save_dropped_money config is on.

Methods

all()shared
Returns every registered currency.
Creates a panel that lists the money of an entity and keeps track of it so that it is rebuilt when the server reports a change.
Returns the definition of a registered currency.
Returns the ID of the default currency: the one named by the default_currency config if it is registered, otherwise the only registered currency.
Returns the model that an amount of a currency has while it lies in the world: the model of the largest threshold in the model_table of the currency that the amount reaches, or else its model.
Returns how much of a currency a new character starts with: the starting_amount the currency is registered with, or the starting_money config for the default currency if that config is above 0.
Spawns the money that Currencies:save_money has saved for the current map, each entity exactly where it was, and freezes what was frozen.
Gives the contents of a money entity to a player, notifies them, starts their pickup cooldown and marks the saved money as out of date.
Saves the money that lies in the world a second from now, if the save_dropped_money config is on.
Registers a currency.
Returns the ID of the currency that a player has named, for instance as the argument of a command, or the ID of the default currency if they have named none.
Saves the currency, amount, position and angles of every fl_money entity in the world, and whether it is frozen, to the plugin data of the current schema and map.
Puts an amount of a currency into the world as an fl_money entity, with the model that the currency has for that amount.

Hooks

Currencies:CanContainMoney(object)

server plugins/currencies/plugin/sv_hooks.lua:225

Implements hook CanContainMoney

Allows players that are not bots and have a character loaded to hold money.

Parameters

  • object Entity

Returns

  • Boolean true for valid non-bot players with a loaded character, otherwise nil

Currencies:CanGiveMoney(actor, target, amount, currency)

server plugins/currencies/plugin/sv_hooks.lua:202

Implements hook CanGiveMoney

Checks that the giver may transfer the money and that the target is valid, is not the giver, is able to contain money and is within 120 units of the giver's eyes.

Parameters

  • actor Entity the entity giving the money, normally a player
  • target Entity the receiver
  • amount Number
  • currency String currency ID

Returns

  • Boolean false when not allowed
  • String error phrase; nothing when allowed

Currencies:CanPlayerDropMoney(actor, amount, currency, pos, _trace)

server plugins/currencies/plugin/sv_hooks.lua:163

Implements hook CanPlayerDropMoney

Checks that the player may transfer the money, that the drop position is within 120 units of their eyes and that they are neither on pickup cooldown nor have dropped money less than half a second ago.

Parameters

  • actor Player
  • amount Number
  • currency String currency ID
  • pos Vector position the money would be dropped at
  • _trace Map eye trace result of the player

Returns

  • Boolean false when not allowed
  • String error phrase if there is one; nothing when allowed

Currencies:CanPlayerPickupMoney(actor, entity)

server plugins/currencies/plugin/sv_hooks.lua:113

Implements hook CanPlayerPickupMoney

Blocks money pickup while the player or the money entity is on its pickup cooldown.

Parameters

  • actor Player
  • entity Entity the fl_money entity

Returns

  • Boolean false while on cooldown, otherwise nil

Currencies:CanPlayerTransferMoney(actor, amount, currency)

server plugins/currencies/plugin/sv_hooks.lua:133

Implements hook CanPlayerTransferMoney

Checks that the amount is a positive, finite number with no more decimals than the currency has (a whole number for a currency without decimals), that the currency exists and that the entity can afford it. An amount with too many decimals is refused rather than rounded, so that both sides of a transfer always change by exactly the same sum.

Parameters

  • actor Entity the entity that parts with the money, a player or a container
  • amount Number
  • currency String currency ID

Returns

  • Boolean false when not allowed
  • String error phrase; nothing when allowed

Currencies:CreatePlayerInteractions(menu, target)

client plugins/currencies/plugin/cl_hooks.lua:64

Implements hook CreatePlayerInteractions

Adds a money submenu to the player interaction menu with a 'give' option for every currency that is not hidden or that the local player owns.

Parameters

  • menu Panel the interaction menu
  • target Player the player being interacted with

Currencies:LoadData()

server plugins/currencies/plugin/sv_hooks.lua:68

Implements hook LoadData

Puts the saved money back into the world when the framework loads its data, if the save_dropped_money config is on.

Currencies:OnActiveCharacterCleared(owner, _character)

server plugins/currencies/plugin/sv_hooks.lua:105

Implements hook OnActiveCharacterCleared

Clears the networked currency balances of a player who drops their character.

Parameters

  • owner Player
  • _character Character the character that is being dropped

Currencies:OnActiveCharacterSet(owner, character)

server plugins/currencies/plugin/sv_hooks.lua:90

Implements hook OnActiveCharacterSet

Networks the currency balances of the newly active character to the player entity.

Parameters

  • owner Player
  • character Character

Currencies:OnContainerOpened(panel, inventory_id)

client plugins/currencies/plugin/cl_hooks.lua:41

Implements hook OnContainerOpened

Creates or refreshes the money panel below an opened container's inventory. Inventories that have an instance_id are skipped.

Parameters

  • panel Panel the container panel
  • inventory_id Number

Currencies:OnInventoryRebuild(panel)

client plugins/currencies/plugin/cl_hooks.lua:10

Implements hook OnInventoryRebuild

Creates or refreshes the money panel that sits next to the 'pockets' inventory panel.

Parameters

  • panel Panel the inventory panel that was rebuilt

Currencies:PostCreateCharacter(owner, char, char_data)

server plugins/currencies/plugin/sv_hooks.lua:38

Implements hook PostCreateCharacter

Adds a Currency record for every registered currency to a new character, with the starting amount of that currency as its balance. Runs the GetStartingMoney hook for every currency.

Parameters

  • owner Player
  • char Character the character being created
  • char_data Map character creation data

Currencies:PreContainerOpen(entity)

server plugins/currencies/plugin/sv_hooks.lua:234

Implements hook PreContainerOpen

Gives a container zero balances for every currency if it has none yet and networks its balances.

Parameters

  • entity Entity the container

Currencies:SaveData()

server plugins/currencies/plugin/sv_hooks.lua:77

Implements hook SaveData

Saves the money that lies in the world when the framework saves its data, if the save_dropped_money config is on. Deletes what has been saved for the map otherwise, so that money which is long gone does not come back once the config is turned on again.

Methods

Returns every registered currency.

Returns

  • Map currency definitions keyed by currency ID

Currencies:create_panel(entity, parent)

client plugins/currencies/plugin/cl_hooks.lua:99

Creates a panel that lists the money of an entity and keeps track of it so that it is rebuilt when the server reports a change. Client only.

Parameters

  • entity Entity entity whose money is shown
  • parent Panel

Returns

  • Panel the created fl_currencies panel

Currencies:find_currency(id)

shared plugins/currencies/plugin/sh_plugin.lua:68

Returns the definition of a registered currency.

Parameters

  • id String currency ID, letter case is ignored

Returns

  • Map currency definition, or nil if it is not registered

Currencies:get_default_currency()

shared plugins/currencies/plugin/sh_plugin.lua:83

Returns the ID of the default currency: the one named by the default_currency config if it is registered, otherwise the only registered currency.

local currency = Currencies:get_default_currency()

if currency and actor:has_money(currency, 50) then
  actor:take_money(currency, 50)
end

Returns

  • String currency ID in lower case; nil if the config does not name a registered currency while none or more than one are registered

Currencies:get_money_model(id, amount)

shared plugins/currencies/plugin/sh_plugin.lua:148

Returns the model that an amount of a currency has while it lies in the world: the model of the largest threshold in the model_table of the currency that the amount reaches, or else its model.

Parameters

  • id String currency ID, letter case is ignored
  • amount Number

Returns

  • String model path; a small box if the currency has no model for the amount, nil if the currency is not registered

Currencies:get_starting_amount(id)

shared plugins/currencies/plugin/sh_plugin.lua:123

Returns how much of a currency a new character starts with: the starting_amount the currency is registered with, or the starting_money config for the default currency if that config is above 0. The GetStartingMoney hook may still change the amount for a particular character.

Parameters

  • id String currency ID, letter case is ignored

Returns

  • Number amount, rounded to the decimals of the currency; 0 if the currency is not registered

Currencies:load_money()

server plugins/currencies/plugin/sv_plugin.lua:128

Spawns the money that Currencies:save_money has saved for the current map, each entity exactly where it was, and freezes what was frozen. Entries of currencies that are not registered are skipped. Server only.

Currencies:pickup_money(actor, entity)

server plugins/currencies/plugin/sv_plugin.lua:20

Gives the contents of a money entity to a player, notifies them, starts their pickup cooldown and marks the saved money as out of date. The entity is not removed here. Server only.

Parameters

  • actor Player
  • entity Entity the fl_money entity

Returns

  • Boolean true if the player has received the money; false if the entity holds no registered currency or the AdjustReceivedMoney hook has refused the money, in which case the money stays where it is

Currencies:queue_money_save()

server plugins/currencies/plugin/sv_plugin.lua:87

Saves the money that lies in the world a second from now, if the save_dropped_money config is on. Calls that come within that second are saved together. Server only.

Currencies:register_currency(id, data)

shared plugins/currencies/plugin/sh_plugin.lua:55

Registers a currency. Characters created afterward get a balance record for it.

Currencies:register_currency('tokens', {
  name = 'currency.tokens.name',
  symbol = 'T',
  decimals = 0,
  hidden = false,
  -- How much of it a new character starts with.
  starting_amount = 100,
  -- Model of dropped money, and optionally models for larger amounts.
  model = 'models/props_lab/box01a.mdl',
  model_table = { [500] = 'models/props_c17/briefcase001a.mdl' }
})

Parameters

  • id String currency ID; use lower case, lookups lower-case the ID they are given
  • data Map currency definition: name, symbol, decimals, hidden, starting_amount, model, model_table

Currencies:resolve_currency(id)

shared plugins/currencies/plugin/sh_plugin.lua:104

Returns the ID of the currency that a player has named, for instance as the argument of a command, or the ID of the default currency if they have named none.

Parameters

  • id String optional, defaults to nil currency ID as it was typed, letter case is ignored

Returns

  • String currency ID in lower case, or nil if the named currency is not registered, or if none is named and there is no default currency

See also

Currencies:save_money()

server plugins/currencies/plugin/sv_plugin.lua:102

Saves the currency, amount, position and angles of every fl_money entity in the world, and whether it is frozen, to the plugin data of the current schema and map. Entities that are being removed are left out, so it can be called right after Entity:Remove. The plugin calls it whenever the framework saves its data, while the save_dropped_money config is on. Server only.

Currencies:spawn_money(currency, amount, position, angles)

server plugins/currencies/plugin/sv_plugin.lua:57

Puts an amount of a currency into the world as an fl_money entity, with the model that the currency has for that amount. Nobody is charged for it: Entity:drop_money is what takes the money out of the pocket of a player. Server only.

local trace = actor:GetEyeTraceNoCursor()
local money_ent = Currencies:spawn_money('tokens', 50, trace.HitPos)

Parameters

  • currency String currency ID, letter case is ignored
  • amount Number amount the entity holds, has to be above 0
  • position Vector where to put the money; it is raised by the height of its bounds
  • angles Angle optional, defaults to nil

Returns

  • Entity the fl_money entity; nil if the currency is not registered, the amount or the position is invalid, or the entity could not be created

Defined in