Skip to content

Exports & events

Public API of Cuxial Electrician: server exports and the hook that runs when a job is paid.

Read whether a player is in an electrician crew, read their level, and run your own code when a job is paid. Everything here runs on the server; the script has no client exports and no public events.

Server exports ​

IsInCrew ​

Tells whether a player belongs to an electrician crew. A player gets a crew as soon as they open the panel at the NPC, so true does not mean that a job is running.

lua
local inCrew = exports.cuxial_electrician:IsInCrew(source)
ParameterTypeDescription
sourcenumberServer id of the player.

Returns: boolean.

lua
if exports.cuxial_electrician:IsInCrew(source) then
    -- the player is in the electrician lobby or working
end

GetProfile ​

Returns the electrician level and XP of a character, online or offline.

lua
local profile = exports.cuxial_electrician:GetProfile(identifier)
ParameterTypeDescription
identifierstringCharacter identifier used by your framework (the citizenid in QBox and QBCore, the identifier in ESX).

Returns: { level: number, xp: number }, or nil when the character has never opened the job or the database is not ready.

lua
local profile = exports.cuxial_electrician:GetProfile(citizenid)
if profile and profile.level >= 10 then
    -- unlock something for experienced electricians
end

xp is the progress inside the current level, not the total earned.

Hook: onFinish ​

server/hooks.lua is an open file with one function that the script calls once per paid member, right after the money and the XP have been given. Write your own code inside it: extra rewards, statistics, integration with another resource.

lua
function CuxialElectrician.hooks.onFinish(src, data)
end
ParameterTypeDescription
srcnumberServer id of the member.
data.runIdnumberNumber of the job in cuxial_jobs_runs. 0 when it could not be saved.
data.regionnumberid of the region in data/regions.lua.
data.scorenumberRepairs made by this member that count towards the job.
data.moneynumberMoney this member received.
data.xpnumberXP this member received.
data.ownerstringCharacter identifier of the crew owner.
server/hooks.lua
lua
function CuxialElectrician.hooks.onFinish(src, data)
    print(('Player %d finished region %d: %d repairs, $%d, %d XP'):format(
        src, data.region, data.score, data.money, data.xp))
end

The hook is not called for members who are disconnected when the trucks are delivered. An error inside the hook is printed to the server console and does not stop the payment.

server/hooks.lua is replaced when you update the script. Keep a copy of your changes.

© Cuxial