Bablo ResourcesDocs

Exports & Hooks

Bablo Electrician Job has a small public surface: two exports that return its configuration, and three server hooks in an open file that the script calls at fixed moments. Use the hooks to require a job, give XP or pay a bonus.

The script talks to your notification, clothing, vehicle key and target resources through open files you can edit. They are listed under Bridges.


Exports

Both exports work on the server and on the client.

GetConfig

Returns the Config table as the script uses it. Settings that were left on auto hold what was detected, for example Framework and Target.

LUA
local config = exports['bablo-electricjob']:GetConfig()
print(config.Command, config.Job.maxMembers)

On the server, Config.Job.sites and Config.Job.orders also hold the boxes and routes from the Route Creator. Called from another resource, the table is a copy. Changing it does not change the script.

GetFramework

Returns the framework the script runs on: 'qbcore', 'qbox' or 'esx'. It returns nil when no framework was found.

LUA
local framework = exports['bablo-electricjob']:GetFramework()

Hooks

The hooks are in frameworks/<framework>/server.lua, where <framework> is qbcore, qbox or esx. Only the file of your framework is used. Out of the box they allow everything and do nothing.

LUA
function Framework:canDoMission(source, orderId)
    return true
end
 
function Framework:onFinishMinigame(source, data)
end
 
function Framework:onFinishMission(source, data)
end

Inside a hook, self is the framework bridge, so self:GetPlayer(source) and self:AddMoney(source, amount, account, reason) are available.

canDoMission

Decides whether a player may take electrician work. The script asks it at two moments:

MomentorderId
A player starts a work order: the crew leader, or a player working soloThe id of the route, for example 'la_mesa'
A player accepts a crew invitenil, because a crew only takes new members while it has no work order

Crew members who joined earlier are not asked again when the leader starts a route.

ReturnResult
false, 'reason'Blocked. The player sees the reason.
falseBlocked with You cannot take electrician work right now.
Anything else, also nilAllowed.

If the function throws an error, the player is blocked as well and the server console prints Framework:canDoMission errored with the error.

Example: only players with the electrician job may take work.

LUA
function Framework:canDoMission(source, orderId)
    local player = self:GetPlayer(source)
    local job = player and player.PlayerData.job
    if not job or job.name ~= 'electrician' then
        return false, 'You need to work for the power company.'
    end
    return true
end

onFinishMinigame

Runs each time a cabinet or fuse box is restored. source is the player who repaired it. The hook only runs while that player is online.

FieldValue
siteIdThe id of the box, for example 'supply_01' or an id from the Route Creator.
titleThe name of the box.
orderIdThe id of the route.
repairKind'sequence' for a cabinet, 'fuse' for a fuse box.
roundsThe number of rounds of a cabinet: 4 or 5, or 1 with Config.DEBUG = true. nil for a fuse box.
assistantIdThe server ID of the crewmate who was helping, or nil. See Helping a Crewmate.

Example: give XP through your own XP script. your-xp and AddXP stand for your resource and its function.

LUA
function Framework:onFinishMinigame(source, data)
    local xp = data.repairKind == 'fuse' and 20 or 10 * data.rounds
    exports['your-xp']:AddXP(source, 'electrician', xp)
    if data.assistantId then
        exports['your-xp']:AddXP(data.assistantId, 'electrician', 5)
    end
end

onFinishMission

Runs when the crew leader has returned the van and the route is settled, after the payouts are handed out. It runs once for every crew member who is still online, with that member as source.

FieldValue
orderIdThe id of the route.
payoutThis member’s share of the contract.
accountThe account it was paid to, Config.Currency.account ('bank' by default).
crewSizeThe number of members in the crew when the van was returned.
leadertrue for the crew leader who returned the van.

Example: a bonus for the crew leader.

LUA
function Framework:onFinishMission(source, data)
    if data.leader then
        self:AddMoney(source, 250, data.account, 'electrician-leader-bonus')
    end
end

What onFinishMinigame and onFinishMission return is ignored. If one of them throws an error, the server console prints it and the job carries on. Payouts themselves are explained on Payouts.


Events and state

The script has no events that other resources are meant to use.

Every bablo-electricjob:* event and callback is internal traffic between the script’s own server and client. Don’t trigger them or rely on them.

The work van carries the state bag babloElectricVan with the id of its crew. It exists for the script itself.


Bridges

These files are not escrowed, so you can change which resource is called. All files you can open are shown in the Script Explorer.

WhatResourcesWhere
HooksYour own codecanDoMission, onFinishMinigame and onFinishMission in frameworks/<framework>/server.lua
MoneyThe player’s framework accountFramework:AddMoney in frameworks/<framework>/server.lua
CharacterThe citizen ID and character name on QBCore and Qbox, the identifier and name on ESXFramework:GetIdentifier and Framework:getPlayerName in frameworks/<framework>/server.lua
NotificationsYour framework, ox_lib or GTA’s feedframeworks/notification/client.lua
Work outfitGTA clothing nativesframeworks/outfit/client.lua, see Work Outfit
Vehicle keysSeven key resources, see belowframeworks/vehiclekeys/client.lua
Targetox_target, qb-target, or an E prompt without a target scriptsrc/interactions/ox_target.lua, qb-target.lua and standalone.lua, picked with Config.Target

Notifications

Config.Notify chooses where messages go:

ValueResult
'framework'The notification of QBCore, Qbox or ESX. When that fails, or no framework was found, GTA’s feed is used. This is the default.
'ox_lib'lib.notify from ox_lib.
'gta'GTA’s notification feed.

To use another notification resource, change ElectricNotification(message, kind, duration) in frameworks/notification/client.lua. kind is 'info', 'success' or 'error'.

While a player is repairing a box, messages are not sent as notifications. On a cabinet they show on the panel monitor instead.

Vehicle keys

When the crew’s van is out, every crew member’s client gives itself the keys through the first of these resources that is started:

OrderResourceHow the key is given
1qbx_vehiclekeysThe server gives the keys through its GiveKeys export.
2Renewed-VehiclekeysaddKey(plate)
3wasabi_carlockGiveKey(plate)
4qs-vehiclekeysGiveKeys(plate)
5tgiann-hotwireThe tgiann-hotwire:addKey event
6cd_garageThe cd_garage:AddKeys event
7qb-vehiclekeysThe vehiclekeys:client:SetOwner event

When none of them is started, no key is given. When the call fails, the client console prints that the resource rejected the key handoff.

To use another key resource, add an entry at the top of the handlers list in frameworks/vehiclekeys/client.lua:

LUA
{ resource = 'my-keys', give = function(plate, vehicle) exports['my-keys']:GiveKey(plate) end },

See Work Van for the van itself.