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

Moving to server side checks for inventory #422

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 10 additions & 34 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,6 @@ local function openFingerprintUI()
SetNuiFocus(true, true)
end

local function SetCarItemsInfo()
local items = {}
for _, item in pairs(Config.CarItems) do
local itemInfo = QBCore.Shared.Items[item.name:lower()]
items[item.slot] = {
name = itemInfo["name"],
amount = tonumber(item.amount),
info = item.info,
label = itemInfo["label"],
description = itemInfo["description"] and itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = item.slot,
}
end
Config.CarItems = items
end

local function doCarDamage(currentVehicle, veh)
local smash = false
Expand Down Expand Up @@ -130,29 +110,26 @@ function TakeOutImpound(vehicle)
end
end

function TakeOutVehicle(vehicleInfo)
local function TakeOutVehicle(data)
if QBCore.Shared.QBJobsStatus then return end
local coords = Config.Locations["vehicle"][currentGarage]
if coords then
QBCore.Functions.TriggerCallback('QBCore:Server:SpawnVehicle', function(netId)
local veh = NetToVeh(netId)
SetCarItemsInfo()
SetVehicleNumberPlateText(veh, Lang:t('info.police_plate')..tostring(math.random(1000, 9999)))
SetEntityHeading(veh, coords.w)
exports['LegacyFuel']:SetFuel(veh, 100.0)
closeMenuFull()
if Config.VehicleSettings[vehicleInfo] ~= nil then
if Config.VehicleSettings[vehicleInfo].extras ~= nil then
QBCore.Shared.SetDefaultVehicleExtras(veh, Config.VehicleSettings[vehicleInfo].extras)
end
if Config.VehicleSettings[vehicleInfo].livery ~= nil then
SetVehicleLivery(veh, Config.VehicleSettings[vehicleInfo].livery)
end
data.plate = QBCore.Functions.GetPlate(veh)
if Config.VehicleSettings[data.vehicle] ~= nil then
if Config.VehicleSettings[data.vehicle].extras ~= nil then QBCore.Shared.SetDefaultVehicleExtras(veh, Config.VehicleSettings[data.vehicle].extras) end
if Config.VehicleSettings[data.vehicle].livery ~= nil then SetVehicleLivery(veh, Config.VehicleSettings[data.vehicle].livery) end
end
TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1)
TriggerEvent("vehiclekeys:client:SetOwner", QBCore.Functions.GetPlate(veh))
TriggerServerEvent("inventory:server:addTrunkItems", QBCore.Functions.GetPlate(veh), Config.CarItems)
TriggerEvent("vehiclekeys:client:SetOwner", data.plate)
TriggerServerEvent("police:server:addVehItems",data.plate)
SetVehicleEngineOn(veh, true, true)
end, vehicleInfo, coords, true)
end, data.vehicle, coords, true)
end
end

Expand Down Expand Up @@ -414,8 +391,7 @@ end)

RegisterNetEvent('police:client:TakeOutVehicle', function(data)
if inGarage then
local vehicle = data.vehicle
TakeOutVehicle(vehicle)
TakeOutVehicle(data)
end
end)

Expand Down
35 changes: 35 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ local function CreateObjectId()
end
end

local function SetCarItemsInfo()
if QBCore.Shared.QBJobsStatus then return end
local items = {}
local index = 1
if Config.CarItems then
for _,v in pairs(Config.CarItems) do
local itemInfo = QBCore.Shared.Items[v.name:lower()]
items[index] = {
name = itemInfo["name"],
amount = tonumber(v.amount),
info = v.info,
label = itemInfo["label"],
description = itemInfo["description"] and itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = index,
}
index = index + 1
end
end
return items
end

local function IsVehicleOwned(plate)
local result = MySQL.scalar.await('SELECT plate FROM player_vehicles WHERE plate = ?', {plate})
return result
Expand Down Expand Up @@ -592,6 +618,15 @@ QBCore.Functions.CreateCallback('police:server:IsPoliceForcePresent', function(_
end)

-- Events

RegisterNetEvent('police:server:addVehItems', function(plate)
if QBCore.Shared.QBJobsStatus then return end
local trunkItems = SetCarItemsInfo()
if trunkItems then
exports['qb-inventory']:addTrunkItems(plate, trunkItems)
end
end)

AddEventHandler('onResourceStart', function(resourceName)
if resourceName == GetCurrentResourceName() then
CreateThread(function()
Expand Down