Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: live database updates #661

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
27 changes: 27 additions & 0 deletions bridge/qb/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local functions = {}
---@return PlayerData? playerData
function functions.GetPlayerData(cb)
if not cb then return QBX.PlayerData end

cb(QBX.PlayerData)
end

Expand All @@ -27,8 +28,10 @@ functions.HasItem = function(items, amount)
return false
end
end

return true
end

return count >= amount
end

Expand Down Expand Up @@ -137,6 +140,7 @@ local function getEntities(pool, ignoreList) -- luacheck: ignore
entities[#entities + 1] = entity
end
end

return entities
end

Expand Down Expand Up @@ -175,6 +179,7 @@ local function getClosestEntity(entities, coords) -- luacheck: ignore
closestDistance = distance
end
end

return closestEntity, closestDistance
end

Expand Down Expand Up @@ -233,11 +238,13 @@ functions.GetClosestBone = function(entity, list)
distance = boneDistance
end
end

if not bone then
bone = {id = GetEntityBoneIndexByName(entity, 'bodyshell'), type = 'remains', name = 'bodyshell'}
coords = GetWorldPositionOfEntityBone(entity, bone.id)
distance = #(coords - playerCoords)
end

return bone, coords, distance
end

Expand Down Expand Up @@ -285,7 +292,9 @@ function functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto)
SetVehRadioStation(veh, 'OFF')
SetVehicleFuelLevel(veh, 100.0)
SetModelAsNoLongerNeeded(model)

if teleportInto then TaskWarpPedIntoVehicle(cache.ped, veh, -1) end

if cb then cb(veh) end
end

Expand All @@ -295,12 +304,14 @@ functions.DeleteVehicle = qbx.deleteVehicle
---@deprecated use qbx.getVehiclePlate from modules/lib.lua
functions.GetPlate = function(vehicle)
if vehicle == 0 then return end

return qbx.getVehiclePlate(vehicle)
end

---@deprecated use qbx.getVehicleDisplayName from modules/lib.lua
functions.GetVehicleLabel = function(vehicle)
if vehicle == nil or vehicle == 0 then return end

return qbx.getVehicleDisplayName(vehicle)
end

Expand All @@ -317,6 +328,7 @@ functions.SpawnClear = function(coords, radius)
closeVeh[#closeVeh + 1] = vehicles[i]
end
end

return #closeVeh == 0
end

Expand Down Expand Up @@ -375,6 +387,7 @@ function functions.SetVehicleProperties(vehicle, props)
SetVehicleWheelHealth(vehicle, wheelIndex, health)
end
end

if props.headlightColor then
SetVehicleHeadlightsColour(vehicle, props.headlightColor)
end
Expand Down Expand Up @@ -779,31 +792,38 @@ functions.StartParticleAtCoord = function(dict, ptName, looped, coords, rot, sca
lib.requestNamedPtfxAsset(dict)
UseParticleFxAssetNextCall(dict)
SetPtfxAssetNextCall(dict)

local particleHandle
if looped then
particleHandle = StartParticleFxLoopedAtCoord(ptName, coords.x, coords.y, coords.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false, false)
if color then
SetParticleFxLoopedColour(particleHandle, color.r, color.g, color.b, false)
end

SetParticleFxLoopedAlpha(particleHandle, alpha or 10.0)

if duration then
Wait(duration)
StopParticleFxLooped(particleHandle, false)
end
else
SetParticleFxNonLoopedAlpha(alpha or 1.0)

if color then
SetParticleFxNonLoopedColour(color.r, color.g, color.b)
end

StartParticleFxNonLoopedAtCoord(ptName, coords.x, coords.y, coords.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false)
end

return particleHandle
end

---@deprecated use ParticleFx natives directly
functions.StartParticleOnEntity = function(dict, ptName, looped, entity, bone, offset, rot, scale, alpha, color, evolution, duration) -- luacheck: ignore
lib.requestNamedPtfxAsset(dict)
UseParticleFxAssetNextCall(dict)

local particleHandle = nil
---@cast bone number
local pedBoneIndex = bone and GetPedBoneIndex(entity, bone) or 0
Expand All @@ -817,28 +837,35 @@ functions.StartParticleOnEntity = function(dict, ptName, looped, entity, bone, o
else
particleHandle = StartParticleFxLoopedOnEntity(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false)
end

if evolution then
SetParticleFxLoopedEvolution(particleHandle, evolution.name, evolution.amount, false)
end

if color then
SetParticleFxLoopedColour(particleHandle, color.r, color.g, color.b, false)
end

SetParticleFxLoopedAlpha(particleHandle, alpha or 1.0)

if duration then
Wait(duration)
StopParticleFxLooped(particleHandle, false)
end
else
SetParticleFxNonLoopedAlpha(alpha or 1.0)

if color then
SetParticleFxNonLoopedColour(color.r, color.g, color.b)
end

if boneID then
StartParticleFxNonLoopedOnPedBone(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, boneID, scale or 1.0, false, false, false)
else
StartParticleFxNonLoopedOnEntity(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false)
end
end

return particleHandle
end

Expand Down
3 changes: 3 additions & 0 deletions bridge/qb/server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function commands.Add(name, help, arguments, argsrequired, callback, permission)
restricted = permission and permission ~= 'user' and 'group.'..permission or false,
params = {}
}

for i = 1, #arguments do
local argument = arguments[i]
properties.params[i] = {
Expand All @@ -16,6 +17,7 @@ function commands.Add(name, help, arguments, argsrequired, callback, permission)
optional = not argsrequired or argument?.optional
}
end

lib.addCommand(name, properties, function(source, args, raw)
local _args = {}
if #args > 0 then
Expand All @@ -25,6 +27,7 @@ function commands.Add(name, help, arguments, argsrequired, callback, permission)
_args[i] = args[arguments[i].name]
end
end

callback(source, _args, raw)
end)
end
Expand Down
3 changes: 3 additions & 0 deletions bridge/qb/server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RegisterServerEvent('baseevents:enteringVehicle', function(veh, seat, modelName,
netId = netId,
event = 'Entering'
}

TriggerClientEvent('QBCore:Client:VehicleInfo', src, data)
end)

Expand All @@ -20,6 +21,7 @@ RegisterServerEvent('baseevents:enteredVehicle', function(veh, seat, modelName,
netId = netId,
event = 'Entered'
}

TriggerClientEvent('QBCore:Client:VehicleInfo', src, data)
end)

Expand All @@ -37,5 +39,6 @@ RegisterServerEvent('baseevents:leftVehicle', function(veh, seat, modelName, net
netId = netId,
event = 'Left'
}

TriggerClientEvent('QBCore:Client:VehicleInfo', src, data)
end)
Loading
Loading