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.
local inCrew = exports.cuxial_electrician:IsInCrew(source)| Parameter | Type | Description |
|---|---|---|
source | number | Server id of the player. |
Returns: boolean.
if exports.cuxial_electrician:IsInCrew(source) then
-- the player is in the electrician lobby or working
endGetProfile
Returns the electrician level and XP of a character, online or offline.
local profile = exports.cuxial_electrician:GetProfile(identifier)| Parameter | Type | Description |
|---|---|---|
identifier | string | Character 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.
local profile = exports.cuxial_electrician:GetProfile(citizenid)
if profile and profile.level >= 10 then
-- unlock something for experienced electricians
endxp 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.
function CuxialElectrician.hooks.onFinish(src, data)
end| Parameter | Type | Description |
|---|---|---|
src | number | Server id of the member. |
data.runId | number | Number of the job in cuxial_jobs_runs. 0 when it could not be saved. |
data.region | number | id of the region in data/regions.lua. |
data.score | number | Repairs made by this member that count towards the job. |
data.money | number | Money this member received. |
data.xp | number | XP this member received. |
data.owner | string | Character identifier of the crew owner. |
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))
endThe 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.
