Skip to content
Atlas

Docs

Money & Items

Charge players and grant items without breaking the economy.

Money first checklist

  1. Validate source and action on the server.
  2. Check balance / CanCarry before mutating.
  3. Mutate money, then items (or reverse with refunds).
  4. Notify the client of the outcome.

Example shop

lua
RegisterNetEvent('shop:server:purchase', function(item, count)
    local src = source
    count = math.floor(tonumber(count) or 0)
    if count < 1 or count > 20 then return end

    local priceEach = Config.Prices[item]
    if not priceEach then return end

    local total = priceEach * count
    if not Atlas.Inventory.CanCarry(src, item, count).ok then return end
    if not Atlas.Money.Remove(src, 'cash', total) then return end

    local added = Atlas.Inventory.Add(src, item, count)
    if not added.ok then
        Atlas.Money.Add(src, 'cash', total)
    end
end)

Inventory result shape

Always branch on ok:

lua
local r = Atlas.Inventory.Remove(src, 'lockpick', 1)
if not r.ok then
    -- r.error
end

Status drain example

lua
Atlas.Status.Add(src, 'hunger', -15)
Atlas.Status.Add(src, 'thirst', -10)
Atlas.Status.Save(src)