Exports ​
What other resources may rely on: bar jobs, league and news scripts, consumables, shops, event scripts. np_billiards
depends on none of them (only oxmysql and np_prophandler). Call them as exports.np_billiards:<name>(...).
A public match is:
{ id, table, bar, mode, race, stake, practice, cupId, score = { a, b }, ranked,
players = { { src, cid, name }, { src, cid, name }? } }
Server ​
server
| Export | Returns |
|---|---|
GetPlayerPoolRating(srcOrCid, mode?) |
{ elo, tier, games, wins, peak } or nil. See below |
GetTableState(tableId) |
{ id, bar, label, status, cloth, match?, players?, score?, mode? } or nil. status: 'open', 'busy', 'reserved', 'closed' |
GetTables() |
Every table state, sorted by id |
GetMatch(matchId) |
The public match, or nil |
IsPlaying(src) |
The match id, or false |
StartMatch(opts) |
ok, matchIdOrError. See below |
VoidMatch(matchId) |
boolean. See below |
CreateCup(bar, opts) |
Cup id, or nil, error. See below |
SetDrinks(src, drinks, seconds?) |
The drinks that were set. See below |
GiveCue(src, cueId, opts?) |
boolean. See below |
RegisterTable(def) |
ok, error?. See below |
RemoveTable(id) |
boolean: false for an unknown table or while a match runs on it |
useItem(event, item, inventory, slot, data) |
The item use hook for np_inventory and ox_inventory (server.export = 'np_billiards.useItem'). Don't call it yourself |
GetPlayerPoolRating ​
local r = exports.np_billiards:GetPlayerPoolRating(src) -- a server id ...
local r9 = exports.np_billiards:GetPlayerPoolRating(cid, '9ball') -- ... or a character id, per mode
-- r = { elo = 1384, tier = 'Hustler II', games = 41, wins = 23, peak = 1420 }
mode is '8ball', '9ball' or 'straight'; without it the overall rating. tier is the tier with its division.
StartMatch ​
local ok, id = exports.np_billiards:StartMatch({
table = 'yellowjack_1', mode = '9ball', race = 5,
players = { srcA, srcB }, -- one player = practice
practice = false,
})
For events, jobs and scripted challenges: no stakes and no fee. The players need a loaded character and must not
be in a match. Errors: 'invalid', 'table_busy', 'invalid_player'. With one player, or practice = true, it is
a practice match. The players still have to stand at the table (4 m) to shoot.
VoidMatch ​
exports.np_billiards:VoidMatch(id) -- -> true when the match existed
Ends the match without a winner: every stake and bet is refunded, no ELO moves.
CreateCup ​
local cupId, err = exports.np_billiards:CreateCup('yellowjack', {
name = 'Friday 9-ball', mode = '9ball', size = 16, entry = 250, rake = 10, split = { 60, 30, 10 }, race = 3,
})
Opens sign-ups for a cup at a bar, like the owner tablet but without the owner check. Errors: 'disabled',
'no_permission' (unknown bar), 'invalid' (size not in Config.Cups.sizes), 'bad_split' (doesn't add up to 100).
SetDrinks ​
exports.np_billiards:SetDrinks(src, 2) -- two drinks for 30 minutes (default)
exports.np_billiards:SetDrinks(src, 4, 600) -- four drinks for 10 minutes
exports.np_billiards:SetDrinks(src, 0) -- sober again (from this source)
For bars and consumables. Clamped to 0 – Config.Drunk.maxDrinks. np_billiards takes the highest of this, np_drugs,
esx_status and the state bag (see Drinks), read at the start of each turn.
GiveCue ​
exports.np_billiards:GiveCue(src, 'ivory_swan', { maker = 'Los Santos Customs Cues', number = 7, wrap = 'walnut' })
Adds a pool_cue item with fresh metadata (serial, full tip, empty history) for a shop or a cue maker job. cueId
is a key of Config.Cues except house. maker, number and wrap are optional and show in the cue case.
Returns false without an inventory bridge that can add items.
RegisterTable ​
exports.np_billiards:RegisterTable({
id = 'bahama_1', bar = 'bahama', barLabel = 'Bahama Mamas', society = 'bahama',
label = 'Table 1', model = 'prop_pooltable_02', coords = vector3(-1388.2, -606.4, 30.3), heading = 34.0,
})
Adds a spawned table at runtime (a player-owned bar, an MLO script). An unknown bar is created with barLabel and
society and no owner. An unknown model falls back to prop_pooltable_02. Every client gets the new table list
at once. Runtime tables aren't saved: register them again after a restart.
Client ​
client
| Export | Returns |
|---|---|
IsPlaying() |
true while you play a match (not while spectating) |
IsOpen() |
true while a pool menu is open or it is your shot |
OpenLobby(tableId?) |
Opens the lobby of a table (default: the nearest) |
OpenCase() |
Opens the cue case |
-- client: don't open your own menu over the table
if exports.np_billiards:IsOpen() then return end