Hooks hooks
Part of Currencies
Hooks called by Currencies
Summary
Hooks
Entity:give_money or Entity:give_money_to.Hooks
AdjustReceivedMoney(entity, currency, value, source)
server plugins/currencies/plugin/lib/meta/sh_entity.lua:90Lets plugins change or refuse the money that an entity is about to be given, for
instance to tax it. Called on the server by Entity:give_money and
Entity:give_money_to for every amount above 0, whatever it comes from: a transfer
from a player or a container, money picked up from the ground, or another plugin.
Nothing has been moved yet when it runs. It is not called when a balance is set
directly with Entity:set_money.
Parameters
- entity Entity the entity that receives the money: a player, whose active character gets it, or another entity such as a container
- currency String currency ID
- amount Number amount that is about to be added, rounded to the decimals of the currency
- source Any what the money comes from, as passed to give_money: the giving entity, a string that names the reason, or nil if the caller has not said
Returns
- Boolean/Number return false to refuse the money: nothing is added, and a transfer or a pickup it belongs to does not happen. Return a number to add that amount instead; it is rounded to the decimals of the currency and never below 0, and whoever gives the money still pays the full amount. Return nothing to leave the amount as it is
Called from
adjust_received
Call sites
Asks whether an entity is able to hold money. Called by Entity:can_contain_money, and
on the server by the default CanGiveMoney handler for the receiver of the money.
Parameters
- object Entity
Returns
- Boolean return true if the entity can hold money; it cannot when nothing is returned
Called from
Call sites
CanGiveMoney(self, target, value, currency)
server plugins/currencies/plugin/lib/meta/sh_entity.lua:326Decides whether money may be moved from one entity to another. Called on the server
by Entity:give_money_to before anything is moved.
Parameters
- giver Entity the entity the money is taken from, a player or a container
- target Entity the receiver; it may be invalid when a player gives money to whatever they are looking at
- amount Number
- currency String currency ID
Returns
- Boolean return false to refuse the transfer
- String error phrase that give_money_to returns to its caller
Called from
Call sites
CanPlayerDropMoney(self, value, currency, pos, trace)
server plugins/currencies/plugin/lib/meta/sh_entity.lua:271Decides whether a player may drop money on the ground. Called on the server by
Entity:drop_money before the money entity is created.
Parameters
- actor Player
- amount Number
- currency String currency ID
- pos Vector where the money would appear, at most 120 units from the eyes of the player
- trace Map eye trace result of the player
Returns
- Boolean return false to refuse the drop
- String error phrase that drop_money returns to its caller
Called from
Call sites
CanPlayerPickupMoney(activator, self)
server plugins/currencies/plugin/entities/entities/fl_money.lua:76Decides whether money lying in the world may be picked up. Called on the server when a valid entity uses an fl_money entity.
Parameters
- activator Entity the entity that used the money, normally a player
- entity Entity the fl_money entity
Returns
- Boolean return false to prevent the pickup
Called from
Call sites
Asks whether an entity may part with an amount of money. Called on the server by the default handlers of CanPlayerDropMoney and CanGiveMoney, before their own checks. The handler of the Currencies plugin refuses amounts that are not positive, finite numbers with at most as many decimals as the currency has, unknown currencies and amounts the entity cannot afford.
Parameters
- actor Entity the entity that drops or gives the money: a player, or a container that money is taken out of
- amount Number
- currency String currency ID
Returns
- Boolean return false to refuse
- String error phrase for the player
Called from
Call sites
EntityMoneyChanged(self, currency, value, old_value)
server plugins/currencies/plugin/lib/meta/sh_entity.lua:157Called on the server after the amount of a currency that an entity holds has been set and networked.
Parameters
- entity Entity the player or other entity whose balance was set
- currency String currency ID
- value Number the new amount
- old_value Number the amount before the change
Called from
Call sites
EntityMoneyReceived(entity, currency, value, source)
server plugins/currencies/plugin/lib/meta/sh_entity.lua:181Called on the server after money has been added to an entity with
Entity:give_money or Entity:give_money_to. This is the place to log where
money comes from.
Parameters
- entity Entity the entity that has received the money
- currency String currency ID
- amount Number amount that was added, after the AdjustReceivedMoney hook
- source Any what the money comes from, as passed to give_money: the giving entity, a string that names the reason, or nil if the caller has not said
Called from
add_received
Call sites
GetStartingMoney(owner, char, currency_id, amount, char_data)
server plugins/currencies/plugin/sv_hooks.lua:53Lets plugins decide how much of a currency a new character starts with, for instance by its faction. Called on the server for every registered currency while a character is being created, before it is saved.
Parameters
- owner Player the player the character is created for
- char Character the new character, not saved yet
- currency String currency ID
- amount Number what the character would start with, see
Currencies:get_starting_amount - char_data Map creation data the character was built from
Returns
- Number return the amount the character should start with; it is rounded to the decimals of the currency and never below 0. Return nothing to keep the amount
Called from
Call sites
PlayerPickupMoney(activator, self)
server plugins/currencies/plugin/entities/entities/fl_money.lua:86Called on the server when money is about to be picked up, before anything has
changed hands. A handler can refuse the pickup or take note of it; the money itself
is given by Currencies:pickup_money once the hook has run.
Parameters
- activator Entity the entity that used the money, normally a player
- entity Entity the fl_money entity; its get_currency and get_currency_amount methods return what it holds
Returns
- Boolean return false to leave the money where it is. A returned value keeps the handlers after it from running, so return nothing otherwise