Skip to content

Commit

Permalink
feat: added hooks createPlayerVehicle and changeVehicleOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
Manason committed Jun 26, 2024
1 parent ac90d53 commit 6bc0cc5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
assert(lib.checkDependency('qbx_core', '1.2.0', true))

---@class ErrorResult
---@field code string
---@field message string
Expand All @@ -9,6 +11,8 @@ local State = {
IMPOUNDED = 2
}

local triggerEventHooks = require '@qbx_core.modules.hooks'

---Returns true if the given plate exists
---@param plate string
---@return boolean
Expand Down Expand Up @@ -141,6 +145,13 @@ local function createPlayerVehicle(request)
props.fuelLevel = props.fuelLevel or 100
props.model = joaat(request.model)

if not triggerEventHooks('createPlayerVehicle', { citizenid = request.citizenid, garage = request.garage, props = props }) then
return nil, {
code = 'hook_cancelled',
message = 'a createPlayerVehicle event hook cancelled this operation'
}
end

return MySQL.insert.await('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state, garage) VALUES ((SELECT license FROM players WHERE citizenid = @citizenid), @citizenid, @vehicle, @hash, @mods, @plate, @state, @garage)', {
citizenid = request.citizenid,
vehicle = request.model,
Expand All @@ -159,6 +170,13 @@ exports('CreatePlayerVehicle', createPlayerVehicle)
---@return boolean success, ErrorResult? errorResult
local function setPlayerVehicleOwner(vehicleId, citizenid)
assert(vehicleId ~= nil, "required field vehicleId was nil")
if not triggerEventHooks('changeVehicleOwner', { vehicleId = vehicleId, newCitizenId = citizenid }) then
return false, {
code = 'hook_cancelled',
message = 'a changeVehicleOwner event hook cancelled this operation'
}
end
triggerEventHooks('')
MySQL.update.await('UPDATE player_vehicles SET citizenid = ?, license = (SELECT license FROM players WHERE citizenid = @citizenid) WHERE id = @id', {
citizenid = citizenid,
id = vehicleId
Expand Down

0 comments on commit 6bc0cc5

Please sign in to comment.