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

Spawn Police Boat near water #504

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<details>
<summary>Click to Expand - Add to qb-radialmenu/config.lua</summary>
'''
{
id = 'pboat',
title = 'Police Boat',
icon = 'ship',
type = 'command',
event = 'pboat',
shouldClose = true
},
'''
</details>

## Installation
### Manual
- Download the script and put it in the `[qb]` directory.
Expand All @@ -103,6 +119,8 @@ ensure qb-policejob
```

## Configuration
<details>
<summary>Click to Expand - Config</summary>
```
Config = {}

Expand Down Expand Up @@ -497,3 +515,4 @@ Config.Items = { -- Items to be displayed on Armory
}
}
```
</details>
25 changes: 25 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ Config.VehicleSettings = {
},
['livery'] = 1,
}
}
}
23 changes: 23 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading