diff --git a/README.md b/README.md index deae6f74..aa8efbf0 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,22 @@ Police Job for QB-Core Framework :police_officer: - /takedrivinglicense - Takes the driving license from nearby player. - /takedna [id] - Takes a DNA sample from the player. +# Additional Commands +- /pboat - Spawn a police boat +
+ Click to Expand - Add to qb-radialmenu/config.lua +''' +{ + id = 'pboat', + title = 'Police Boat', + icon = 'ship', + type = 'command', + event = 'pboat', + shouldClose = true + }, +''' +
+ ## Installation ### Manual - Download the script and put it in the `[qb]` directory. @@ -103,6 +119,8 @@ ensure qb-policejob ``` ## Configuration +
+ Click to Expand - Config ``` Config = {} @@ -497,3 +515,4 @@ Config.Items = { -- Items to be displayed on Armory } } ``` +
diff --git a/client/main.lua b/client/main.lua index 82dd5a9e..de065950 100644 --- a/client/main.lua +++ b/client/main.lua @@ -222,3 +222,28 @@ CreateThread(function() EndTextCommandSetBlipName(blip) end end) + +-- Spawn Police Boat +RegisterNetEvent('policejob:checkProximityToWater', function() + local playerPed = PlayerPedId() + local playerCoords = GetEntityCoords(playerPed) + if IsEntityInWater(playerPed) then + TriggerServerEvent('policejob:spawnVehicleForPlayer') + else + QBCore.Functions.Notify('You need to be near water to do this.', 'error') + end +end) + +RegisterNetEvent('policejob:pboat', function(vehicleName) + local playerPed = PlayerPedId() + local pos = GetEntityCoords(playerPed) + local vehicleHash = GetHashKey(vehicleName) + + RequestModel(vehicleHash) + while not HasModelLoaded(vehicleHash) do + Wait(1) + end + + local spawnedVehicle = CreateVehicle(vehicleHash, pos.x, pos.y, pos.z, GetEntityHeading(playerPed), true, false) + SetPedIntoVehicle(playerPed, spawnedVehicle, -1) +end) \ No newline at end of file diff --git a/config.lua b/config.lua index 2a63b0d1..373d9d29 100644 --- a/config.lua +++ b/config.lua @@ -169,4 +169,4 @@ Config.VehicleSettings = { }, ['livery'] = 1, } -} +} \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 6531e2d5..9c71caaf 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1146,3 +1146,26 @@ CreateThread(function() UpdateBlips() end end) + +-- Police Boat Spawn +TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) + +RegisterCommand('pboat', function(source, args, rawCommand) + local Player = QBCore.Functions.GetPlayer(source) + if Player then + local playerJob = Player.PlayerData.job.name + if playerJob == 'police' then + TriggerClientEvent('policejob:checkProximityToWater', source) + else + TriggerClientEvent('QBCore:Notify', source, 'You do not have the required job to do this.', 'error') + end + end +end, false) + +RegisterNetEvent('policejob:spawnVehicleForPlayer', function() + local source = source + local Player = QBCore.Functions.GetPlayer(source) + if Player then + TriggerClientEvent('policejob:pboat', source, 'predator') -- Replace 'predator' with the name of the vehicle you want to spawn + end +end) \ No newline at end of file