Exports & hooks ​
What other resources may rely on. np_vending depends on none of them (only oxmysql and np_prophandler, which spawns its props).
All exports are server-side unless marked client, called as exports.np_vending:<name>(...). They answer nil,
false or {} until np_vending is ready (np_vending:server:ready), and every table they return is a plain copy.
Operator keys name who owns a machine: 'city', 'p:<identifier>' (a player), 'job:<name>' (a company),
'gang:<id>' (an np_gangs gang). A public machine is:
{ id, code, label, model, coords = { x, y, z, w }, zone, world, operator, operatorName,
status = 'active' | 'off' | 'broken' | 'unpaid' }
Server ​
server
| Export | Returns |
|---|---|
GetMachine(id | code) |
The public machine plus slots = { { slot, item, amount, capacity, price } }, cash (cash box) and forSale ({ price, rent, traffic, avg7, kind, ends?, bid? } or nil), or nil |
GetMachinesNear(coords, radius?) |
{ public machine + distance }, nearest first (radius defaults to 50 m) |
GetOperatorMachines(operatorKey) |
{ public machine } of one operator |
GetOperators(src) |
{ { key, name, role = 'owner' | 'member', kind = 'player' | 'job' | 'gang' } }: every operator a player acts for |
CanPlaceAt(src, model, coords, operator?) |
ok, errorCode | nil, checks: the same spacing check placement runs. errorCode e.g. 'too_close:otherOwner', 'zone_off', 'staff_zone', 'zone_full', 'limit_reached'; checks in the Check shape |
RegisterItemEffect(item, effect) |
boolean. See below |
AddMachine(def) |
Machine id, or nil, error. See below |
RemoveMachine(id | code) |
boolean |
SetMachineStatus(id | code, status) |
boolean. 'active', 'off' or 'broken' |
GetRules() |
The spacing rules and limits that apply now: { sameOwner, otherOwner, sameTypeOther, worldMachine, shop, groupCountsAsOwner, perPlayer, perCompany, permitFee, tighten, modelSpacing } |
registerHook(name, fn) |
Hook id, or nil for an unknown name. See Hooks |
removeHook(id) |
boolean |
Item exports (np_inventory / ox_inventory server.export = 'np_vending.<item>'): vending_tablet, vending_deed,
vending_crate (the names follow Config.ItemNames). They exist for the inventory's use hook; don't call them
yourself.
RegisterItemEffect ​
exports.np_vending:RegisterItemEffect('my_energy_drink', { thirst = 20, stress = -10 }) -- points 0..100
exports.np_vending:RegisterItemEffect('mystery_soda', function(src, item)
TriggerClientEvent('my_status:hallucinate', src, 30)
end)
exports.np_vending:RegisterItemEffect('my_energy_drink', nil) -- remove it again
What Drink now does with an item. A registered effect wins over np_inventory's own use flow. Effects are removed when the registering resource stops.
AddMachine ​
local id, err = exports.np_vending:AddMachine({
model = 'sprunk',
coords = vector3(-1213.4, -890.1, 12.5), heading = 34.0,
operator = 'job:burgershot', operatorName = 'Burger Shot', -- default: 'city'
label = 'Burger Shot lobby',
world = false, -- true: an existing map prop, nothing is spawned
stock = true, -- city machines are stocked unless false, others only with true
})
A machine placed by another resource (an MLO's built-in machine, a business script). There is no spacing check.
Client ​
client
| Export | Returns |
|---|---|
OpenDashboard(operator?) |
Opens the operator dashboard |
StartPlacement(model?) |
Starts placement mode (with the model picker when model is nil) |
IsPlacing() |
boolean |
GetTargetMachine() |
{ id?, model, coords } of the machine in front of the player, or nil. id is nil for a map prop nobody has used yet |
Hooks ​
local id = exports.np_vending:registerHook(name, fn)
exports.np_vending:removeHook(id)
Hooks run synchronously in registration order. Returning false, reason vetoes; the reason is sent to the player as
the error code, so give it a locale text or keep it to an existing code ('vetoed', 'not_available', …). A hook
that errors is skipped and logged. The hooks of a resource are removed when it stops.
| Name | Payload | Return |
|---|---|---|
canBuy |
{ source, machine, slot, item, qty, pay } before anything is priced |
false, reason refuses the purchase |
onSale |
{ source, machine, slot, item, qty, total, pay, operator } after the price is known, before money moves |
false, reason vetoes the sale |
canPlace |
{ source, model, coords, operator, zone } after the spacing check passed |
false, reason refuses the placement |
onBreakIn |
{ source, machine, coords, operator, kind = 'breakin' | 'vandalism' } before a break-in or vandalism starts |
false, reason stops it |
-- no new machines inside your casino interior
exports.np_vending:registerHook('canPlace', function(p)
if #(vector3(p.coords.x, p.coords.y, p.coords.z) - vector3(1100.0, 220.0, -50.0)) < 60.0 then
return false, 'zone_off'
end
end)