Exports ​
What other resources (quests, news, business payroll, tournaments) may rely on. np_golf depends on none of them (only
oxmysql, np_prophandler and np_npchandler). Exports are called as exports.np_golf:<name>(...).
Ids. A character id (cid) is the framework's identifier (ESX identifier, qbx / qb citizenid, or the standalone
id). Round ids look like R0001, group ids like G0001. Exports that take srcOrCid accept a server id (number) or
a character id (string).
Server ​
server
| Export | Returns |
|---|---|
GetHandicap(srcOrCid) |
Handicap index (number; 28 for new players), or nil without a character |
GetProfile(srcOrCid) |
{ name, hcp, rounds, best9, longest, member, memberUntil, fairways, fairwayHoles, gir, putts, perfect, swings, money, week, trend, limits, caddie, prefs }, or nil |
IsPlaying(src) |
boolean: the player is in a live round |
GetPlayerRound(src) |
Round id, or nil |
GetRoundState(roundId) |
The round view the NUI gets (below), or nil |
GetLiveRounds() |
{ { id, format, holes, hole, thru, names, spectators, odds, group, time } }, practice rounds excluded |
CreateGroup(hostSrc, opts?) |
Group id, or nil, error ('no_character', 'in_group', 'playing', 'slot_past', 'slot_taken'). See below |
AddToGroup(groupId, src) |
boolean. Adds a player without the invite step |
StartRound(groupId, format?) |
true, roundId or false, error. No check-in, no fees |
EndRound(roundId) |
boolean. Ends a live round as abandoned |
OpenBetsMarket(roundId, market?) |
boolean. Turns spectators on for the round and refreshes its odds; market = 'winner', 'hole' or 'longdrive' checks that market is open |
GetWind() |
{ x, y, speed, dir, mph }: speed in m/s, direction in degrees |
Groups and tournaments ​
lua
-- a club championship: the event script handles entry fees and prizes
local groupId, err = exports.np_golf:CreateGroup(hostSrc, {
slot = os.time(), -- tee time (unix seconds, snapped to the 10-minute slot); default now
public = false,
format = 'stroke', -- 'stroke' | 'match' | 'skins' | 'stableford' | 'bestball'
holes = 18, -- 9 | 18
})
for _, src in ipairs(entrants) do exports.np_golf:AddToGroup(groupId, src) end
local ok, roundId = exports.np_golf:StartRound(groupId)
StartRound marks every member as joined and ready and starts the round at once. The players walk to the 1st tee as
usual. A slot can only hold one group, so pick a free one.
Round view ​
GetRoundState returns the same plain table the NUI and the phone get:
lua
{ id, format, formatLabel, holes, idx, practice, status = 'playing' | 'finished' | 'abandoned',
hole = { key, n, par, si, name, yards, tee, pin, greenRadius, slope },
list = { { key, n, par, si, yards, name } },
turn, rules, stakes,
players = { { cid, name, short, initials, hcp, playing, strokes, putts, penalties, holed, pickedUp, retired,
ball = { x, y, z, lie }, dist, scores, received, gross, net, toPar, netToPar, stableford, thru,
ballKey, ballLabel, caddie, dropped, stats } },
leaderboard, match, skins, bets, feed, wind, stimp, inFlight, group, course }
Client ​
client
| Export | Returns |
|---|---|
IsPlaying() |
boolean: the local player is in a round |
IsAddressing() |
boolean: the local player stands at the ball (use it to suppress your own keys or UI) |
GetRoundState() |
The local round view, or nil |
IsOpen() |
boolean: a golf menu has NUI focus |
OpenClubhouse() |
Opens the clubhouse |
lua
-- client: don't open your phone / radial while a golfer addresses the ball
if exports.np_golf:IsAddressing() then return end