Skip to content
Open
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
30 changes: 30 additions & 0 deletions [esx_addons]/esx_policejob/client/blips.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local A = POLICE

function createBlip(id)
local ped = GetPlayerPed(id)
local blip = GetBlipFromEntity(ped)
if not DoesBlipExist(blip) then
blip = AddBlipForEntity(ped)
SetBlipSprite(blip, 1)
ShowHeadingIndicatorOnBlip(blip, true)
SetBlipRotation(blip, math.ceil(GetEntityHeading(ped)))
SetBlipNameToPlayerName(blip, id)
SetBlipScale(blip, 0.85)
SetBlipAsShortRange(blip, true)
table.insert(A.blipsCops, blip)
end
end

CreateThread(function()
for _, v in pairs(Config.PoliceStations) do
local blip = AddBlipForCoord(v.Blip.Coords)
SetBlipSprite (blip, v.Blip.Sprite)
SetBlipDisplay(blip, v.Blip.Display)
SetBlipScale (blip, v.Blip.Scale)
SetBlipColour (blip, v.Blip.Colour)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(TranslateCap('map_blip'))
EndTextCommandSetBlipName(blip)
end
end)
35 changes: 35 additions & 0 deletions [esx_addons]/esx_policejob/client/boot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local A = POLICE

AddEventHandler('esx:onPlayerSpawn', function()
A.isDead = false
TriggerEvent('esx_policejob:unrestrain')
if not A.hasAlreadyJoined then
TriggerServerEvent('esx_policejob:spawned')
end
A.hasAlreadyJoined = true
end)

AddEventHandler('esx:onPlayerDeath', function()
A.isDead = true
end)

AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
TriggerEvent('esx_policejob:unrestrain')
TriggerEvent('esx_phone:removeSpecialContact', 'police')

if Config.EnableESXService then
TriggerServerEvent('esx_service:disableService', 'police')
end

if Config.EnableHandcuffTimer and A.handcuffTimer.active then
ESX.ClearTimeout(A.handcuffTimer.task)
end
end
end)

function ImpoundVehicle(vehicle)
ESX.Game.DeleteVehicle(vehicle)
ESX.ShowNotification(TranslateCap('impound_successful'))
A.currentTask.busy = false
end
228 changes: 228 additions & 0 deletions [esx_addons]/esx_policejob/client/cuffs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
local A = POLICE

RegisterNetEvent('esx_policejob:handcuff')
AddEventHandler('esx_policejob:handcuff', function()
A.isHandcuffed = not A.isHandcuffed
local playerPed = PlayerPedId()

if A.isHandcuffed then
POLICE.playCuffAnim(playerPed)

SetEnableHandcuffs(playerPed, true)
DisablePlayerFiring(playerPed, true)
SetCurrentPedWeapon(playerPed, `WEAPON_UNARMED`, true)
SetPedCanPlayGestureAnims(playerPed, false)

if Config.Cuffs and Config.Cuffs.FreezePlayer then
FreezeEntityPosition(playerPed, true)
else
FreezeEntityPosition(playerPed, false)
SetPedCanRagdoll(playerPed, true)
SetPedMoveRateOverride(playerPed, 1.0)
SetRunSprintMultiplierForPlayer(PlayerId(), 1.0)
end

DisplayRadar(false)
SetEntityCollision(playerPed, true, true)
SetEntityDynamic(playerPed, true)
TriggerServerEvent('esx_policejob:cuffsState', true)

if Config.EnableHandcuffTimer then
if A.handcuffTimer.active then ESX.ClearTimeout(A.handcuffTimer.task) end
StartHandcuffTimer()
end
else
if Config.EnableHandcuffTimer and A.handcuffTimer.active then
ESX.ClearTimeout(A.handcuffTimer.task)
end

POLICE.stopCuffAnim(playerPed)
SetEnableHandcuffs(playerPed, false)
DisablePlayerFiring(playerPed, false)
SetPedCanPlayGestureAnims(playerPed, true)
FreezeEntityPosition(playerPed, false)
DisplayRadar(true)
SetEntityCollision(playerPed, true, true)
SetEntityDynamic(playerPed, true)

TriggerServerEvent('esx_policejob:cuffsState', false)
end
end)

RegisterNetEvent('esx_policejob:unrestrain')
AddEventHandler('esx_policejob:unrestrain', function()
if not A.isHandcuffed then return end
local playerPed = PlayerPedId()
A.isHandcuffed = false

POLICE.stopCuffAnim(playerPed)
SetEnableHandcuffs(playerPed, false)
DisablePlayerFiring(playerPed, false)
SetPedCanPlayGestureAnims(playerPed, true)
FreezeEntityPosition(playerPed, false)
DisplayRadar(true)

if Config.EnableHandcuffTimer and A.handcuffTimer.active then
ESX.ClearTimeout(A.handcuffTimer.task)
end

TriggerServerEvent('esx_policejob:cuffsState', false)
end)

CreateThread(function()
while true do
if A.isHandcuffed and (not Config.Cuffs or not Config.Cuffs.FreezePlayer) then
local ped = PlayerPedId()

if IsPedUsingAnyScenario(ped) then
ClearPedTasksImmediately(ped)
end

if IsEntityPlayingAnim(ped, A.ARREST_DICT, A.ARREST_ANIM, 3) ~= 1 then
POLICE.playCuffAnim(ped)
end

FreezeEntityPosition(ped, false)

DisableControlAction(0, 24, true)
DisableControlAction(0, 25, true)
DisableControlAction(0, 37, true)
DisableControlAction(0, 140, true)
DisableControlAction(0, 141, true)
DisableControlAction(0, 142, true)
DisableControlAction(0, 47, true)
DisableControlAction(2, 36, true)
Wait(0)
else
Wait(300)
end
end
end)

RegisterNetEvent('esx_policejob:drag')
AddEventHandler('esx_policejob:drag', function(copId)
if A.isHandcuffed then
A.dragStatus.isDragged = not A.dragStatus.isDragged
A.dragStatus.CopId = copId
end
end)

CreateThread(function()
local wasDragged
while true do
local sleep = 1500
if A.isHandcuffed and A.dragStatus.isDragged then
sleep = 50
local targetPed = GetPlayerPed(GetPlayerFromServerId(A.dragStatus.CopId))
if DoesEntityExist(targetPed) and IsPedOnFoot(targetPed) and not Player(A.dragStatus.CopId).state.isDead then
if not wasDragged then
AttachEntityToEntity(PlayerPedId(), targetPed, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
wasDragged = true
else
Wait(1000)
end
else
wasDragged = false
A.dragStatus.isDragged = false
DetachEntity(PlayerPedId(), true, false)
end
elseif wasDragged then
wasDragged = false
DetachEntity(PlayerPedId(), true, false)
end
Wait(sleep)
end
end)

RegisterNetEvent('esx_policejob:putInVehicle')
AddEventHandler('esx_policejob:putInVehicle', function()
if A.isHandcuffed then
local playerPed = PlayerPedId()
local vehicle, distance = ESX.Game.GetClosestVehicle()
if vehicle and distance < 5.0 then
local maxSeats, freeSeat = GetVehicleMaxNumberOfPassengers(vehicle)
for i=maxSeats - 1, 0, -1 do
if IsVehicleSeatFree(vehicle, i) then freeSeat = i break end
end
if freeSeat then
TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
A.dragStatus.isDragged = false
end
end
end
end)

RegisterNetEvent('esx_policejob:OutVehicle')
AddEventHandler('esx_policejob:OutVehicle', function()
local ped = PlayerPedId()
if IsPedSittingInAnyVehicle(ped) then
local vehicle = GetVehiclePedIsIn(ped, false)
TaskLeaveVehicle(ped, vehicle, 64)
end
end)

CreateThread(function()
while true do
local sleep = 1000
if A.isHandcuffed and Config.Cuffs and Config.Cuffs.FreezePlayer then
sleep = 0
DisableControlAction(0, 1, true)
DisableControlAction(0, 2, true)
DisableControlAction(0, 24, true)
DisableControlAction(0, 257, true)
DisableControlAction(0, 25, true)
DisableControlAction(0, 263, true)
DisableControlAction(0, 32, true)
DisableControlAction(0, 34, true)
DisableControlAction(0, 31, true)
DisableControlAction(0, 30, true)
DisableControlAction(0, 45, true)
DisableControlAction(0, 22, true)
DisableControlAction(0, 44, true)
DisableControlAction(0, 37, true)
DisableControlAction(0, 23, true)
DisableControlAction(0, 288, true)
DisableControlAction(0, 289, true)
DisableControlAction(0, 170, true)
DisableControlAction(0, 167, true)
DisableControlAction(0, 0, true)
DisableControlAction(0, 26, true)
DisableControlAction(0, 73, true)
DisableControlAction(2, 199, true)
DisableControlAction(0, 59, true)
DisableControlAction(0, 71, true)
DisableControlAction(0, 72, true)
DisableControlAction(2, 36, true)
DisableControlAction(0, 47, true)
DisableControlAction(0, 264, true)
DisableControlAction(0, 257, true)
DisableControlAction(0, 140, true)
DisableControlAction(0, 141, true)
DisableControlAction(0, 142, true)
DisableControlAction(0, 143, true)
DisableControlAction(0, 75, true)
DisableControlAction(27, 75, true)

local ped = PlayerPedId()
if IsEntityPlayingAnim(ped, 'mp_arresting', 'idle', 3) ~= 1 then
ESX.Streaming.RequestAnimDict('mp_arresting', function()
TaskPlayAnim(ped, 'mp_arresting', 'idle', 8.0, -8.0, -1, 49, 0.0, false, false, false)
RemoveAnimDict('mp_arresting')
end)
end
end
Wait(sleep)
end
end)

function StartHandcuffTimer()
if Config.EnableHandcuffTimer and A.handcuffTimer.active then
ESX.ClearTimeout(A.handcuffTimer.task)
end
A.handcuffTimer.active = true
A.handcuffTimer.task = ESX.SetTimeout(Config.HandcuffTimer, function()
ESX.ShowNotification(TranslateCap('unrestrained_timer'))
TriggerEvent('esx_policejob:unrestrain')
A.handcuffTimer.active = false
end)
end
74 changes: 74 additions & 0 deletions [esx_addons]/esx_policejob/client/inputs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
local A = POLICE

ESX.RegisterInput("police:interact", "(ESX PoliceJob) " .. TranslateCap('interaction'), "keyboard", "E", function()
if not A.CurrentAction then return end
if (not ESX.PlayerData.job) or (ESX.PlayerData.job.name ~= 'police') then
return
end

if A.CurrentAction == 'menu_cloakroom' then
OpenCloakroomMenu()

elseif A.CurrentAction == 'menu_armory' then
if not Config.EnableESXService or A.playerInService then
OpenArmoryMenu(A.CurrentActionData.station)
else
ESX.ShowNotification(TranslateCap('service_not'))
end

elseif A.CurrentAction == 'menu_vehicle_spawner' then
if not Config.EnableESXService or A.playerInService then
OpenVehicleSpawnerMenu('car', A.CurrentActionData.station, A.CurrentActionData.part, A.CurrentActionData.partNum)
else
ESX.ShowNotification(TranslateCap('service_not'))
end

elseif A.CurrentAction == 'Helicopters' then
if not Config.EnableESXService or A.playerInService then
OpenVehicleSpawnerMenu('helicopter', A.CurrentActionData.station, A.CurrentActionData.part, A.CurrentActionData.partNum)
else
ESX.ShowNotification(TranslateCap('service_not'))
end

elseif A.CurrentAction == 'delete_vehicle' then
ESX.Game.DeleteVehicle(A.CurrentActionData.vehicle)

elseif A.CurrentAction == 'menu_boss_actions' then
ESX.CloseContext()
TriggerEvent('esx_society:openBossMenu', 'police', function()
ESX.CloseContext()
A.CurrentAction = 'menu_boss_actions'
A.CurrentActionMsg = TranslateCap('open_bossmenu')
A.CurrentActionData = {}
end, { wash = false })

elseif A.CurrentAction == 'remove_entity' then
if A.CurrentActionData and A.CurrentActionData.entity and DoesEntityExist(A.CurrentActionData.entity) then
DeleteEntity(A.CurrentActionData.entity)
end
end

A.CurrentAction = nil
end)

ESX.RegisterInput("police:quickactions", "(ESX PoliceJob) "..TranslateCap('quick_actions'), "keyboard", "F6", function()
if not ESX.PlayerData.job or (ESX.PlayerData.job.name ~= 'police') or A.isDead then
return
end
if not Config.EnableESXService or A.playerInService then
OpenPoliceActionsMenu()
else
ESX.ShowNotification(TranslateCap('service_not'))
end
end)

CreateThread(function()
while true do
local Sleep = 1000
if A.CurrentAction then
Sleep = 0
ESX.ShowHelpNotification(A.CurrentActionMsg)
end
Wait(Sleep)
end
end)
Loading