Vault API
The Vault block is a programmable credit bank. Its balance is kept on the server, survives restarts, and is tied to a UUID that never changes. Destroying a Vault destroys its balance.
Scripts can reach a vault two ways:
vaultglobal: address any vault on the computer’s entity by UUID.vaultperipheral: wrap a specific Vault block, for exampleperipheral.wrapRelative("left", "vault").
Both run the same checks the Vault’s interact dialog uses, against the player who started the script. Scripts grant no extra authority: a player who couldn’t withdraw through the dialog can’t withdraw through a script. Scripts with no player, such as startup scripts, can read balances but can’t move credits.
Access rules
Adjacent block |
Deposit |
Withdraw |
|---|---|---|
None |
Members of the vault entity’s faction |
Members of the vault entity’s faction |
|
Anyone |
Unchanged by this module |
|
Same faction |
Same faction |
|
Factions that have authed |
Factions that have authed |
Players with no faction never match a faction rule.
Typical usage
local bank = peripheral.wrapRelative("left", "vault")
print("Balance:", bank.getBalance())
-- Charge the player who ran the script (shows an OK/Cancel dialog)
if bank.requestPayment(500, "Program licence") then
print("Thanks!")
end
Using the global instead:
for _, id in ipairs(vault.list()) do
print(id, vault.getBalance(id))
end
Vault peripheral reference
getUuid()Returns the vault’s persistent UUID, the same ID used by thevaultglobal.getBalance()Returns the balance in credits.getAccessLevel()Returns the strongest access the script’s player has:OWNER,FACTION,PASSWORD,PUBLIC_DEPOSITorNONE.requestPayment(amount, [reason])Shows the player an OK/Cancel dialog, withreasonin the body. If they press OK, movesamountcredits from them into the vault. Returnsfalseif they cancel. Throws if access is denied or they can’t afford it.payout(amount, [reason])Paysamountcredits from the vault to the player. Throws if access is denied or the balance is too low.
The peripheral also has every Block method.
vault global reference
vault.list()Returns the UUIDs of every vault on this computer’s entity. Doesn’t check access.vault.getBalance(uuid)vault.requestPayment(uuid, amount, [reason])vault.payoutToPlayer(uuid, amount, [reason])Same as the peripheral methods above, for the vault with that UUID. They throw if no vault on this entity has that UUID.
Notes
The
vaultglobal only reaches vaults on the computer’s own entity. Wrap a block to use a vault you can reach as a peripheral.Every deposit, payout and refund is written to the server log with the player, vault, amount and
reason.Every call throws a Lua error on failure, so wrap calls in
pcallwhen you want to recover.